Mesa (main): radv/rt: use stage ID as handle for general and closestHit shaders

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 22 15:55:35 UTC 2022


Module: Mesa
Branch: main
Commit: c39cccec9c5a6d027457e625e34db5f0092c076b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c39cccec9c5a6d027457e625e34db5f0092c076b

Author: Daniel Schürmann <daniel at schuermann.dev>
Date:   Fri Apr 22 14:18:36 2022 +0200

radv/rt: use stage ID as handle for general and closestHit shaders

This avoids some code duplication and divergence.

Quake II RTX:
Totals from 7 (0.01% of 134913) affected shaders:
CodeSize: 218880 -> 217592 (-0.59%)
Instrs: 39692 -> 39468 (-0.56%)
Latency: 789091 -> 761581 (-3.49%)
InvThroughput: 526061 -> 507721 (-3.49%)
VClause: 1202 -> 1188 (-1.16%)
Copies: 4649 -> 4621 (-0.60%)
Branches: 1605 -> 1598 (-0.44%)

Reviewed-by: Konstantin Seurer <konstantin.seurer at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17301>

---

 src/amd/vulkan/radv_pipeline_rt.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/src/amd/vulkan/radv_pipeline_rt.c b/src/amd/vulkan/radv_pipeline_rt.c
index d1d0478fdf6..31a620718ba 100644
--- a/src/amd/vulkan/radv_pipeline_rt.c
+++ b/src/amd/vulkan/radv_pipeline_rt.c
@@ -1804,28 +1804,16 @@ create_rt_shader(struct radv_device *device, const VkRayTracingPipelineCreateInf
    nir_ssa_def *idx = nir_load_var(&b, vars.idx);
 
    /* We do a trick with the indexing of the resume shaders so that the first
-    * shader of group x always gets id x and the resume shader ids then come after
-    * groupCount. This makes the shadergroup handles independent of compilation. */
-   unsigned call_idx_base = pCreateInfo->groupCount + 1;
-   for (unsigned i = 0; i < pCreateInfo->groupCount; ++i) {
-      const VkRayTracingShaderGroupCreateInfoKHR *group_info = &pCreateInfo->pGroups[i];
-      uint32_t shader_id = VK_SHADER_UNUSED_KHR;
-
-      switch (group_info->type) {
-      case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
-         shader_id = group_info->generalShader;
-         break;
-      case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR:
-      case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
-         shader_id = group_info->closestHitShader;
-         break;
-      default:
-         break;
-      }
-      if (shader_id == VK_SHADER_UNUSED_KHR)
+    * shader of stage x always gets id x and the resume shader ids then come after
+    * stageCount. This makes the shadergroup handles independent of compilation. */
+   unsigned call_idx_base = pCreateInfo->stageCount + 1;
+   for (unsigned i = 0; i < pCreateInfo->stageCount; ++i) {
+      const VkPipelineShaderStageCreateInfo *stage = &pCreateInfo->pStages[i];
+      gl_shader_stage type = vk_to_mesa_shader_stage(stage->stage);
+      if (type != MESA_SHADER_RAYGEN && type != MESA_SHADER_CALLABLE &&
+          type != MESA_SHADER_CLOSEST_HIT && type != MESA_SHADER_MISS)
          continue;
 
-      const VkPipelineShaderStageCreateInfo *stage = &pCreateInfo->pStages[shader_id];
       nir_shader *nir_stage = parse_rt_stage(device, stage);
 
       /* Move ray tracing system values to the top that are set by rt_trace_ray
@@ -1948,12 +1936,16 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
 
    compute_pipeline->dynamic_stack_size = radv_rt_pipeline_has_dynamic_stack_size(pCreateInfo);
 
+   /* For General and ClosestHit shaders, we can use the shader ID directly as handle.
+    * As (potentially different) AnyHit shaders are inlined, for Intersection shaders
+    * we use the Group ID.
+    */
    for (unsigned i = 0; i < local_create_info.groupCount; ++i) {
       const VkRayTracingShaderGroupCreateInfoKHR *group_info = &local_create_info.pGroups[i];
       switch (group_info->type) {
       case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
          if (group_info->generalShader != VK_SHADER_UNUSED_KHR)
-            compute_pipeline->rt_group_handles[i].handles[0] = i + 2;
+            compute_pipeline->rt_group_handles[i].handles[0] = group_info->generalShader + 2;
          break;
       case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR:
          if (group_info->intersectionShader != VK_SHADER_UNUSED_KHR)
@@ -1961,7 +1953,7 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
          FALLTHROUGH;
       case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
          if (group_info->closestHitShader != VK_SHADER_UNUSED_KHR)
-            compute_pipeline->rt_group_handles[i].handles[0] = i + 2;
+            compute_pipeline->rt_group_handles[i].handles[0] = group_info->closestHitShader + 2;
          if (group_info->anyHitShader != VK_SHADER_UNUSED_KHR)
             compute_pipeline->rt_group_handles[i].handles[1] = i + 2;
          break;



More information about the mesa-commit mailing list