diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index f1218c72d25..b7446ec8c43 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -3516,3 +3516,12 @@ void nir_remove_sysval_output(nir_intrinsic_instr *intr) nir_instr_remove(&intr->instr); } } + +void nir_remove_non_entrypoints(nir_shader *nir) +{ + foreach_list_typed_safe(nir_function, func, node, &nir->functions) { + if (!func->is_entrypoint) + exec_node_remove(&func->node); + } + assert(exec_list_length(&nir->functions) == 1); +} diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index e159e2f5dde..a5a6068e797 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3669,6 +3669,8 @@ nir_shader_get_entrypoint(const nir_shader *shader) return func->impl; } +void nir_remove_non_entrypoints(nir_shader *shader); + nir_shader *nir_shader_create(void *mem_ctx, gl_shader_stage stage, const nir_shader_compiler_options *options, diff --git a/src/gallium/frontends/clover/nir/invocation.cpp b/src/gallium/frontends/clover/nir/invocation.cpp index 9750f7d2f49..c5cb23a6845 100644 --- a/src/gallium/frontends/clover/nir/invocation.cpp +++ b/src/gallium/frontends/clover/nir/invocation.cpp @@ -475,11 +475,7 @@ binary clover::nir::spirv_to_nir(const binary &mod, const device &dev, NIR_PASS_V(nir, nir_opt_deref); // Pick off the single entrypoint that we want. - foreach_list_typed_safe(nir_function, func, node, &nir->functions) { - if (!func->is_entrypoint) - exec_node_remove(&func->node); - } - assert(exec_list_length(&nir->functions) == 1); + nir_remove_non_entrypoints(nir); nir_validate_shader(nir, "clover after function inlining"); diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c index 140de1ca4c6..e51132a46fa 100644 --- a/src/gallium/frontends/lavapipe/lvp_pipeline.c +++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c @@ -894,11 +894,7 @@ lvp_shader_compile_to_ir(struct lvp_pipeline *pipeline, NIR_PASS_V(nir, nir_opt_deref); /* Pick off the single entrypoint that we want */ - foreach_list_typed_safe(nir_function, func, node, &nir->functions) { - if (!func->is_entrypoint) - exec_node_remove(&func->node); - } - assert(exec_list_length(&nir->functions) == 1); + nir_remove_non_entrypoints(nir); struct nir_lower_subgroups_options subgroup_opts = {0}; subgroup_opts.lower_quad = true; diff --git a/src/intel/compiler/brw_kernel.c b/src/intel/compiler/brw_kernel.c index 5f2e6f37d31..f3d112e816b 100644 --- a/src/intel/compiler/brw_kernel.c +++ b/src/intel/compiler/brw_kernel.c @@ -334,11 +334,7 @@ brw_kernel_from_spirv(struct brw_compiler *compiler, NIR_PASS_V(nir, nir_opt_deref); /* Pick off the single entrypoint that we want */ - foreach_list_typed_safe(nir_function, func, node, &nir->functions) { - if (!func->is_entrypoint) - exec_node_remove(&func->node); - } - assert(exec_list_length(&nir->functions) == 1); + nir_remove_non_entrypoints(nir); /* Now that we've deleted all but the main function, we can go ahead and * lower the rest of the constant initializers. We do this here so that diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index c5c51174b64..8e1282c7a0b 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -297,11 +297,7 @@ _mesa_spirv_to_nir(struct gl_context *ctx, NIR_PASS_V(nir, nir_opt_deref); /* Pick off the single entrypoint that we want */ - foreach_list_typed_safe(nir_function, func, node, &nir->functions) { - if (!func->is_entrypoint) - exec_node_remove(&func->node); - } - assert(exec_list_length(&nir->functions) == 1); + nir_remove_non_entrypoints(nir); /* Now that we've deleted all but the main function, we can go ahead and * lower the rest of the constant initializers. We do this here so that diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c index ef8d725ee15..c21a93e9b01 100644 --- a/src/microsoft/clc/clc_compiler.c +++ b/src/microsoft/clc/clc_compiler.c @@ -845,11 +845,7 @@ clc_spirv_to_dxil(struct clc_libclc *lib, NIR_PASS_V(nir, nir_inline_functions); // Pick off the single entrypoint that we want. - foreach_list_typed_safe(nir_function, func, node, &nir->functions) { - if (!func->is_entrypoint) - exec_node_remove(&func->node); - } - assert(exec_list_length(&nir->functions) == 1); + nir_remove_non_entrypoints(nir); { bool progress; diff --git a/src/vulkan/runtime/vk_nir.c b/src/vulkan/runtime/vk_nir.c index e8c05697585..eff8667ce1f 100644 --- a/src/vulkan/runtime/vk_nir.c +++ b/src/vulkan/runtime/vk_nir.c @@ -110,11 +110,7 @@ vk_spirv_to_nir(struct vk_device *device, NIR_PASS_V(nir, nir_opt_deref); /* Pick off the single entrypoint that we want */ - foreach_list_typed_safe(nir_function, func, node, &nir->functions) { - if (!func->is_entrypoint) - exec_node_remove(&func->node); - } - assert(exec_list_length(&nir->functions) == 1); + nir_remove_non_entrypoints(nir); /* Now that we've deleted all but the main function, we can go ahead and * lower the rest of the constant initializers. We do this here so that