summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-05-26 01:33:57 -0300
committerGravatar ReinUsesLisp2019-05-26 01:41:34 -0300
commitdec3c981d0f4310243c0a5a77fca89df44fea0e3 (patch)
tree1a2ee7e1b00fc4f93a277903ccfae0ce524b7154
parentMerge pull request #2516 from lioncash/label (diff)
downloadyuzu-dec3c981d0f4310243c0a5a77fca89df44fea0e3.tar.gz
yuzu-dec3c981d0f4310243c0a5a77fca89df44fea0e3.tar.xz
yuzu-dec3c981d0f4310243c0a5a77fca89df44fea0e3.zip
vk_device: Enable features when available and misc changes
Keeps track of native ASTC support, VK_EXT_scalar_block_layout availability and SSBO range. Check for independentBlend and vertexPipelineStorageAndAtomics as a required feature. Always enable it. Use vk::to_string format to log Vulkan enums. Style changes.
-rw-r--r--src/video_core/renderer_vulkan/vk_device.cpp136
-rw-r--r--src/video_core/renderer_vulkan/vk_device.h58
2 files changed, 151 insertions, 43 deletions
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp
index 00242ecbe..f39985c40 100644
--- a/src/video_core/renderer_vulkan/vk_device.cpp
+++ b/src/video_core/renderer_vulkan/vk_device.cpp
@@ -18,6 +18,7 @@ constexpr std::array<vk::Format, 3> Depth24UnormS8Uint = {
18 vk::Format::eD32SfloatS8Uint, vk::Format::eD16UnormS8Uint, {}}; 18 vk::Format::eD32SfloatS8Uint, vk::Format::eD16UnormS8Uint, {}};
19constexpr std::array<vk::Format, 3> Depth16UnormS8Uint = { 19constexpr std::array<vk::Format, 3> Depth16UnormS8Uint = {
20 vk::Format::eD24UnormS8Uint, vk::Format::eD32SfloatS8Uint, {}}; 20 vk::Format::eD24UnormS8Uint, vk::Format::eD32SfloatS8Uint, {}};
21constexpr std::array<vk::Format, 2> Astc = {vk::Format::eA8B8G8R8UnormPack32, {}};
21 22
22} // namespace Alternatives 23} // namespace Alternatives
23 24
@@ -51,15 +52,19 @@ VKDevice::VKDevice(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice phy
51 : physical{physical}, format_properties{GetFormatProperties(dldi, physical)} { 52 : physical{physical}, format_properties{GetFormatProperties(dldi, physical)} {
52 SetupFamilies(dldi, surface); 53 SetupFamilies(dldi, surface);
53 SetupProperties(dldi); 54 SetupProperties(dldi);
55 SetupFeatures(dldi);
54} 56}
55 57
56VKDevice::~VKDevice() = default; 58VKDevice::~VKDevice() = default;
57 59
58bool VKDevice::Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instance) { 60bool VKDevice::Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instance) {
59 const auto queue_cis = GetDeviceQueueCreateInfos(); 61 vk::PhysicalDeviceFeatures device_features;
60 vk::PhysicalDeviceFeatures device_features{}; 62 device_features.vertexPipelineStoresAndAtomics = true;
63 device_features.independentBlend = true;
64 device_features.textureCompressionASTC_LDR = is_optimal_astc_supported;
61 65
62 const std::vector<const char*> extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; 66 const auto queue_cis = GetDeviceQueueCreateInfos();
67 const std::vector<const char*> extensions = LoadExtensions(dldi);
63 const vk::DeviceCreateInfo device_ci({}, static_cast<u32>(queue_cis.size()), queue_cis.data(), 68 const vk::DeviceCreateInfo device_ci({}, static_cast<u32>(queue_cis.size()), queue_cis.data(),
64 0, nullptr, static_cast<u32>(extensions.size()), 69 0, nullptr, static_cast<u32>(extensions.size()),
65 extensions.data(), &device_features); 70 extensions.data(), &device_features);
@@ -90,7 +95,7 @@ vk::Format VKDevice::GetSupportedFormat(vk::Format wanted_format,
90 LOG_CRITICAL(Render_Vulkan, 95 LOG_CRITICAL(Render_Vulkan,
91 "Format={} with usage={} and type={} has no defined alternatives and host " 96 "Format={} with usage={} and type={} has no defined alternatives and host "
92 "hardware does not support it", 97 "hardware does not support it",
93 static_cast<u32>(wanted_format), static_cast<u32>(wanted_usage), 98 vk::to_string(wanted_format), vk::to_string(wanted_usage),
94 static_cast<u32>(format_type)); 99 static_cast<u32>(format_type));
95 UNREACHABLE(); 100 UNREACHABLE();
96 return wanted_format; 101 return wanted_format;
@@ -118,6 +123,30 @@ vk::Format VKDevice::GetSupportedFormat(vk::Format wanted_format,
118 return wanted_format; 123 return wanted_format;
119} 124}
120 125
126bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features,
127 const vk::DispatchLoaderDynamic& dldi) const {
128 if (!features.textureCompressionASTC_LDR) {
129 return false;
130 }
131 const auto format_feature_usage{
132 vk::FormatFeatureFlagBits::eSampledImage | vk::FormatFeatureFlagBits::eBlitSrc |
133 vk::FormatFeatureFlagBits::eBlitDst | vk::FormatFeatureFlagBits::eTransferSrc |
134 vk::FormatFeatureFlagBits::eTransferDst};
135 constexpr std::array<vk::Format, 9> astc_formats = {
136 vk::Format::eAstc4x4UnormBlock, vk::Format::eAstc4x4SrgbBlock,
137 vk::Format::eAstc8x8SrgbBlock, vk::Format::eAstc8x6SrgbBlock,
138 vk::Format::eAstc5x4SrgbBlock, vk::Format::eAstc5x5UnormBlock,
139 vk::Format::eAstc5x5SrgbBlock, vk::Format::eAstc10x8UnormBlock,
140 vk::Format::eAstc10x8SrgbBlock};
141 for (const auto format : astc_formats) {
142 const auto format_properties{physical.getFormatProperties(format, dldi)};
143 if (!(format_properties.optimalTilingFeatures & format_feature_usage)) {
144 return false;
145 }
146 }
147 return true;
148}
149
121bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage, 150bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
122 FormatType format_type) const { 151 FormatType format_type) const {
123 const auto it = format_properties.find(wanted_format); 152 const auto it = format_properties.find(wanted_format);
@@ -132,11 +161,9 @@ bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlag
132 161
133bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical, 162bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical,
134 vk::SurfaceKHR surface) { 163 vk::SurfaceKHR surface) {
135 const std::string swapchain_extension = VK_KHR_SWAPCHAIN_EXTENSION_NAME;
136
137 bool has_swapchain{}; 164 bool has_swapchain{};
138 for (const auto& prop : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) { 165 for (const auto& prop : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) {
139 has_swapchain |= prop.extensionName == swapchain_extension; 166 has_swapchain |= prop.extensionName == std::string(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
140 } 167 }
141 if (!has_swapchain) { 168 if (!has_swapchain) {
142 // The device doesn't support creating swapchains. 169 // The device doesn't support creating swapchains.
@@ -160,8 +187,14 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev
160 } 187 }
161 188
162 // TODO(Rodrigo): Check if the device matches all requeriments. 189 // TODO(Rodrigo): Check if the device matches all requeriments.
163 const vk::PhysicalDeviceProperties props = physical.getProperties(dldi); 190 const auto properties{physical.getProperties(dldi)};
164 if (props.limits.maxUniformBufferRange < 65536) { 191 const auto limits{properties.limits};
192 if (limits.maxUniformBufferRange < 65536) {
193 return false;
194 }
195
196 const vk::PhysicalDeviceFeatures features{physical.getFeatures(dldi)};
197 if (!features.vertexPipelineStoresAndAtomics || !features.independentBlend) {
165 return false; 198 return false;
166 } 199 }
167 200
@@ -169,6 +202,30 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev
169 return true; 202 return true;
170} 203}
171 204
205std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynamic& dldi) {
206 std::vector<const char*> extensions;
207 extensions.reserve(2);
208 extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
209
210 const auto Test = [&](const vk::ExtensionProperties& extension,
211 std::optional<std::reference_wrapper<bool>> status, const char* name,
212 u32 revision) {
213 if (extension.extensionName != std::string(name)) {
214 return;
215 }
216 extensions.push_back(name);
217 if (status) {
218 status->get() = true;
219 }
220 };
221
222 for (const auto& extension : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) {
223 Test(extension, ext_scalar_block_layout, VK_EXT_SCALAR_BLOCK_LAYOUT_EXTENSION_NAME, 1);
224 }
225
226 return extensions;
227}
228
172void VKDevice::SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface) { 229void VKDevice::SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface) {
173 std::optional<u32> graphics_family_, present_family_; 230 std::optional<u32> graphics_family_, present_family_;
174 231
@@ -196,10 +253,16 @@ void VKDevice::SetupProperties(const vk::DispatchLoaderDynamic& dldi) {
196 const vk::PhysicalDeviceProperties props = physical.getProperties(dldi); 253 const vk::PhysicalDeviceProperties props = physical.getProperties(dldi);
197 device_type = props.deviceType; 254 device_type = props.deviceType;
198 uniform_buffer_alignment = static_cast<u64>(props.limits.minUniformBufferOffsetAlignment); 255 uniform_buffer_alignment = static_cast<u64>(props.limits.minUniformBufferOffsetAlignment);
256 max_storage_buffer_range = static_cast<u64>(props.limits.maxStorageBufferRange);
257}
258
259void VKDevice::SetupFeatures(const vk::DispatchLoaderDynamic& dldi) {
260 const auto supported_features{physical.getFeatures(dldi)};
261 is_optimal_astc_supported = IsOptimalAstcSupported(supported_features, dldi);
199} 262}
200 263
201std::vector<vk::DeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const { 264std::vector<vk::DeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const {
202 static const float QUEUE_PRIORITY = 1.f; 265 static const float QUEUE_PRIORITY = 1.0f;
203 266
204 std::set<u32> unique_queue_families = {graphics_family, present_family}; 267 std::set<u32> unique_queue_families = {graphics_family, present_family};
205 std::vector<vk::DeviceQueueCreateInfo> queue_cis; 268 std::vector<vk::DeviceQueueCreateInfo> queue_cis;
@@ -212,26 +275,43 @@ std::vector<vk::DeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() con
212 275
213std::map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties( 276std::map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties(
214 const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical) { 277 const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical) {
278 static constexpr std::array<vk::Format, 33> formats = {vk::Format::eA8B8G8R8UnormPack32,
279 vk::Format::eB5G6R5UnormPack16,
280 vk::Format::eA2B10G10R10UnormPack32,
281 vk::Format::eR32G32B32A32Sfloat,
282 vk::Format::eR16G16Unorm,
283 vk::Format::eR16G16Snorm,
284 vk::Format::eR8G8B8A8Srgb,
285 vk::Format::eR8Unorm,
286 vk::Format::eB10G11R11UfloatPack32,
287 vk::Format::eR32Sfloat,
288 vk::Format::eR16Sfloat,
289 vk::Format::eR16G16B16A16Sfloat,
290 vk::Format::eD32Sfloat,
291 vk::Format::eD16Unorm,
292 vk::Format::eD16UnormS8Uint,
293 vk::Format::eD24UnormS8Uint,
294 vk::Format::eD32SfloatS8Uint,
295 vk::Format::eBc1RgbaUnormBlock,
296 vk::Format::eBc2UnormBlock,
297 vk::Format::eBc3UnormBlock,
298 vk::Format::eBc4UnormBlock,
299 vk::Format::eBc5UnormBlock,
300 vk::Format::eBc5SnormBlock,
301 vk::Format::eBc7UnormBlock,
302 vk::Format::eAstc4x4UnormBlock,
303 vk::Format::eAstc4x4SrgbBlock,
304 vk::Format::eAstc8x8SrgbBlock,
305 vk::Format::eAstc8x6SrgbBlock,
306 vk::Format::eAstc5x4SrgbBlock,
307 vk::Format::eAstc5x5UnormBlock,
308 vk::Format::eAstc5x5SrgbBlock,
309 vk::Format::eAstc10x8UnormBlock,
310 vk::Format::eAstc10x8SrgbBlock};
215 std::map<vk::Format, vk::FormatProperties> format_properties; 311 std::map<vk::Format, vk::FormatProperties> format_properties;
216 312 for (const auto format : formats) {
217 const auto AddFormatQuery = [&format_properties, &dldi, physical](vk::Format format) {
218 format_properties.emplace(format, physical.getFormatProperties(format, dldi)); 313 format_properties.emplace(format, physical.getFormatProperties(format, dldi));
219 }; 314 }
220 AddFormatQuery(vk::Format::eA8B8G8R8UnormPack32);
221 AddFormatQuery(vk::Format::eB5G6R5UnormPack16);
222 AddFormatQuery(vk::Format::eA2B10G10R10UnormPack32);
223 AddFormatQuery(vk::Format::eR8G8B8A8Srgb);
224 AddFormatQuery(vk::Format::eR8Unorm);
225 AddFormatQuery(vk::Format::eD32Sfloat);
226 AddFormatQuery(vk::Format::eD16Unorm);
227 AddFormatQuery(vk::Format::eD16UnormS8Uint);
228 AddFormatQuery(vk::Format::eD24UnormS8Uint);
229 AddFormatQuery(vk::Format::eD32SfloatS8Uint);
230 AddFormatQuery(vk::Format::eBc1RgbaUnormBlock);
231 AddFormatQuery(vk::Format::eBc2UnormBlock);
232 AddFormatQuery(vk::Format::eBc3UnormBlock);
233 AddFormatQuery(vk::Format::eBc4UnormBlock);
234
235 return format_properties; 315 return format_properties;
236} 316}
237 317
diff --git a/src/video_core/renderer_vulkan/vk_device.h b/src/video_core/renderer_vulkan/vk_device.h
index e87c7a508..537825d8b 100644
--- a/src/video_core/renderer_vulkan/vk_device.h
+++ b/src/video_core/renderer_vulkan/vk_device.h
@@ -11,7 +11,7 @@
11 11
12namespace Vulkan { 12namespace Vulkan {
13 13
14/// Format usage descriptor 14/// Format usage descriptor.
15enum class FormatType { Linear, Optimal, Buffer }; 15enum class FormatType { Linear, Optimal, Buffer };
16 16
17/// Handles data specific to a physical device. 17/// Handles data specific to a physical device.
@@ -34,12 +34,12 @@ public:
34 vk::Format GetSupportedFormat(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage, 34 vk::Format GetSupportedFormat(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
35 FormatType format_type) const; 35 FormatType format_type) const;
36 36
37 /// Returns the dispatch loader with direct function pointers of the device 37 /// Returns the dispatch loader with direct function pointers of the device.
38 const vk::DispatchLoaderDynamic& GetDispatchLoader() const { 38 const vk::DispatchLoaderDynamic& GetDispatchLoader() const {
39 return dld; 39 return dld;
40 } 40 }
41 41
42 /// Returns the logical device 42 /// Returns the logical device.
43 vk::Device GetLogical() const { 43 vk::Device GetLogical() const {
44 return logical.get(); 44 return logical.get();
45 } 45 }
@@ -69,30 +69,55 @@ public:
69 return present_family; 69 return present_family;
70 } 70 }
71 71
72 /// Returns if the device is integrated with the host CPU 72 /// Returns if the device is integrated with the host CPU.
73 bool IsIntegrated() const { 73 bool IsIntegrated() const {
74 return device_type == vk::PhysicalDeviceType::eIntegratedGpu; 74 return device_type == vk::PhysicalDeviceType::eIntegratedGpu;
75 } 75 }
76 76
77 /// Returns uniform buffer alignment requeriment 77 /// Returns uniform buffer alignment requeriment.
78 u64 GetUniformBufferAlignment() const { 78 u64 GetUniformBufferAlignment() const {
79 return uniform_buffer_alignment; 79 return uniform_buffer_alignment;
80 } 80 }
81 81
82 /// Returns the maximum range for storage buffers.
83 u64 GetMaxStorageBufferRange() const {
84 return max_storage_buffer_range;
85 }
86
87 /// Returns true if ASTC is natively supported.
88 bool IsOptimalAstcSupported() const {
89 return is_optimal_astc_supported;
90 }
91
92 /// Returns true if the device supports VK_EXT_scalar_block_layout.
93 bool IsExtScalarBlockLayoutSupported() const {
94 return ext_scalar_block_layout;
95 }
96
82 /// Checks if the physical device is suitable. 97 /// Checks if the physical device is suitable.
83 static bool IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical, 98 static bool IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical,
84 vk::SurfaceKHR surface); 99 vk::SurfaceKHR surface);
85 100
86private: 101private:
102 /// Loads extensions into a vector and stores available ones in this object.
103 std::vector<const char*> LoadExtensions(const vk::DispatchLoaderDynamic& dldi);
104
87 /// Sets up queue families. 105 /// Sets up queue families.
88 void SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface); 106 void SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface);
89 107
90 /// Sets up device properties. 108 /// Sets up device properties.
91 void SetupProperties(const vk::DispatchLoaderDynamic& dldi); 109 void SetupProperties(const vk::DispatchLoaderDynamic& dldi);
92 110
111 /// Sets up device features.
112 void SetupFeatures(const vk::DispatchLoaderDynamic& dldi);
113
93 /// Returns a list of queue initialization descriptors. 114 /// Returns a list of queue initialization descriptors.
94 std::vector<vk::DeviceQueueCreateInfo> GetDeviceQueueCreateInfos() const; 115 std::vector<vk::DeviceQueueCreateInfo> GetDeviceQueueCreateInfos() const;
95 116
117 /// Returns true if ASTC textures are natively supported.
118 bool IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features,
119 const vk::DispatchLoaderDynamic& dldi) const;
120
96 /// Returns true if a format is supported. 121 /// Returns true if a format is supported.
97 bool IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage, 122 bool IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
98 FormatType format_type) const; 123 FormatType format_type) const;
@@ -101,16 +126,19 @@ private:
101 static std::map<vk::Format, vk::FormatProperties> GetFormatProperties( 126 static std::map<vk::Format, vk::FormatProperties> GetFormatProperties(
102 const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical); 127 const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical);
103 128
104 const vk::PhysicalDevice physical; ///< Physical device 129 const vk::PhysicalDevice physical; ///< Physical device.
105 vk::DispatchLoaderDynamic dld; ///< Device function pointers 130 vk::DispatchLoaderDynamic dld; ///< Device function pointers.
106 UniqueDevice logical; ///< Logical device 131 UniqueDevice logical; ///< Logical device.
107 vk::Queue graphics_queue; ///< Main graphics queue 132 vk::Queue graphics_queue; ///< Main graphics queue.
108 vk::Queue present_queue; ///< Main present queue 133 vk::Queue present_queue; ///< Main present queue.
109 u32 graphics_family{}; ///< Main graphics queue family index 134 u32 graphics_family{}; ///< Main graphics queue family index.
110 u32 present_family{}; ///< Main present queue family index 135 u32 present_family{}; ///< Main present queue family index.
111 vk::PhysicalDeviceType device_type; ///< Physical device type 136 vk::PhysicalDeviceType device_type; ///< Physical device type.
112 u64 uniform_buffer_alignment{}; ///< Uniform buffer alignment requeriment 137 u64 uniform_buffer_alignment{}; ///< Uniform buffer alignment requeriment.
113 std::map<vk::Format, vk::FormatProperties> format_properties; ///< Format properties dictionary 138 u64 max_storage_buffer_range{}; ///< Max storage buffer size.
139 bool is_optimal_astc_supported{}; ///< Support for native ASTC.
140 bool ext_scalar_block_layout{}; ///< Support for VK_EXT_scalar_block_layout.
141 std::map<vk::Format, vk::FormatProperties> format_properties; ///< Format properties dictionary.
114}; 142};
115 143
116} // namespace Vulkan 144} // namespace Vulkan