From f603a2c25a3efd50ff21a125ee59645bf5599475 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Fri, 12 Mar 2021 15:13:30 -0800 Subject: [PATCH] anv: Lower ViewIndex to zero when multiview is disabled Vulkan spec says If multiview is enabled in the render pass, this value will be one of the bits set in the view mask of the subpass the pipeline is compiled against. If multiview is not enabled in the render pass, this value will be zero. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4446 Fixes: 0db70703300 ("anv/pipeline: Add shader lowering for multiview") Reviewed-by: Lionel Landwerlin Reviewed-by: Jason Ekstrand Part-of: --- src/intel/vulkan/anv_nir_lower_multiview.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/intel/vulkan/anv_nir_lower_multiview.c b/src/intel/vulkan/anv_nir_lower_multiview.c index 7c0abac0cad..b42af415c64 100644 --- a/src/intel/vulkan/anv_nir_lower_multiview.c +++ b/src/intel/vulkan/anv_nir_lower_multiview.c @@ -150,6 +150,21 @@ build_view_index(struct lower_multiview_state *state) return state->view_index; } +static bool +is_load_view_index(const nir_instr *instr, const void *data) +{ + return instr->type == nir_instr_type_intrinsic && + nir_instr_as_intrinsic(instr)->intrinsic == nir_intrinsic_load_view_index; +} + +static nir_ssa_def * +replace_load_view_index_with_zero(struct nir_builder *b, + nir_instr *instr, void *data) +{ + assert(is_load_view_index(instr, data)); + return nir_imm_zero(b, 1, 32); +} + bool anv_nir_lower_multiview(nir_shader *shader, struct anv_graphics_pipeline *pipeline) @@ -157,9 +172,11 @@ anv_nir_lower_multiview(nir_shader *shader, assert(shader->info.stage != MESA_SHADER_COMPUTE); uint32_t view_mask = pipeline->subpass->view_mask; - /* If multiview isn't enabled, we have nothing to do. */ - if (view_mask == 0) - return false; + /* If multiview isn't enabled, just lower the ViewIndex builtin to zero. */ + if (view_mask == 0) { + return nir_shader_lower_instructions(shader, is_load_view_index, + replace_load_view_index_with_zero, NULL); + } /* This pass assumes a single entrypoint */ nir_function_impl *entrypoint = nir_shader_get_entrypoint(shader);