From 1cb115abd28ab2d63068fa0958e7ecdce82919c9 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 29 May 2024 11:15:07 +1000 Subject: [PATCH] nir: add nir_function_impl_clone_remap_globals() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be use by the glsl nir linker when we are combining different shaders from the same shader stage that might have multiple declarations of global variables across the different shaders. Acked-by: Marek Olšák Part-of: --- src/compiler/nir/nir.h | 4 ++++ src/compiler/nir/nir_clone.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index e32934f7e6c..fcd11378be1 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5203,6 +5203,10 @@ nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s); nir_function *nir_function_clone(nir_shader *ns, const nir_function *fxn); nir_function_impl *nir_function_impl_clone(nir_shader *shader, const nir_function_impl *fi); +nir_function_impl * +nir_function_impl_clone_remap_globals(nir_shader *shader, + const nir_function_impl *fi, + struct hash_table *remap_table); nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var); nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader); diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index dd37f282d31..3c128fbb768 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -675,20 +675,29 @@ clone_function_impl(clone_state *state, const nir_function_impl *fi) } nir_function_impl * -nir_function_impl_clone(nir_shader *shader, const nir_function_impl *fi) +nir_function_impl_clone_remap_globals(nir_shader *shader, + const nir_function_impl *fi, + struct hash_table *remap_table) { clone_state state; - init_clone_state(&state, NULL, false, false); + init_clone_state(&state, remap_table, !!remap_table, false); state.ns = shader; nir_function_impl *nfi = clone_function_impl(&state, fi); - free_clone_state(&state); + if (!remap_table) + free_clone_state(&state); return nfi; } +nir_function_impl * +nir_function_impl_clone(nir_shader *shader, const nir_function_impl *fi) +{ + return nir_function_impl_clone_remap_globals(shader, fi, NULL); +} + nir_function * nir_function_clone(nir_shader *ns, const nir_function *fxn) {