[Mesa-dev] [PATCH 1/2] nir: remove mem_ctx arg from nir_shader_create()

Rob Clark robdclark at gmail.com
Wed Nov 18 12:45:34 PST 2015


From: Rob Clark <robclark at freedesktop.org>

Reference counting (which is introduced in a subsequent patch) basically
should only be done on root nodes in the ralloc tree.  In particular,
having multiple threads calling in to ralloc for the same graph will not
work.

Whereas reference-counting of shaders will be a useful thing, there does
not appear to be any use case for having a nir_shader itself parented
under some other parent mem_ctx.  So remove that option.

Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
 src/gallium/auxiliary/nir/tgsi_to_nir.c                    | 2 +-
 src/glsl/nir/glsl_to_nir.cpp                               | 2 +-
 src/glsl/nir/nir.c                                         | 5 ++---
 src/glsl/nir/nir.h                                         | 5 ++---
 src/glsl/nir/nir_clone.c                                   | 4 ++--
 src/glsl/nir/tests/control_flow_tests.cpp                  | 2 +-
 src/mesa/drivers/dri/i965/brw_nir.c                        | 2 +-
 src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp     | 2 +-
 src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp | 2 +-
 src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp   | 2 +-
 src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp   | 2 +-
 src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp  | 2 +-
 src/mesa/program/prog_to_nir.c                             | 2 +-
 13 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c
index 0539cfc..dcc81af 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
@@ -1946,7 +1946,7 @@ tgsi_to_nir(const void *tgsi_tokens,
    tgsi_scan_shader(tgsi_tokens, &scan);
    c->scan = &scan;
 
-   s = nir_shader_create(NULL, tgsi_processor_to_shader_stage(scan.processor),
+   s = nir_shader_create(tgsi_processor_to_shader_stage(scan.processor),
                          options);
 
    nir_function *func = nir_function_create(s, "main");
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index e149d73..859a4ad 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -137,7 +137,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
 {
    struct gl_shader *sh = shader_prog->_LinkedShaders[stage];
 
-   nir_shader *shader = nir_shader_create(NULL, stage, options);
+   nir_shader *shader = nir_shader_create(stage, options);
 
    nir_visitor v1(shader);
    nir_function_visitor v2(&v1);
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 93c18fb..568017a 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -30,11 +30,10 @@
 #include <assert.h>
 
 nir_shader *
-nir_shader_create(void *mem_ctx,
-                  gl_shader_stage stage,
+nir_shader_create(gl_shader_stage stage,
                   const nir_shader_compiler_options *options)
 {
-   nir_shader *shader = ralloc(mem_ctx, nir_shader);
+   nir_shader *shader = ralloc(NULL, nir_shader);
 
    exec_list_make_empty(&shader->uniforms);
    exec_list_make_empty(&shader->inputs);
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index e9d722e..e378f01 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1594,8 +1594,7 @@ typedef struct nir_shader {
       foreach_list_typed(nir_function_overload, overload, node, \
                          &(func)->overload_list)
 
-nir_shader *nir_shader_create(void *mem_ctx,
-                              gl_shader_stage stage,
+nir_shader *nir_shader_create(gl_shader_stage stage,
                               const nir_shader_compiler_options *options);
 
 /** creates a register, including assigning it an index and adding it to the list */
@@ -1890,7 +1889,7 @@ void nir_index_blocks(nir_function_impl *impl);
 void nir_print_shader(nir_shader *shader, FILE *fp);
 void nir_print_instr(const nir_instr *instr, FILE *fp);
 
-nir_shader * nir_shader_clone(void *mem_ctx, const nir_shader *s);
+nir_shader * nir_shader_clone(const nir_shader *s);
 
 #ifdef DEBUG
 void nir_validate_shader(nir_shader *shader);
diff --git a/src/glsl/nir/nir_clone.c b/src/glsl/nir/nir_clone.c
index 33ff526..654cc0e 100644
--- a/src/glsl/nir/nir_clone.c
+++ b/src/glsl/nir/nir_clone.c
@@ -625,12 +625,12 @@ clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
 }
 
 nir_shader *
-nir_shader_clone(void *mem_ctx, const nir_shader *s)
+nir_shader_clone(const nir_shader *s)
 {
    clone_state state;
    init_clone_state(&state);
 
-   nir_shader *ns = nir_shader_create(mem_ctx, s->stage, s->options);
+   nir_shader *ns = nir_shader_create(s->stage, s->options);
    state.ns = ns;
 
    clone_var_list(&state, &ns->uniforms, &s->uniforms);
diff --git a/src/glsl/nir/tests/control_flow_tests.cpp b/src/glsl/nir/tests/control_flow_tests.cpp
index b9f90e6..dc7202a 100644
--- a/src/glsl/nir/tests/control_flow_tests.cpp
+++ b/src/glsl/nir/tests/control_flow_tests.cpp
@@ -37,7 +37,7 @@ protected:
 nir_cf_test::nir_cf_test()
 {
    static const nir_shader_compiler_options options = { };
-   shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, &options);
+   shader = nir_shader_create(MESA_SHADER_VERTEX, &options);
    nir_function *func = nir_function_create(shader, "main");
    nir_function_overload *overload = nir_function_overload_create(func);
    impl = nir_function_impl_create(overload);
diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c
index 7896f29..79e70b9 100644
--- a/src/mesa/drivers/dri/i965/brw_nir.c
+++ b/src/mesa/drivers/dri/i965/brw_nir.c
@@ -186,7 +186,7 @@ should_clone_nir()
    do_pass                                                           \
    nir_validate_shader(nir);                                         \
    if (should_clone_nir()) {                                         \
-      nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
+      nir_shader *clone = nir_shader_clone(nir);                     \
       ralloc_free(nir);                                              \
       nir = clone;                                                   \
    }                                                                 \
diff --git a/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp b/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
index 62d39f7..466fe18 100644
--- a/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
@@ -62,7 +62,7 @@ void cmod_propagation_test::SetUp()
 
    fp = ralloc(NULL, struct brw_fragment_program);
    prog_data = ralloc(NULL, struct brw_wm_prog_data);
-   nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_FRAGMENT, NULL);
+   nir_shader *shader = nir_shader_create(MESA_SHADER_FRAGMENT, NULL);
 
    v = new cmod_propagation_fs_visitor(compiler, prog_data, shader);
 
diff --git a/src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp b/src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp
index 32e8b8f..e375bdc 100644
--- a/src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp
@@ -62,7 +62,7 @@ void saturate_propagation_test::SetUp()
 
    fp = ralloc(NULL, struct brw_fragment_program);
    prog_data = ralloc(NULL, struct brw_wm_prog_data);
-   nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_FRAGMENT, NULL);
+   nir_shader *shader = nir_shader_create(MESA_SHADER_FRAGMENT, NULL);
 
    v = new saturate_propagation_fs_visitor(compiler, prog_data, shader);
 
diff --git a/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp b/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp
index 9aa2fcc..7426f70 100644
--- a/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp
@@ -100,7 +100,7 @@ void cmod_propagation_test::SetUp()
 
    vp = ralloc(NULL, struct brw_vertex_program);
 
-   nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL);
+   nir_shader *shader = nir_shader_create(MESA_SHADER_VERTEX, NULL);
 
    v = new cmod_propagation_vec4_visitor(compiler, shader);
 
diff --git a/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp b/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp
index a1f91d9..823a868 100644
--- a/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp
@@ -94,7 +94,7 @@ void copy_propagation_test::SetUp()
 
    vp = ralloc(NULL, struct brw_vertex_program);
 
-   nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL);
+   nir_shader *shader = nir_shader_create(MESA_SHADER_VERTEX, NULL);
 
    v = new copy_propagation_vec4_visitor(compiler, shader);
 
diff --git a/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp b/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
index d84e2e9..2509da6 100644
--- a/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
+++ b/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
@@ -97,7 +97,7 @@ void register_coalesce_test::SetUp()
 
    vp = ralloc(NULL, struct brw_vertex_program);
 
-   nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL);
+   nir_shader *shader = nir_shader_create(MESA_SHADER_VERTEX, NULL);
 
    v = new register_coalesce_vec4_visitor(compiler, shader);
 
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index 539e3c0..5c64b35 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -1080,7 +1080,7 @@ prog_to_nir(const struct gl_program *prog,
    c = rzalloc(NULL, struct ptn_compile);
    if (!c)
       return NULL;
-   s = nir_shader_create(NULL, stage, options);
+   s = nir_shader_create(stage, options);
    if (!s)
       goto fail;
    c->prog = prog;
-- 
2.5.0



More information about the mesa-dev mailing list