From 1f333d128d072f70a1c3cce8e5880ff749dffd89 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Mon, 22 Apr 2024 15:58:51 -0400 Subject: [PATCH] Fix device max recursion depth validation warnings in ray tracing examples --- examples/raytracingcallable/raytracingcallable.cpp | 10 +++++++++- .../raytracingintersection/raytracingintersection.cpp | 10 +++++++++- .../raytracingreflections/raytracingreflections.cpp | 10 +++++++++- examples/raytracingshadows/raytracingshadows.cpp | 10 +++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/examples/raytracingcallable/raytracingcallable.cpp b/examples/raytracingcallable/raytracingcallable.cpp index 933868d96..adb0a1cbd 100644 --- a/examples/raytracingcallable/raytracingcallable.cpp +++ b/examples/raytracingcallable/raytracingcallable.cpp @@ -463,12 +463,20 @@ class VulkanExample : public VulkanRaytracingSample shaderGroups.push_back(shaderGroup); } + // Get max pipeline ray tracing recursion depth for physical device + VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {}; + physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR; + VkPhysicalDeviceProperties2 physicalDeviceProperties2; + physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR; + vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2); + VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR(); rayTracingPipelineCI.stageCount = static_cast(shaderStages.size()); rayTracingPipelineCI.pStages = shaderStages.data(); rayTracingPipelineCI.groupCount = static_cast(shaderGroups.size()); rayTracingPipelineCI.pGroups = shaderGroups.data(); - rayTracingPipelineCI.maxPipelineRayRecursionDepth = 2; + rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(2), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth); rayTracingPipelineCI.layout = pipelineLayout; VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline)); } diff --git a/examples/raytracingintersection/raytracingintersection.cpp b/examples/raytracingintersection/raytracingintersection.cpp index 013b8b918..d1e9cb8ed 100644 --- a/examples/raytracingintersection/raytracingintersection.cpp +++ b/examples/raytracingintersection/raytracingintersection.cpp @@ -431,12 +431,20 @@ class VulkanExample : public VulkanRaytracingSample shaderGroups.push_back(shaderGroup); } + // Get max pipeline ray tracing recursion depth for physical device + VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {}; + physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR; + VkPhysicalDeviceProperties2 physicalDeviceProperties2; + physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR; + vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2); + VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR(); rayTracingPipelineCI.stageCount = static_cast(shaderStages.size()); rayTracingPipelineCI.pStages = shaderStages.data(); rayTracingPipelineCI.groupCount = static_cast(shaderGroups.size()); rayTracingPipelineCI.pGroups = shaderGroups.data(); - rayTracingPipelineCI.maxPipelineRayRecursionDepth = 2; + rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(2), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth); rayTracingPipelineCI.layout = pipelineLayout; VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline)); } diff --git a/examples/raytracingreflections/raytracingreflections.cpp b/examples/raytracingreflections/raytracingreflections.cpp index 32ba5c45e..5adc32077 100644 --- a/examples/raytracingreflections/raytracingreflections.cpp +++ b/examples/raytracingreflections/raytracingreflections.cpp @@ -393,12 +393,20 @@ class VulkanExample : public VulkanRaytracingSample shaderGroups.push_back(shaderGroup); } + // Get max pipeline ray tracing recursion depth for physical device + VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {}; + physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR; + VkPhysicalDeviceProperties2 physicalDeviceProperties2; + physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR; + vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2); + VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR(); rayTracingPipelineCI.stageCount = static_cast(shaderStages.size()); rayTracingPipelineCI.pStages = shaderStages.data(); rayTracingPipelineCI.groupCount = static_cast(shaderGroups.size()); rayTracingPipelineCI.pGroups = shaderGroups.data(); - rayTracingPipelineCI.maxPipelineRayRecursionDepth = 4; + rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(4), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth); rayTracingPipelineCI.layout = pipelineLayout; VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline)); } diff --git a/examples/raytracingshadows/raytracingshadows.cpp b/examples/raytracingshadows/raytracingshadows.cpp index 6a575ade2..52ba54450 100644 --- a/examples/raytracingshadows/raytracingshadows.cpp +++ b/examples/raytracingshadows/raytracingshadows.cpp @@ -393,12 +393,20 @@ class VulkanExample : public VulkanRaytracingSample shaderGroups.push_back(shaderGroup); } + // Get max pipeline ray tracing recursion depth for physical device + VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {}; + physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR; + VkPhysicalDeviceProperties2 physicalDeviceProperties2; + physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR; + vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2); + VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR(); rayTracingPipelineCI.stageCount = static_cast(shaderStages.size()); rayTracingPipelineCI.pStages = shaderStages.data(); rayTracingPipelineCI.groupCount = static_cast(shaderGroups.size()); rayTracingPipelineCI.pGroups = shaderGroups.data(); - rayTracingPipelineCI.maxPipelineRayRecursionDepth = 2; + rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(2), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth); rayTracingPipelineCI.layout = pipelineLayout; VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline)); }