summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/renderer_vulkan/vk_device.cpp276
1 files changed, 152 insertions, 124 deletions
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp
index fdaea4210..9226e591c 100644
--- a/src/video_core/renderer_vulkan/vk_device.cpp
+++ b/src/video_core/renderer_vulkan/vk_device.cpp
@@ -22,14 +22,21 @@ namespace {
22 22
23namespace Alternatives { 23namespace Alternatives {
24 24
25constexpr std::array Depth24UnormS8_UINT = {VK_FORMAT_D32_SFLOAT_S8_UINT, 25constexpr std::array Depth24UnormS8_UINT{
26 VK_FORMAT_D16_UNORM_S8_UINT, VkFormat{}}; 26 VK_FORMAT_D32_SFLOAT_S8_UINT,
27constexpr std::array Depth16UnormS8_UINT = {VK_FORMAT_D24_UNORM_S8_UINT, 27 VK_FORMAT_D16_UNORM_S8_UINT,
28 VK_FORMAT_D32_SFLOAT_S8_UINT, VkFormat{}}; 28 VkFormat{},
29};
30
31constexpr std::array Depth16UnormS8_UINT{
32 VK_FORMAT_D24_UNORM_S8_UINT,
33 VK_FORMAT_D32_SFLOAT_S8_UINT,
34 VkFormat{},
35};
29 36
30} // namespace Alternatives 37} // namespace Alternatives
31 38
32constexpr std::array REQUIRED_EXTENSIONS = { 39constexpr std::array REQUIRED_EXTENSIONS{
33 VK_KHR_SWAPCHAIN_EXTENSION_NAME, 40 VK_KHR_SWAPCHAIN_EXTENSION_NAME,
34 VK_KHR_16BIT_STORAGE_EXTENSION_NAME, 41 VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
35 VK_KHR_8BIT_STORAGE_EXTENSION_NAME, 42 VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
@@ -169,97 +176,104 @@ bool VKDevice::Create() {
169 const auto queue_cis = GetDeviceQueueCreateInfos(); 176 const auto queue_cis = GetDeviceQueueCreateInfos();
170 const std::vector extensions = LoadExtensions(); 177 const std::vector extensions = LoadExtensions();
171 178
172 VkPhysicalDeviceFeatures2 features2; 179 VkPhysicalDeviceFeatures2 features2{
173 features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; 180 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
174 features2.pNext = nullptr; 181 .pNext = nullptr,
182 };
175 const void* first_next = &features2; 183 const void* first_next = &features2;
176 void** next = &features2.pNext; 184 void** next = &features2.pNext;
177 185
178 auto& features = features2.features; 186 features2.features = {
179 features.robustBufferAccess = false; 187 .robustBufferAccess = false,
180 features.fullDrawIndexUint32 = false; 188 .fullDrawIndexUint32 = false,
181 features.imageCubeArray = false; 189 .imageCubeArray = false,
182 features.independentBlend = true; 190 .independentBlend = true,
183 features.geometryShader = true; 191 .geometryShader = true,
184 features.tessellationShader = true; 192 .tessellationShader = true,
185 features.sampleRateShading = false; 193 .sampleRateShading = false,
186 features.dualSrcBlend = false; 194 .dualSrcBlend = false,
187 features.logicOp = false; 195 .logicOp = false,
188 features.multiDrawIndirect = false; 196 .multiDrawIndirect = false,
189 features.drawIndirectFirstInstance = false; 197 .drawIndirectFirstInstance = false,
190 features.depthClamp = true; 198 .depthClamp = true,
191 features.depthBiasClamp = true; 199 .depthBiasClamp = true,
192 features.fillModeNonSolid = false; 200 .fillModeNonSolid = false,
193 features.depthBounds = false; 201 .depthBounds = false,
194 features.wideLines = false; 202 .wideLines = false,
195 features.largePoints = true; 203 .largePoints = true,
196 features.alphaToOne = false; 204 .alphaToOne = false,
197 features.multiViewport = true; 205 .multiViewport = true,
198 features.samplerAnisotropy = true; 206 .samplerAnisotropy = true,
199 features.textureCompressionETC2 = false; 207 .textureCompressionETC2 = false,
200 features.textureCompressionASTC_LDR = is_optimal_astc_supported; 208 .textureCompressionASTC_LDR = is_optimal_astc_supported,
201 features.textureCompressionBC = false; 209 .textureCompressionBC = false,
202 features.occlusionQueryPrecise = true; 210 .occlusionQueryPrecise = true,
203 features.pipelineStatisticsQuery = false; 211 .pipelineStatisticsQuery = false,
204 features.vertexPipelineStoresAndAtomics = true; 212 .vertexPipelineStoresAndAtomics = true,
205 features.fragmentStoresAndAtomics = true; 213 .fragmentStoresAndAtomics = true,
206 features.shaderTessellationAndGeometryPointSize = false; 214 .shaderTessellationAndGeometryPointSize = false,
207 features.shaderImageGatherExtended = true; 215 .shaderImageGatherExtended = true,
208 features.shaderStorageImageExtendedFormats = false; 216 .shaderStorageImageExtendedFormats = false,
209 features.shaderStorageImageMultisample = false; 217 .shaderStorageImageMultisample = false,
210 features.shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported; 218 .shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported,
211 features.shaderStorageImageWriteWithoutFormat = true; 219 .shaderStorageImageWriteWithoutFormat = true,
212 features.shaderUniformBufferArrayDynamicIndexing = false; 220 .shaderUniformBufferArrayDynamicIndexing = false,
213 features.shaderSampledImageArrayDynamicIndexing = false; 221 .shaderSampledImageArrayDynamicIndexing = false,
214 features.shaderStorageBufferArrayDynamicIndexing = false; 222 .shaderStorageBufferArrayDynamicIndexing = false,
215 features.shaderStorageImageArrayDynamicIndexing = false; 223 .shaderStorageImageArrayDynamicIndexing = false,
216 features.shaderClipDistance = false; 224 .shaderClipDistance = false,
217 features.shaderCullDistance = false; 225 .shaderCullDistance = false,
218 features.shaderFloat64 = false; 226 .shaderFloat64 = false,
219 features.shaderInt64 = false; 227 .shaderInt64 = false,
220 features.shaderInt16 = false; 228 .shaderInt16 = false,
221 features.shaderResourceResidency = false; 229 .shaderResourceResidency = false,
222 features.shaderResourceMinLod = false; 230 .shaderResourceMinLod = false,
223 features.sparseBinding = false; 231 .sparseBinding = false,
224 features.sparseResidencyBuffer = false; 232 .sparseResidencyBuffer = false,
225 features.sparseResidencyImage2D = false; 233 .sparseResidencyImage2D = false,
226 features.sparseResidencyImage3D = false; 234 .sparseResidencyImage3D = false,
227 features.sparseResidency2Samples = false; 235 .sparseResidency2Samples = false,
228 features.sparseResidency4Samples = false; 236 .sparseResidency4Samples = false,
229 features.sparseResidency8Samples = false; 237 .sparseResidency8Samples = false,
230 features.sparseResidency16Samples = false; 238 .sparseResidency16Samples = false,
231 features.sparseResidencyAliased = false; 239 .sparseResidencyAliased = false,
232 features.variableMultisampleRate = false; 240 .variableMultisampleRate = false,
233 features.inheritedQueries = false; 241 .inheritedQueries = false,
234 242 };
235 VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage; 243
236 bit16_storage.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR; 244 VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage{
237 bit16_storage.pNext = nullptr; 245 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR,
238 bit16_storage.storageBuffer16BitAccess = false; 246 .pNext = nullptr,
239 bit16_storage.uniformAndStorageBuffer16BitAccess = true; 247 .storageBuffer16BitAccess = false,
240 bit16_storage.storagePushConstant16 = false; 248 .uniformAndStorageBuffer16BitAccess = true,
241 bit16_storage.storageInputOutput16 = false; 249 .storagePushConstant16 = false,
250 .storageInputOutput16 = false,
251 };
242 SetNext(next, bit16_storage); 252 SetNext(next, bit16_storage);
243 253
244 VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage; 254 VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage{
245 bit8_storage.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR; 255 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR,
246 bit8_storage.pNext = nullptr; 256 .pNext = nullptr,
247 bit8_storage.storageBuffer8BitAccess = false; 257 .storageBuffer8BitAccess = false,
248 bit8_storage.uniformAndStorageBuffer8BitAccess = true; 258 .uniformAndStorageBuffer8BitAccess = true,
249 bit8_storage.storagePushConstant8 = false; 259 .storagePushConstant8 = false,
260 };
250 SetNext(next, bit8_storage); 261 SetNext(next, bit8_storage);
251 262
252 VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset; 263 VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset{
253 host_query_reset.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT; 264 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
254 host_query_reset.hostQueryReset = true; 265 .hostQueryReset = true,
266 };
255 SetNext(next, host_query_reset); 267 SetNext(next, host_query_reset);
256 268
257 VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8; 269 VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
258 if (is_float16_supported) { 270 if (is_float16_supported) {
259 float16_int8.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR; 271 float16_int8 = {
260 float16_int8.pNext = nullptr; 272 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
261 float16_int8.shaderFloat16 = true; 273 .pNext = nullptr,
262 float16_int8.shaderInt8 = false; 274 .shaderFloat16 = true,
275 .shaderInt8 = false,
276 };
263 SetNext(next, float16_int8); 277 SetNext(next, float16_int8);
264 } else { 278 } else {
265 LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively"); 279 LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
@@ -271,10 +285,11 @@ bool VKDevice::Create() {
271 285
272 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout; 286 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
273 if (khr_uniform_buffer_standard_layout) { 287 if (khr_uniform_buffer_standard_layout) {
274 std430_layout.sType = 288 std430_layout = {
275 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR; 289 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR,
276 std430_layout.pNext = nullptr; 290 .pNext = nullptr,
277 std430_layout.uniformBufferStandardLayout = true; 291 .uniformBufferStandardLayout = true,
292 };
278 SetNext(next, std430_layout); 293 SetNext(next, std430_layout);
279 } else { 294 } else {
280 LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs"); 295 LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
@@ -282,9 +297,11 @@ bool VKDevice::Create() {
282 297
283 VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8; 298 VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
284 if (ext_index_type_uint8) { 299 if (ext_index_type_uint8) {
285 index_type_uint8.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT; 300 index_type_uint8 = {
286 index_type_uint8.pNext = nullptr; 301 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT,
287 index_type_uint8.indexTypeUint8 = true; 302 .pNext = nullptr,
303 .indexTypeUint8 = true,
304 };
288 SetNext(next, index_type_uint8); 305 SetNext(next, index_type_uint8);
289 } else { 306 } else {
290 LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes"); 307 LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
@@ -292,11 +309,12 @@ bool VKDevice::Create() {
292 309
293 VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback; 310 VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
294 if (ext_transform_feedback) { 311 if (ext_transform_feedback) {
295 transform_feedback.sType = 312 transform_feedback = {
296 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT; 313 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT,
297 transform_feedback.pNext = nullptr; 314 .pNext = nullptr,
298 transform_feedback.transformFeedback = true; 315 .transformFeedback = true,
299 transform_feedback.geometryStreams = true; 316 .geometryStreams = true,
317 };
300 SetNext(next, transform_feedback); 318 SetNext(next, transform_feedback);
301 } else { 319 } else {
302 LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks"); 320 LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks");
@@ -304,10 +322,12 @@ bool VKDevice::Create() {
304 322
305 VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border; 323 VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border;
306 if (ext_custom_border_color) { 324 if (ext_custom_border_color) {
307 custom_border.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT; 325 custom_border = {
308 custom_border.pNext = nullptr; 326 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT,
309 custom_border.customBorderColors = VK_TRUE; 327 .pNext = nullptr,
310 custom_border.customBorderColorWithoutFormat = VK_TRUE; 328 .customBorderColors = VK_TRUE,
329 .customBorderColorWithoutFormat = VK_TRUE,
330 };
311 SetNext(next, custom_border); 331 SetNext(next, custom_border);
312 } else { 332 } else {
313 LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors"); 333 LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors");
@@ -315,9 +335,11 @@ bool VKDevice::Create() {
315 335
316 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state; 336 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
317 if (ext_extended_dynamic_state) { 337 if (ext_extended_dynamic_state) {
318 dynamic_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT; 338 dynamic_state = {
319 dynamic_state.pNext = nullptr; 339 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT,
320 dynamic_state.extendedDynamicState = VK_TRUE; 340 .pNext = nullptr,
341 .extendedDynamicState = VK_TRUE,
342 };
321 SetNext(next, dynamic_state); 343 SetNext(next, dynamic_state);
322 } else { 344 } else {
323 LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state"); 345 LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state");
@@ -331,11 +353,13 @@ bool VKDevice::Create() {
331 if (nv_device_diagnostics_config) { 353 if (nv_device_diagnostics_config) {
332 nsight_aftermath_tracker.Initialize(); 354 nsight_aftermath_tracker.Initialize();
333 355
334 diagnostics_nv.sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV; 356 diagnostics_nv = {
335 diagnostics_nv.pNext = &features2; 357 .sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV,
336 diagnostics_nv.flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV | 358 .pNext = &features2,
337 VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV | 359 .flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV |
338 VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV; 360 VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
361 VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV,
362 };
339 first_next = &diagnostics_nv; 363 first_next = &diagnostics_nv;
340 } 364 }
341 365
@@ -704,13 +728,15 @@ void VKDevice::SetupFeatures() {
704} 728}
705 729
706void VKDevice::CollectTelemetryParameters() { 730void VKDevice::CollectTelemetryParameters() {
707 VkPhysicalDeviceDriverPropertiesKHR driver; 731 VkPhysicalDeviceDriverPropertiesKHR driver{
708 driver.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR; 732 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
709 driver.pNext = nullptr; 733 .pNext = nullptr,
734 };
710 735
711 VkPhysicalDeviceProperties2KHR properties; 736 VkPhysicalDeviceProperties2KHR properties{
712 properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; 737 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
713 properties.pNext = &driver; 738 .pNext = &driver,
739 };
714 physical.GetProperties2KHR(properties); 740 physical.GetProperties2KHR(properties);
715 741
716 driver_id = driver.driverID; 742 driver_id = driver.driverID;
@@ -719,24 +745,26 @@ void VKDevice::CollectTelemetryParameters() {
719 const std::vector extensions = physical.EnumerateDeviceExtensionProperties(); 745 const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
720 reported_extensions.reserve(std::size(extensions)); 746 reported_extensions.reserve(std::size(extensions));
721 for (const auto& extension : extensions) { 747 for (const auto& extension : extensions) {
722 reported_extensions.push_back(extension.extensionName); 748 reported_extensions.emplace_back(extension.extensionName);
723 } 749 }
724} 750}
725 751
726std::vector<VkDeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const { 752std::vector<VkDeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const {
727 static constexpr float QUEUE_PRIORITY = 1.0f; 753 static constexpr float QUEUE_PRIORITY = 1.0f;
728 754
729 std::unordered_set<u32> unique_queue_families = {graphics_family, present_family}; 755 std::unordered_set<u32> unique_queue_families{graphics_family, present_family};
730 std::vector<VkDeviceQueueCreateInfo> queue_cis; 756 std::vector<VkDeviceQueueCreateInfo> queue_cis;
757 queue_cis.reserve(unique_queue_families.size());
731 758
732 for (const u32 queue_family : unique_queue_families) { 759 for (const u32 queue_family : unique_queue_families) {
733 VkDeviceQueueCreateInfo& ci = queue_cis.emplace_back(); 760 queue_cis.push_back({
734 ci.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 761 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
735 ci.pNext = nullptr; 762 .pNext = nullptr,
736 ci.flags = 0; 763 .flags = 0,
737 ci.queueFamilyIndex = queue_family; 764 .queueFamilyIndex = queue_family,
738 ci.queueCount = 1; 765 .queueCount = 1,
739 ci.pQueuePriorities = &QUEUE_PRIORITY; 766 .pQueuePriorities = &QUEUE_PRIORITY,
767 });
740 } 768 }
741 769
742 return queue_cis; 770 return queue_cis;