From 0b3f78796d131980627f95f07be7de4b4f8b515c Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 20 Mar 2024 14:12:03 -0700 Subject: [PATCH] anv, hasvk: Move multiview remapping loop below output stores This will help prepare for the next patch. No functional changes. Reviewed-by: Caio Oliveira Part-of: --- src/intel/vulkan/anv_nir_lower_multiview.c | 54 ++++++++++--------- .../vulkan_hasvk/anv_nir_lower_multiview.c | 54 ++++++++++--------- 2 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/intel/vulkan/anv_nir_lower_multiview.c b/src/intel/vulkan/anv_nir_lower_multiview.c index 246ef70f6f8..86676ed358b 100644 --- a/src/intel/vulkan/anv_nir_lower_multiview.c +++ b/src/intel/vulkan/anv_nir_lower_multiview.c @@ -234,6 +234,35 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask, */ state.instance_id_with_views = nir_load_instance_id(b); + /* The view index is available in all stages but the instance id is only + * available in the VS. If it's not a fragment shader, we need to pass + * the view index on to the next stage. + */ + nir_def *view_index = build_view_index(&state); + + assert(view_index->parent_instr->block == nir_start_block(entrypoint)); + b->cursor = nir_after_instr(view_index->parent_instr); + + /* Unless there is only one possible view index (that would be set + * directly), pass it to the next stage. + */ + nir_variable *view_index_out = NULL; + if (util_bitcount(state.view_mask) != 1) { + view_index_out = nir_variable_create(shader, nir_var_shader_out, + glsl_int_type(), "view index"); + view_index_out->data.location = VARYING_SLOT_VIEW_INDEX; + } + + nir_variable *layer_id_out = + nir_variable_create(shader, nir_var_shader_out, + glsl_int_type(), "layer ID"); + layer_id_out->data.location = VARYING_SLOT_LAYER; + + if (view_index_out) + nir_store_var(b, view_index_out, view_index, 0x1); + + nir_store_var(b, layer_id_out, view_index, 0x1); + nir_foreach_block(block, entrypoint) { nir_foreach_instr_safe(instr, block) { if (instr->type != nir_instr_type_intrinsic) @@ -262,31 +291,6 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask, } } - /* The view index is available in all stages but the instance id is only - * available in the VS. If it's not a fragment shader, we need to pass - * the view index on to the next stage. - */ - nir_def *view_index = build_view_index(&state); - - assert(view_index->parent_instr->block == nir_start_block(entrypoint)); - b->cursor = nir_after_instr(view_index->parent_instr); - - /* Unless there is only one possible view index (that would be set - * directly), pass it to the next stage. */ - if (util_bitcount(state.view_mask) != 1) { - nir_variable *view_index_out = - nir_variable_create(shader, nir_var_shader_out, - glsl_int_type(), "view index"); - view_index_out->data.location = VARYING_SLOT_VIEW_INDEX; - nir_store_var(b, view_index_out, view_index, 0x1); - } - - nir_variable *layer_id_out = - nir_variable_create(shader, nir_var_shader_out, - glsl_int_type(), "layer ID"); - layer_id_out->data.location = VARYING_SLOT_LAYER; - nir_store_var(b, layer_id_out, view_index, 0x1); - nir_metadata_preserve(entrypoint, nir_metadata_block_index | nir_metadata_dominance); diff --git a/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c b/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c index d3f9cdb825d..ea1909177df 100644 --- a/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c +++ b/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c @@ -209,6 +209,35 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask) */ state.instance_id_with_views = nir_load_instance_id(b); + /* The view index is available in all stages but the instance id is only + * available in the VS. If it's not a fragment shader, we need to pass + * the view index on to the next stage. + */ + nir_def *view_index = build_view_index(&state); + + assert(view_index->parent_instr->block == nir_start_block(entrypoint)); + b->cursor = nir_after_instr(view_index->parent_instr); + + /* Unless there is only one possible view index (that would be set + * directly), pass it to the next stage. + */ + nir_variable *view_index_out = NULL; + if (util_bitcount(state.view_mask) != 1) { + view_index_out = nir_variable_create(shader, nir_var_shader_out, + glsl_int_type(), "view index"); + view_index_out->data.location = VARYING_SLOT_VIEW_INDEX; + } + + nir_variable *layer_id_out = + nir_variable_create(shader, nir_var_shader_out, + glsl_int_type(), "layer ID"); + layer_id_out->data.location = VARYING_SLOT_LAYER; + + if (view_index_out) + nir_store_var(b, view_index_out, view_index, 0x1); + + nir_store_var(b, layer_id_out, view_index, 0x1); + nir_foreach_block(block, entrypoint) { nir_foreach_instr_safe(instr, block) { if (instr->type != nir_instr_type_intrinsic) @@ -237,31 +266,6 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask) } } - /* The view index is available in all stages but the instance id is only - * available in the VS. If it's not a fragment shader, we need to pass - * the view index on to the next stage. - */ - nir_def *view_index = build_view_index(&state); - - assert(view_index->parent_instr->block == nir_start_block(entrypoint)); - b->cursor = nir_after_instr(view_index->parent_instr); - - /* Unless there is only one possible view index (that would be set - * directly), pass it to the next stage. */ - if (util_bitcount(state.view_mask) != 1) { - nir_variable *view_index_out = - nir_variable_create(shader, nir_var_shader_out, - glsl_int_type(), "view index"); - view_index_out->data.location = VARYING_SLOT_VIEW_INDEX; - nir_store_var(b, view_index_out, view_index, 0x1); - } - - nir_variable *layer_id_out = - nir_variable_create(shader, nir_var_shader_out, - glsl_int_type(), "layer ID"); - layer_id_out->data.location = VARYING_SLOT_LAYER; - nir_store_var(b, layer_id_out, view_index, 0x1); - nir_metadata_preserve(entrypoint, nir_metadata_block_index | nir_metadata_dominance);