radv/rt: Enable monolithic pipelines
authorKonstantin Seurer <konstantin.seurer@gmail.com>
Fri, 8 Sep 2023 06:47:00 +0000 (08:47 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sun, 10 Sep 2023 11:40:12 +0000 (11:40 +0000)
Store can_inline inside the stages to avoid rerunning the analysis pass
for library stages.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21929>

src/amd/vulkan/radv_pipeline_rt.c
src/amd/vulkan/radv_private.h

index 9ce02f5..42a37ca 100644 (file)
@@ -454,6 +454,30 @@ radv_rt_nir_to_asm(struct radv_device *device, struct vk_pipeline_cache *cache,
    return shader ? VK_SUCCESS : VK_ERROR_OUT_OF_HOST_MEMORY;
 }
 
+static bool
+radv_rt_can_inline_shader(nir_shader *nir)
+{
+   if (nir->info.stage == MESA_SHADER_RAYGEN || nir->info.stage == MESA_SHADER_ANY_HIT ||
+       nir->info.stage == MESA_SHADER_INTERSECTION)
+      return true;
+
+   if (nir->info.stage == MESA_SHADER_CALLABLE)
+      return false;
+
+   nir_function_impl *impl = nir_shader_get_entrypoint(nir);
+   nir_foreach_block (block, impl) {
+      nir_foreach_instr (instr, block) {
+         if (instr->type != nir_instr_type_intrinsic)
+            continue;
+
+         if (nir_instr_as_intrinsic(instr)->intrinsic == nir_intrinsic_trace_ray)
+            return false;
+      }
+   }
+
+   return true;
+}
+
 static VkResult
 radv_rt_compile_shaders(struct radv_device *device, struct vk_pipeline_cache *cache,
                         const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
@@ -473,7 +497,7 @@ radv_rt_compile_shaders(struct radv_device *device, struct vk_pipeline_cache *ca
    if (!stages)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
-   bool monolithic = false;
+   bool monolithic = !(pipeline->base.base.create_flags & VK_PIPELINE_CREATE_2_LIBRARY_BIT_KHR);
    for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
       if (rt_stages[i].shader || rt_stages[i].nir)
          continue;
@@ -486,15 +510,15 @@ radv_rt_compile_shaders(struct radv_device *device, struct vk_pipeline_cache *ca
       /* precompile the shader */
       stage->nir = radv_parse_rt_stage(device, &pCreateInfo->pStages[i], key, pipeline_layout);
 
+      rt_stages[i].can_inline = radv_rt_can_inline_shader(stage->nir);
+
       stage->feedback.duration = os_time_get_nano() - stage_start;
    }
 
    bool has_callable = false;
    for (uint32_t i = 0; i < pipeline->stage_count; i++) {
-      if (rt_stages[i].stage == MESA_SHADER_CALLABLE) {
-         has_callable = true;
-         break;
-      }
+      has_callable |= rt_stages[i].stage == MESA_SHADER_CALLABLE;
+      monolithic &= rt_stages[i].can_inline;
    }
 
    for (uint32_t idx = 0; idx < pCreateInfo->stageCount; idx++) {
index 9618970..d5f9104 100644 (file)
@@ -2378,6 +2378,8 @@ struct radv_ray_tracing_stage {
    gl_shader_stage stage;
    uint32_t stack_size;
 
+   bool can_inline;
+
    uint8_t sha1[SHA1_DIGEST_LENGTH];
 };