2019-02-12 22:28:05 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
#include <unordered_map>
|
2019-02-12 22:28:05 +01:00
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/renderer_vulkan/declarations.h"
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Format usage descriptor.
|
2019-02-12 22:28:05 +01:00
|
|
|
enum class FormatType { Linear, Optimal, Buffer };
|
|
|
|
|
|
|
|
/// Handles data specific to a physical device.
|
|
|
|
class VKDevice final {
|
|
|
|
public:
|
|
|
|
explicit VKDevice(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical,
|
|
|
|
vk::SurfaceKHR surface);
|
|
|
|
~VKDevice();
|
|
|
|
|
|
|
|
/// Initializes the device. Returns true on success.
|
|
|
|
bool Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a format supported by the device for the passed requeriments.
|
|
|
|
* @param wanted_format The ideal format to be returned. It may not be the returned format.
|
|
|
|
* @param wanted_usage The usage that must be fulfilled even if the format is not supported.
|
|
|
|
* @param format_type Format type usage.
|
|
|
|
* @returns A format supported by the device.
|
|
|
|
*/
|
|
|
|
vk::Format GetSupportedFormat(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
|
|
|
|
FormatType format_type) const;
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns the dispatch loader with direct function pointers of the device.
|
2019-02-12 22:28:05 +01:00
|
|
|
const vk::DispatchLoaderDynamic& GetDispatchLoader() const {
|
|
|
|
return dld;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns the logical device.
|
2019-02-12 22:28:05 +01:00
|
|
|
vk::Device GetLogical() const {
|
|
|
|
return logical.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the physical device.
|
|
|
|
vk::PhysicalDevice GetPhysical() const {
|
|
|
|
return physical;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the main graphics queue.
|
|
|
|
vk::Queue GetGraphicsQueue() const {
|
|
|
|
return graphics_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the main present queue.
|
|
|
|
vk::Queue GetPresentQueue() const {
|
|
|
|
return present_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns main graphics queue family index.
|
|
|
|
u32 GetGraphicsFamily() const {
|
|
|
|
return graphics_family;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns main present queue family index.
|
|
|
|
u32 GetPresentFamily() const {
|
|
|
|
return present_family;
|
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// Returns true if the device is integrated with the host CPU.
|
2019-02-12 22:28:05 +01:00
|
|
|
bool IsIntegrated() const {
|
|
|
|
return device_type == vk::PhysicalDeviceType::eIntegratedGpu;
|
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// Returns the driver ID.
|
|
|
|
vk::DriverIdKHR GetDriverID() const {
|
|
|
|
return driver_id;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns uniform buffer alignment requeriment.
|
2019-02-12 22:28:05 +01:00
|
|
|
u64 GetUniformBufferAlignment() const {
|
|
|
|
return uniform_buffer_alignment;
|
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// Returns storage alignment requeriment.
|
|
|
|
u64 GetStorageBufferAlignment() const {
|
|
|
|
return storage_buffer_alignment;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns the maximum range for storage buffers.
|
|
|
|
u64 GetMaxStorageBufferRange() const {
|
|
|
|
return max_storage_buffer_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if ASTC is natively supported.
|
|
|
|
bool IsOptimalAstcSupported() const {
|
|
|
|
return is_optimal_astc_supported;
|
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// Returns true if the device supports float16 natively
|
|
|
|
bool IsFloat16Supported() const {
|
|
|
|
return is_float16_supported;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns true if the device supports VK_EXT_scalar_block_layout.
|
2019-09-13 06:55:28 +02:00
|
|
|
bool IsKhrUniformBufferStandardLayoutSupported() const {
|
|
|
|
return khr_uniform_buffer_standard_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the device supports VK_EXT_index_type_uint8.
|
|
|
|
bool IsExtIndexTypeUint8Supported() const {
|
|
|
|
return ext_index_type_uint8;
|
2019-05-26 06:33:57 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Checks if the physical device is suitable.
|
|
|
|
static bool IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical,
|
|
|
|
vk::SurfaceKHR surface);
|
|
|
|
|
|
|
|
private:
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Loads extensions into a vector and stores available ones in this object.
|
|
|
|
std::vector<const char*> LoadExtensions(const vk::DispatchLoaderDynamic& dldi);
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Sets up queue families.
|
|
|
|
void SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface);
|
|
|
|
|
|
|
|
/// Sets up device properties.
|
|
|
|
void SetupProperties(const vk::DispatchLoaderDynamic& dldi);
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Sets up device features.
|
|
|
|
void SetupFeatures(const vk::DispatchLoaderDynamic& dldi);
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Returns a list of queue initialization descriptors.
|
|
|
|
std::vector<vk::DeviceQueueCreateInfo> GetDeviceQueueCreateInfos() const;
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns true if ASTC textures are natively supported.
|
|
|
|
bool IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features,
|
|
|
|
const vk::DispatchLoaderDynamic& dldi) const;
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Returns true if a format is supported.
|
|
|
|
bool IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
|
|
|
|
FormatType format_type) const;
|
|
|
|
|
|
|
|
/// Returns the device properties for Vulkan formats.
|
2019-09-13 06:55:28 +02:00
|
|
|
static std::unordered_map<vk::Format, vk::FormatProperties> GetFormatProperties(
|
2019-02-12 22:28:05 +01:00
|
|
|
const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical);
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
const vk::PhysicalDevice physical; ///< Physical device.
|
|
|
|
vk::DispatchLoaderDynamic dld; ///< Device function pointers.
|
|
|
|
UniqueDevice logical; ///< Logical device.
|
|
|
|
vk::Queue graphics_queue; ///< Main graphics queue.
|
|
|
|
vk::Queue present_queue; ///< Main present queue.
|
|
|
|
u32 graphics_family{}; ///< Main graphics queue family index.
|
|
|
|
u32 present_family{}; ///< Main present queue family index.
|
|
|
|
vk::PhysicalDeviceType device_type; ///< Physical device type.
|
|
|
|
vk::DriverIdKHR driver_id{}; ///< Driver ID.
|
|
|
|
u64 uniform_buffer_alignment{}; ///< Uniform buffer alignment requeriment.
|
|
|
|
u64 storage_buffer_alignment{}; ///< Storage buffer alignment requeriment.
|
|
|
|
u64 max_storage_buffer_range{}; ///< Max storage buffer size.
|
|
|
|
bool is_optimal_astc_supported{}; ///< Support for native ASTC.
|
|
|
|
bool is_float16_supported{}; ///< Support for float16 arithmetics.
|
|
|
|
bool khr_uniform_buffer_standard_layout{}; ///< Support for std430 on UBOs.
|
|
|
|
bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8.
|
|
|
|
bool khr_driver_properties{}; ///< Support for VK_KHR_driver_properties.
|
|
|
|
std::unordered_map<vk::Format, vk::FormatProperties>
|
|
|
|
format_properties; ///< Format properties dictionary.
|
2019-02-12 22:28:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|