From c9e032be7f6279cb0f4cbc6ac222e4f308aad647 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 1 Feb 2023 14:56:22 +0100 Subject: [PATCH] radv: allow to create a noop FS in a library with GPL Otherwise, a noop FS will be always compiled during linking if not provided by the application and that is too slow for fast-linking. This should be improved to use a global noop FS but it's really tricky because NIR linking doesn't do anything when the next stage is unknown, and hence doesn't remove unused varyings. Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_pipeline.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index 8f38eb63df4..9eacda921f6 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -3481,9 +3481,11 @@ radv_graphics_pipeline_compile(struct radv_graphics_pipeline *pipeline, if (pCreateInfo->flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT) return VK_PIPELINE_COMPILE_REQUIRED; - if (pipeline->base.type == RADV_PIPELINE_GRAPHICS && - !(radv_pipeline_to_graphics(&pipeline->base)->active_stages & - VK_SHADER_STAGE_FRAGMENT_BIT)) { + if ((pipeline->base.type == RADV_PIPELINE_GRAPHICS && + !(radv_pipeline_to_graphics(&pipeline->base)->active_stages & VK_SHADER_STAGE_FRAGMENT_BIT)) || + (pipeline->base.type == RADV_PIPELINE_GRAPHICS_LIB && + (lib_flags & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT) && + !(radv_pipeline_to_graphics_lib(&pipeline->base)->base.active_stages & VK_SHADER_STAGE_FRAGMENT_BIT))) { nir_builder fs_b = radv_meta_init_shader(device, MESA_SHADER_FRAGMENT, "noop_fs"); stages[MESA_SHADER_FRAGMENT] = (struct radv_pipeline_stage) { @@ -5165,7 +5167,11 @@ radv_graphics_lib_pipeline_init(struct radv_graphics_lib_pipeline *pipeline, return VK_ERROR_OUT_OF_HOST_MEMORY; } - if (pipeline->base.active_stages != 0) { + if (pipeline->base.active_stages != 0 || + (imported_flags & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT)) { + const VkPipelineCreationFeedbackCreateInfo *creation_feedback = + vk_find_struct_const(pCreateInfo->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO); + struct radv_pipeline_key key = radv_generate_graphics_pipeline_key(&pipeline->base, pCreateInfo, state); @@ -5186,6 +5192,13 @@ radv_graphics_lib_pipeline_init(struct radv_graphics_lib_pipeline *pipeline, &pipeline->base.last_vgt_api_stage); if (result != VK_SUCCESS) return result; + + /* Force add the fragment shader stage when a noop FS has been compiled. */ + if ((imported_flags & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT) && + !(pipeline->base.active_stages & VK_SHADER_STAGE_FRAGMENT_BIT)) { + assert(pipeline->base.base.shaders[MESA_SHADER_FRAGMENT]); + pipeline->base.active_stages |= VK_SHADER_STAGE_FRAGMENT_BIT; + } } return VK_SUCCESS;