From d45e9e576d366387e77fe5834bdd54221eb727ac 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: (cherry picked from commit f603a2c25a3efd50ff21a125ee59645bf5599475) --- .pick_status.json | 2 +- src/intel/vulkan/anv_nir_lower_multiview.c | 23 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 349fecce725..0c55d1631d6 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -13,7 +13,7 @@ "description": "anv: Lower ViewIndex to zero when multiview is disabled", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "0db70703300938356e8f3bef33e5826efc0b10c3" }, diff --git a/src/intel/vulkan/anv_nir_lower_multiview.c b/src/intel/vulkan/anv_nir_lower_multiview.c index 0502b1e3df7..07119e3f650 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);