diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index d1a197f51fc..b421afd948b 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -678,9 +678,10 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st if (nir->info.stage == MESA_SHADER_VERTEX || nir->info.stage == MESA_SHADER_GEOMETRY || nir->info.stage == MESA_SHADER_FRAGMENT) { - NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), true, true); + NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), + nir_var_shader_in | nir_var_shader_out); } else if (nir->info.stage == MESA_SHADER_TESS_EVAL) { - NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), true, false); + NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), nir_var_shader_out); } NIR_PASS(_, nir, nir_split_var_copies); diff --git a/src/asahi/vulkan/hk_shader.c b/src/asahi/vulkan/hk_shader.c index 76c8710b12d..c0adf1e4138 100644 --- a/src/asahi/vulkan/hk_shader.c +++ b/src/asahi/vulkan/hk_shader.c @@ -166,7 +166,7 @@ hk_preprocess_nir_internal(struct vk_physical_device *vk_pdev, nir_shader *nir) nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir)); NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); NIR_PASS(_, nir, nir_lower_global_vars_to_local); diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 2561dc17f64..9f6e284bcec 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -315,7 +315,7 @@ preprocess_nir(nir_shader *nir) } NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); NIR_PASS(_, nir, nir_lower_system_values); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 77bd9868674..5da2383e4be 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5171,7 +5171,7 @@ bool nir_lower_locals_to_regs(nir_shader *shader, uint8_t bool_bitsize); bool nir_lower_io_vars_to_temporaries(nir_shader *shader, nir_function_impl *entrypoint, - bool outputs, bool inputs); + nir_variable_mode modes); bool nir_lower_vars_to_scratch(nir_shader *shader, nir_variable_mode modes, diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 30ae32a27ad..c780af96d2e 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -1248,7 +1248,7 @@ nir_lower_io_passes(nir_shader *nir, bool renumber_vs_inputs) if (lower_indirect_outputs) { NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); /* We need to lower all the copy_deref's introduced by lower_io_to- * _temporaries before calling nir_lower_io. diff --git a/src/compiler/nir/nir_lower_io_vars_to_temporaries.c b/src/compiler/nir/nir_lower_io_vars_to_temporaries.c index 360e986db68..5775feb231e 100644 --- a/src/compiler/nir/nir_lower_io_vars_to_temporaries.c +++ b/src/compiler/nir/nir_lower_io_vars_to_temporaries.c @@ -332,10 +332,14 @@ move_variables_to_list(nir_shader *shader, nir_variable_mode mode, bool nir_lower_io_vars_to_temporaries(nir_shader *shader, nir_function_impl *entrypoint, - bool outputs, bool inputs) + nir_variable_mode modes) { + ASSERTED const nir_variable_mode supported_modes = + nir_var_shader_in | nir_var_shader_out; struct lower_io_state state; + assert(!(modes & ~supported_modes)); + if (shader->info.stage != MESA_SHADER_VERTEX && shader->info.stage != MESA_SHADER_TESS_EVAL && shader->info.stage != MESA_SHADER_GEOMETRY && @@ -348,11 +352,11 @@ nir_lower_io_vars_to_temporaries(nir_shader *shader, nir_function_impl *entrypoi state.input_map = _mesa_pointer_hash_table_create(NULL); exec_list_make_empty(&state.old_inputs); - if (inputs) + if (modes & nir_var_shader_in) move_variables_to_list(shader, nir_var_shader_in, &state.old_inputs); exec_list_make_empty(&state.old_outputs); - if (outputs) + if (modes & nir_var_shader_out) move_variables_to_list(shader, nir_var_shader_out, &state.old_outputs); exec_list_make_empty(&state.new_inputs); @@ -374,10 +378,10 @@ nir_lower_io_vars_to_temporaries(nir_shader *shader, nir_function_impl *entrypoi } nir_foreach_function_impl(impl, shader) { - if (inputs) + if (modes & nir_var_shader_in) emit_input_copies_impl(&state, impl); - if (outputs) + if (modes & nir_var_shader_out) emit_output_copies_impl(&state, impl); nir_progress(true, impl, nir_metadata_control_flow); diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index af2028cf3fa..41b744e9349 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -489,13 +489,19 @@ ir3_nir_lower_io_vars_to_temporaries(nir_shader *s) * stop doing that once we're sure all drivers are doing their own * indirect i/o lowering. */ - bool lower_input = s->info.stage == MESA_SHADER_VERTEX || - s->info.stage == MESA_SHADER_FRAGMENT; - bool lower_output = s->info.stage != MESA_SHADER_TESS_CTRL && - s->info.stage != MESA_SHADER_GEOMETRY; - if (lower_input || lower_output) { + nir_variable_mode lower_modes = 0; + + if (s->info.stage == MESA_SHADER_VERTEX || + s->info.stage == MESA_SHADER_FRAGMENT) + lower_modes |= nir_var_shader_in; + + if (s->info.stage != MESA_SHADER_TESS_CTRL && + s->info.stage != MESA_SHADER_GEOMETRY) + lower_modes |= nir_var_shader_out; + + if (lower_modes) { NIR_PASS(_, s, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(s), - lower_output, lower_input); + lower_modes); /* nir_lower_io_vars_to_temporaries() creates global variables and copy * instructions which need to be cleaned up. diff --git a/src/gallium/drivers/crocus/crocus_program.c b/src/gallium/drivers/crocus/crocus_program.c index 7836192ee59..5be1a0d6f05 100644 --- a/src/gallium/drivers/crocus/crocus_program.c +++ b/src/gallium/drivers/crocus/crocus_program.c @@ -1181,7 +1181,7 @@ crocus_compile_vs(struct crocus_context *ice, /* Check if variables were found. */ if (nir_lower_clip_vs(nir, (1 << key->nr_userclip_plane_consts) - 1, true, false, NULL)) { - nir_lower_io_vars_to_temporaries(nir, impl, true, false); + nir_lower_io_vars_to_temporaries(nir, impl, nir_var_shader_out); nir_lower_global_vars_to_local(nir); nir_lower_vars_to_ssa(nir); nir_shader_gather_info(nir, impl); @@ -1541,7 +1541,7 @@ crocus_compile_tes(struct crocus_context *ice, nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_lower_clip_vs(nir, (1 << key->nr_userclip_plane_consts) - 1, true, false, NULL); - nir_lower_io_vars_to_temporaries(nir, impl, true, false); + nir_lower_io_vars_to_temporaries(nir, impl, nir_var_shader_out); nir_lower_global_vars_to_local(nir); nir_lower_vars_to_ssa(nir); nir_shader_gather_info(nir, impl); @@ -1684,7 +1684,7 @@ crocus_compile_gs(struct crocus_context *ice, nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_lower_clip_gs(nir, (1 << key->nr_userclip_plane_consts) - 1, false, NULL); - nir_lower_io_vars_to_temporaries(nir, impl, true, false); + nir_lower_io_vars_to_temporaries(nir, impl, nir_var_shader_out); nir_lower_global_vars_to_local(nir); nir_lower_vars_to_ssa(nir); nir_shader_gather_info(nir, impl); diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index ea8045d0f2d..8615035822f 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -1898,7 +1898,7 @@ iris_compile_vs(struct iris_screen *screen, /* Check if variables were found. */ if (nir_lower_clip_vs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1, true, false, NULL)) { - nir_lower_io_vars_to_temporaries(nir, impl, true, false); + nir_lower_io_vars_to_temporaries(nir, impl, nir_var_shader_out); nir_lower_global_vars_to_local(nir); nir_lower_vars_to_ssa(nir); nir_shader_gather_info(nir, impl); @@ -2345,7 +2345,7 @@ iris_compile_tes(struct iris_screen *screen, nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_lower_clip_vs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1, true, false, NULL); - nir_lower_io_vars_to_temporaries(nir, impl, true, false); + nir_lower_io_vars_to_temporaries(nir, impl, nir_var_shader_out); nir_lower_global_vars_to_local(nir); nir_lower_vars_to_ssa(nir); nir_shader_gather_info(nir, impl); @@ -2540,7 +2540,7 @@ iris_compile_gs(struct iris_screen *screen, nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_lower_clip_gs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1, false, NULL); - nir_lower_io_vars_to_temporaries(nir, impl, true, false); + nir_lower_io_vars_to_temporaries(nir, impl, nir_var_shader_out); nir_lower_global_vars_to_local(nir); nir_lower_vars_to_ssa(nir); nir_shader_gather_info(nir, impl); diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp index fe2bc328440..8a49bf60bd4 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp @@ -3418,7 +3418,7 @@ Converter::run() if (lowered) { nir_function_impl *impl = nir_shader_get_entrypoint(nir); - NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, impl, true, false); + NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, impl, nir_var_shader_out); NIR_PASS(_, nir, nir_lower_global_vars_to_local); NIR_PASS(_, nir, nv50_nir_lower_load_user_clip_plane, info); } else { diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c index e4a096743ad..b6dc0a3e7f2 100644 --- a/src/gallium/frontends/lavapipe/lvp_pipeline.c +++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c @@ -359,7 +359,8 @@ lvp_shader_lower(struct lvp_device *pdevice, nir_shader *nir, struct lvp_pipelin optimize(nir); nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir)); - NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), true, true); + NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), + nir_var_shader_out | nir_var_shader_in); NIR_PASS(_, nir, nir_split_var_copies); NIR_PASS(_, nir, nir_lower_global_vars_to_local); diff --git a/src/imagination/pco/pco_nir.c b/src/imagination/pco/pco_nir.c index 8949a154f09..78d833111e1 100644 --- a/src/imagination/pco/pco_nir.c +++ b/src/imagination/pco/pco_nir.c @@ -567,8 +567,7 @@ void pco_preprocess_nir(pco_ctx *ctx, nir_shader *nir) nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), - true, - true); + nir_var_shader_out | nir_var_shader_in); NIR_PASS(_, nir, nir_lower_global_vars_to_local); NIR_PASS(_, nir, nir_split_var_copies); diff --git a/src/intel/compiler/brw/brw_nir.c b/src/intel/compiler/brw/brw_nir.c index 0cfdc337e1f..28aca6795b9 100644 --- a/src/intel/compiler/brw/brw_nir.c +++ b/src/intel/compiler/brw/brw_nir.c @@ -1660,7 +1660,7 @@ brw_nir_link_shaders(const struct brw_compiler *compiler, * those write-mask in output is handled by I/O lowering. */ NIR_PASS(_, producer, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(producer), true, false); + nir_shader_get_entrypoint(producer), nir_var_shader_out); NIR_PASS(_, producer, nir_lower_global_vars_to_local); NIR_PASS(_, producer, nir_split_var_copies); NIR_PASS(_, producer, nir_lower_var_copies); diff --git a/src/intel/compiler/elk/elk_nir.c b/src/intel/compiler/elk/elk_nir.c index 6f59ef733be..5217fb8f6b5 100644 --- a/src/intel/compiler/elk/elk_nir.c +++ b/src/intel/compiler/elk/elk_nir.c @@ -1236,7 +1236,7 @@ elk_nir_link_shaders(const struct elk_compiler *compiler, * that we need to clean up. */ NIR_PASS(_, producer, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(producer), true, false); + nir_shader_get_entrypoint(producer), nir_var_shader_out); NIR_PASS(_, producer, nir_lower_global_vars_to_local); NIR_PASS(_, producer, nir_split_var_copies); NIR_PASS(_, producer, nir_lower_var_copies); diff --git a/src/intel/vulkan/anv_shader_compile.c b/src/intel/vulkan/anv_shader_compile.c index 7b13d98d219..deafca72f12 100644 --- a/src/intel/vulkan/anv_shader_compile.c +++ b/src/intel/vulkan/anv_shader_compile.c @@ -192,7 +192,7 @@ anv_shader_preprocess_nir(struct vk_physical_device *device, const struct brw_compiler *compiler = pdevice->compiler; NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = { .point_coord = true, diff --git a/src/intel/vulkan_hasvk/anv_pipeline.c b/src/intel/vulkan_hasvk/anv_pipeline.c index 32a3b4ab3de..c983022f156 100644 --- a/src/intel/vulkan_hasvk/anv_pipeline.c +++ b/src/intel/vulkan_hasvk/anv_pipeline.c @@ -90,7 +90,7 @@ anv_shader_stage_to_nir(struct anv_device *device, } NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = { .point_coord = true, diff --git a/src/kosmickrisp/kosmicomp.c b/src/kosmickrisp/kosmicomp.c index 554c6b007d8..501ba4e0095 100644 --- a/src/kosmickrisp/kosmicomp.c +++ b/src/kosmickrisp/kosmicomp.c @@ -98,7 +98,7 @@ optimize(nir_shader *nir) nir_var_shader_in | nir_var_shader_out | nir_var_system_value, NULL); NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); nir_lower_compute_system_values_options options = { .has_base_global_invocation_id = 0, }; diff --git a/src/kosmickrisp/vulkan/kk_shader.c b/src/kosmickrisp/vulkan/kk_shader.c index cc8bfa09921..19b98acf356 100644 --- a/src/kosmickrisp/vulkan/kk_shader.c +++ b/src/kosmickrisp/vulkan/kk_shader.c @@ -100,7 +100,7 @@ kk_preprocess_nir(UNUSED struct vk_physical_device *vk_pdev, nir_shader *nir, * jump, which is illegal. */ NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); msl_preprocess_nir(nir); } @@ -1279,4 +1279,4 @@ const struct vk_device_shader_ops kk_device_shader_ops = { .deserialize = kk_deserialize_shader, .cmd_set_dynamic_graphics_state = vk_cmd_set_dynamic_graphics_state, .cmd_bind_shaders = kk_cmd_bind_shaders, -}; \ No newline at end of file +}; diff --git a/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c b/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c index 4b8d4574b86..1bd2c978718 100644 --- a/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c +++ b/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c @@ -1027,7 +1027,8 @@ dxil_spirv_nir_passes(nir_shader *nir, NIR_PASS(_, nir, dxil_nir_lower_int_cubemaps, false); NIR_PASS(_, nir, nir_lower_clip_cull_distance_array_vars); - NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), true, true); + NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), + nir_var_shader_out | nir_var_shader_in); NIR_PASS(_, nir, nir_lower_global_vars_to_local); NIR_PASS(_, nir, nir_split_var_copies); NIR_PASS(_, nir, nir_lower_var_copies); diff --git a/src/nouveau/compiler/nak_nir.c b/src/nouveau/compiler/nak_nir.c index 37660e722c1..4a5f1379596 100644 --- a/src/nouveau/compiler/nak_nir.c +++ b/src/nouveau/compiler/nak_nir.c @@ -333,7 +333,7 @@ nak_preprocess_nir(nir_shader *nir, const struct nak_compiler *nak) OPT(nir, nir_lower_io_vars_to_temporaries, nir_shader_get_entrypoint(nir), - true /* outputs */, false /* inputs */); + nir_var_shader_out); const nir_lower_tex_options tex_options = { .lower_txd_3d = true, diff --git a/src/panfrost/vulkan/panvk_vX_shader.c b/src/panfrost/vulkan/panvk_vX_shader.c index d7a88c1eb9a..8e04d789904 100644 --- a/src/panfrost/vulkan/panvk_vX_shader.c +++ b/src/panfrost/vulkan/panvk_vX_shader.c @@ -399,7 +399,7 @@ panvk_preprocess_nir(struct vk_physical_device *vk_pdev, NIR_PASS(_, nir, nir_opt_vectorize_io_vars, nir_var_shader_out); NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); #if PAN_ARCH < 9 /* This needs to be done just after the io_to_temporaries pass, because we @@ -798,7 +798,7 @@ panvk_lower_nir(struct panvk_device *dev, nir_shader *nir, /* Pull output writes out of the loop and give them constant offsets for * pan_lower_store_components */ NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); + nir_shader_get_entrypoint(nir), nir_var_shader_out); } #endif