From df710fe6956d2a6093473f8809b56267c3e31e5b Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Fri, 8 Sep 2023 08:47:00 +0200 Subject: [PATCH] radv/rt: Enable monolithic pipelines Store can_inline inside the stages to avoid rerunning the analysis pass for library stages. Part-of: --- src/amd/vulkan/radv_pipeline_rt.c | 34 +++++++++++++++++++++++++++++----- src/amd/vulkan/radv_private.h | 2 ++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline_rt.c b/src/amd/vulkan/radv_pipeline_rt.c index 9ce02f5..42a37ca 100644 --- a/src/amd/vulkan/radv_pipeline_rt.c +++ b/src/amd/vulkan/radv_pipeline_rt.c @@ -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++) { diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 9618970..d5f9104 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -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]; }; -- 2.7.4