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-12-09 05:04:48 +01:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2019-09-13 06:55:28 +02:00
|
|
|
#include <unordered_map>
|
2021-04-11 07:50:30 +02:00
|
|
|
#include <span>
|
2019-02-12 22:28:05 +01:00
|
|
|
#include <vector>
|
2020-03-27 05:33:21 +01:00
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
#include "common/common_types.h"
|
2020-12-25 01:30:11 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
2019-02-12 22:28:05 +01:00
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2020-12-26 05:26:52 +01:00
|
|
|
class NsightAftermathTracker;
|
|
|
|
|
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 };
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
/// Subgroup size of the guest emulated hardware (Nvidia has 32 threads per subgroup).
|
|
|
|
const u32 GuestWarpSize = 32;
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Handles data specific to a physical device.
|
2021-01-05 08:09:39 +01:00
|
|
|
class Device {
|
2019-02-12 22:28:05 +01:00
|
|
|
public:
|
2020-12-26 05:10:53 +01:00
|
|
|
explicit Device(VkInstance instance, vk::PhysicalDevice physical, VkSurfaceKHR surface,
|
|
|
|
const vk::InstanceDispatch& dld);
|
|
|
|
~Device();
|
2019-02-12 22:28:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-03-27 05:33:21 +01:00
|
|
|
VkFormat GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
|
|
|
|
FormatType format_type) const;
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2019-12-19 06:09:05 +01:00
|
|
|
/// Reports a device loss.
|
|
|
|
void ReportLoss() const;
|
|
|
|
|
2020-03-30 10:21:59 +02:00
|
|
|
/// Reports a shader to Nsight Aftermath.
|
2021-04-11 07:50:30 +02:00
|
|
|
void SaveShader(std::span<const u32> spirv) const;
|
2020-03-30 10:21:59 +02:00
|
|
|
|
2021-06-20 23:26:55 +02:00
|
|
|
/// Returns the name of the VkDriverId reported from Vulkan.
|
|
|
|
std::string GetDriverName() const;
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns the dispatch loader with direct function pointers of the device.
|
2020-03-27 05:33:21 +01:00
|
|
|
const vk::DeviceDispatch& GetDispatchLoader() const {
|
2019-02-12 22:28:05 +01:00
|
|
|
return dld;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns the logical device.
|
2020-03-27 05:33:21 +01:00
|
|
|
const vk::Device& GetLogical() const {
|
|
|
|
return logical;
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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-12-09 05:04:48 +01:00
|
|
|
/// Returns the current Vulkan API version provided in Vulkan-formatted version numbers.
|
2020-06-29 07:48:29 +02:00
|
|
|
u32 ApiVersion() const {
|
2019-12-09 05:04:48 +01:00
|
|
|
return properties.apiVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the current driver version provided in Vulkan-formatted version numbers.
|
|
|
|
u32 GetDriverVersion() const {
|
|
|
|
return properties.driverVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the device name.
|
|
|
|
std::string_view GetModelName() const {
|
|
|
|
return properties.deviceName;
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// Returns the driver ID.
|
2020-03-27 05:33:21 +01:00
|
|
|
VkDriverIdKHR GetDriverID() const {
|
2019-09-13 06:55:28 +02:00
|
|
|
return driver_id;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns uniform buffer alignment requeriment.
|
2020-03-27 05:33:21 +01:00
|
|
|
VkDeviceSize GetUniformBufferAlignment() const {
|
2019-12-09 05:04:48 +01:00
|
|
|
return properties.limits.minUniformBufferOffsetAlignment;
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// Returns storage alignment requeriment.
|
2020-03-27 05:33:21 +01:00
|
|
|
VkDeviceSize GetStorageBufferAlignment() const {
|
2019-12-09 05:04:48 +01:00
|
|
|
return properties.limits.minStorageBufferOffsetAlignment;
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns the maximum range for storage buffers.
|
2020-03-27 05:33:21 +01:00
|
|
|
VkDeviceSize GetMaxStorageBufferRange() const {
|
2019-12-09 05:04:48 +01:00
|
|
|
return properties.limits.maxStorageBufferRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the maximum size for push constants.
|
2020-03-27 05:33:21 +01:00
|
|
|
VkDeviceSize GetMaxPushConstantsSize() const {
|
2019-12-09 05:04:48 +01:00
|
|
|
return properties.limits.maxPushConstantsSize;
|
2019-05-26 06:33:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-16 21:02:46 +02:00
|
|
|
/// Returns the maximum size for shared memory.
|
|
|
|
u32 GetMaxComputeSharedMemorySize() const {
|
|
|
|
return properties.limits.maxComputeSharedMemorySize;
|
|
|
|
}
|
|
|
|
|
2021-02-20 07:30:13 +01:00
|
|
|
/// Returns float control properties of the device.
|
|
|
|
const VkPhysicalDeviceFloatControlsPropertiesKHR& FloatControlProperties() const {
|
|
|
|
return float_controls;
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// 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-12-09 05:04:48 +01:00
|
|
|
/// Returns true if the device warp size can potentially be bigger than guest's warp size.
|
|
|
|
bool IsWarpSizePotentiallyBiggerThanGuest() const {
|
|
|
|
return is_warp_potentially_bigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the device can be forced to use the guest warp size.
|
2020-03-27 05:33:21 +01:00
|
|
|
bool IsGuestWarpSizeSupported(VkShaderStageFlagBits stage) const {
|
|
|
|
return guest_warp_stages & stage;
|
2019-12-09 05:04:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 09:06:02 +01:00
|
|
|
/// Returns true if formatless image load is supported.
|
|
|
|
bool IsFormatlessImageLoadSupported() const {
|
|
|
|
return is_formatless_image_load_supported;
|
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
/// Returns true when blitting from and to depth stencil images is supported.
|
|
|
|
bool IsBlitDepthStencilSupported() const {
|
|
|
|
return is_blit_depth_stencil_supported;
|
|
|
|
}
|
|
|
|
|
2020-05-04 23:31:17 +02:00
|
|
|
/// Returns true if the device supports VK_NV_viewport_swizzle.
|
|
|
|
bool IsNvViewportSwizzleSupported() const {
|
|
|
|
return nv_viewport_swizzle;
|
|
|
|
}
|
|
|
|
|
2021-03-29 00:53:34 +02:00
|
|
|
/// Returns true if the device supports VK_KHR_uniform_buffer_standard_layout.
|
2019-09-13 06:55:28 +02:00
|
|
|
bool IsKhrUniformBufferStandardLayoutSupported() const {
|
|
|
|
return khr_uniform_buffer_standard_layout;
|
|
|
|
}
|
|
|
|
|
2021-03-29 00:53:34 +02:00
|
|
|
/// Returns true if the device supports VK_KHR_spirv_1_4.
|
|
|
|
bool IsKhrSpirv1_4Supported() const {
|
|
|
|
return khr_spirv_1_4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the device supports VK_KHR_workgroup_memory_explicit_layout.
|
|
|
|
bool IsKhrWorkgroupMemoryExplicitLayoutSupported() const {
|
|
|
|
return khr_workgroup_memory_explicit_layout;
|
|
|
|
}
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
/// 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
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
/// Returns true if the device supports VK_EXT_sampler_filter_minmax.
|
|
|
|
bool IsExtSamplerFilterMinmaxSupported() const {
|
|
|
|
return ext_sampler_filter_minmax;
|
|
|
|
}
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
/// Returns true if the device supports VK_EXT_depth_range_unrestricted.
|
|
|
|
bool IsExtDepthRangeUnrestrictedSupported() const {
|
|
|
|
return ext_depth_range_unrestricted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the device supports VK_EXT_shader_viewport_index_layer.
|
|
|
|
bool IsExtShaderViewportIndexLayerSupported() const {
|
|
|
|
return ext_shader_viewport_index_layer;
|
|
|
|
}
|
|
|
|
|
2021-03-24 01:27:17 +01:00
|
|
|
/// Returns true if the device supports VK_EXT_subgroup_size_control.
|
|
|
|
bool IsExtSubgroupSizeControlSupported() const {
|
|
|
|
return ext_subgroup_size_control;
|
|
|
|
}
|
|
|
|
|
2020-03-06 09:09:06 +01:00
|
|
|
/// Returns true if the device supports VK_EXT_transform_feedback.
|
|
|
|
bool IsExtTransformFeedbackSupported() const {
|
|
|
|
return ext_transform_feedback;
|
|
|
|
}
|
|
|
|
|
2020-05-04 21:41:19 +02:00
|
|
|
/// Returns true if the device supports VK_EXT_custom_border_color.
|
|
|
|
bool IsExtCustomBorderColorSupported() const {
|
|
|
|
return ext_custom_border_color;
|
|
|
|
}
|
|
|
|
|
2020-06-21 22:20:30 +02:00
|
|
|
/// Returns true if the device supports VK_EXT_extended_dynamic_state.
|
|
|
|
bool IsExtExtendedDynamicStateSupported() const {
|
|
|
|
return ext_extended_dynamic_state;
|
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
/// Returns true if the device supports VK_EXT_shader_stencil_export.
|
|
|
|
bool IsExtShaderStencilExportSupported() const {
|
|
|
|
return ext_shader_stencil_export;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true when a known debugging tool is attached.
|
|
|
|
bool HasDebuggingToolAttached() const {
|
|
|
|
return has_renderdoc || has_nsight_graphics;
|
|
|
|
}
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
/// Returns the vendor name reported from Vulkan.
|
|
|
|
std::string_view GetVendorName() const {
|
|
|
|
return vendor_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the list of available extensions.
|
|
|
|
const std::vector<std::string>& GetAvailableExtensions() const {
|
|
|
|
return reported_extensions;
|
|
|
|
}
|
|
|
|
|
2021-06-17 00:29:48 +02:00
|
|
|
u64 GetDeviceLocalMemory() const {
|
|
|
|
return device_access_memory;
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:50:25 +01:00
|
|
|
private:
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Checks if the physical device is suitable.
|
2021-01-17 00:42:02 +01:00
|
|
|
void CheckSuitability(bool requires_swapchain) const;
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Loads extensions into a vector and stores available ones in this object.
|
2021-01-17 00:42:02 +01:00
|
|
|
std::vector<const char*> LoadExtensions(bool requires_surface);
|
2019-05-26 06:33:57 +02:00
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Sets up queue families.
|
2020-03-27 05:33:21 +01:00
|
|
|
void SetupFamilies(VkSurfaceKHR surface);
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Sets up device features.
|
2020-04-02 07:32:58 +02:00
|
|
|
void SetupFeatures();
|
2019-05-26 06:33:57 +02:00
|
|
|
|
2021-02-20 07:30:13 +01:00
|
|
|
/// Sets up device properties.
|
|
|
|
void SetupProperties();
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
/// Collects telemetry information from the device.
|
|
|
|
void CollectTelemetryParameters();
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
/// Collects information about attached tools.
|
|
|
|
void CollectToolingInfo();
|
|
|
|
|
2021-06-17 00:29:48 +02:00
|
|
|
/// Collects information about the device's local memory.
|
|
|
|
void CollectPhysicalMemoryInfo();
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Returns a list of queue initialization descriptors.
|
2020-03-27 05:33:21 +01:00
|
|
|
std::vector<VkDeviceQueueCreateInfo> GetDeviceQueueCreateInfos() const;
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
/// Returns true if ASTC textures are natively supported.
|
2020-03-27 05:33:21 +01:00
|
|
|
bool IsOptimalAstcSupported(const VkPhysicalDeviceFeatures& features) const;
|
2019-05-26 06:33:57 +02:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
/// Returns true if the device natively supports blitting depth stencil images.
|
|
|
|
bool TestDepthStencilBlits() const;
|
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
/// Returns true if a format is supported.
|
2020-03-27 05:33:21 +01:00
|
|
|
bool IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
|
2019-02-12 22:28:05 +01:00
|
|
|
FormatType format_type) const;
|
|
|
|
|
2021-02-20 07:30:13 +01:00
|
|
|
VkInstance instance; ///< Vulkan instance.
|
|
|
|
vk::DeviceDispatch dld; ///< Device function pointers.
|
|
|
|
vk::PhysicalDevice physical; ///< Physical device.
|
|
|
|
VkPhysicalDeviceProperties properties; ///< Device properties.
|
|
|
|
VkPhysicalDeviceFloatControlsPropertiesKHR float_controls{}; ///< Float control properties.
|
|
|
|
vk::Device logical; ///< Logical device.
|
|
|
|
vk::Queue graphics_queue; ///< Main graphics queue.
|
|
|
|
vk::Queue present_queue; ///< Main present queue.
|
|
|
|
u32 instance_version{}; ///< Vulkan onstance version.
|
2021-06-25 07:38:56 +02:00
|
|
|
u32 graphics_family{}; ///< Main graphics queue family index.
|
|
|
|
u32 present_family{}; ///< Main present queue family index.
|
|
|
|
VkDriverIdKHR driver_id{}; ///< Driver ID.
|
|
|
|
VkShaderStageFlags guest_warp_stages{}; ///< Stages where the guest warp size can be forced.
|
|
|
|
u64 device_access_memory{}; ///< Total size of device local memory in bytes.
|
|
|
|
bool is_optimal_astc_supported{}; ///< Support for native ASTC.
|
|
|
|
bool is_float16_supported{}; ///< Support for float16 arithmetics.
|
|
|
|
bool is_warp_potentially_bigger{}; ///< Host warp size can be bigger than guest.
|
2021-01-15 06:45:44 +01:00
|
|
|
bool is_formatless_image_load_supported{}; ///< Support for shader image read without format.
|
|
|
|
bool is_shader_storage_image_multisample{}; ///< Support for image operations on MSAA images.
|
|
|
|
bool is_blit_depth_stencil_supported{}; ///< Support for blitting from and to depth stencil.
|
|
|
|
bool nv_viewport_swizzle{}; ///< Support for VK_NV_viewport_swizzle.
|
2021-03-29 00:53:34 +02:00
|
|
|
bool khr_uniform_buffer_standard_layout{}; ///< Support for scalar uniform buffer layouts.
|
|
|
|
bool khr_spirv_1_4{}; ///< Support for VK_KHR_spirv_1_4.
|
|
|
|
bool khr_workgroup_memory_explicit_layout{}; ///< Support for explicit workgroup layouts.
|
|
|
|
bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8.
|
|
|
|
bool ext_sampler_filter_minmax{}; ///< Support for VK_EXT_sampler_filter_minmax.
|
|
|
|
bool ext_depth_range_unrestricted{}; ///< Support for VK_EXT_depth_range_unrestricted.
|
|
|
|
bool ext_shader_viewport_index_layer{}; ///< Support for VK_EXT_shader_viewport_index_layer.
|
|
|
|
bool ext_tooling_info{}; ///< Support for VK_EXT_tooling_info.
|
|
|
|
bool ext_subgroup_size_control{}; ///< Support for VK_EXT_subgroup_size_control.
|
|
|
|
bool ext_transform_feedback{}; ///< Support for VK_EXT_transform_feedback.
|
|
|
|
bool ext_custom_border_color{}; ///< Support for VK_EXT_custom_border_color.
|
|
|
|
bool ext_extended_dynamic_state{}; ///< Support for VK_EXT_extended_dynamic_state.
|
|
|
|
bool ext_shader_stencil_export{}; ///< Support for VK_EXT_shader_stencil_export.
|
|
|
|
bool nv_device_diagnostics_config{}; ///< Support for VK_NV_device_diagnostics_config.
|
|
|
|
bool has_renderdoc{}; ///< Has RenderDoc attached
|
|
|
|
bool has_nsight_graphics{}; ///< Has Nsight Graphics attached
|
2020-08-02 19:05:41 +02:00
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
// Telemetry parameters
|
|
|
|
std::string vendor_name; ///< Device's driver name.
|
|
|
|
std::vector<std::string> reported_extensions; ///< Reported Vulkan extensions.
|
|
|
|
|
|
|
|
/// Format properties dictionary.
|
2020-03-27 05:33:21 +01:00
|
|
|
std::unordered_map<VkFormat, VkFormatProperties> format_properties;
|
2020-03-30 10:21:59 +02:00
|
|
|
|
|
|
|
/// Nsight Aftermath GPU crash tracker
|
2020-12-26 05:26:52 +01:00
|
|
|
std::unique_ptr<NsightAftermathTracker> nsight_aftermath_tracker;
|
2019-02-12 22:28:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|