[Mesa-dev] [PATCH] prog_to_nir: Don't allocate nir_variable with type vec4[0] for uniforms.

Kenneth Graunke kenneth at whitecape.org
Mon Aug 24 16:39:24 PDT 2015


If there are no parameters, we don't need to create a nir_variable to
hold them...and allocating an array of length 0 is pretty bogus.

Should avoid i965 backend assertions in future patches Jason and I are
working on.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/program/prog_to_nir.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Hey Jason,

It sounds like the right thing to do is make prog_to_nir stop generating
idiotic shader code.  Here's a patch that does that.

The assert you're removing may still be unnecessary, but it also seems
like a totally reasonable thing for the backend to enforce...so I'd prefer
to leave it...

--Ken

diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index e088578..29ff638 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -167,6 +167,8 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
          }
          /* FALLTHROUGH */
       case PROGRAM_STATE_VAR: {
+         assert(c->parameters != NULL);
+
          nir_intrinsic_instr *load =
             nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_var);
          nir_ssa_dest_init(&load->instr, &load->dest, 4, NULL);
@@ -1090,13 +1092,15 @@ prog_to_nir(const struct gl_program *prog,
       goto fail;
    c->prog = prog;
 
-   c->parameters = rzalloc(s, nir_variable);
-   c->parameters->type = glsl_array_type(glsl_vec4_type(),
-                                            prog->Parameters->NumParameters);
-   c->parameters->name = "parameters";
-   c->parameters->data.read_only = true;
-   c->parameters->data.mode = nir_var_uniform;
-   exec_list_push_tail(&s->uniforms, &c->parameters->node);
+   if (prog->Parameters->NumParameters > 0) {
+      c->parameters = rzalloc(s, nir_variable);
+      c->parameters->type =
+         glsl_array_type(glsl_vec4_type(), prog->Parameters->NumParameters);
+      c->parameters->name = "parameters";
+      c->parameters->data.read_only = true;
+      c->parameters->data.mode = nir_var_uniform;
+      exec_list_push_tail(&s->uniforms, &c->parameters->node);
+   }
 
    nir_function *func = nir_function_create(s, "main");
    nir_function_overload *overload = nir_function_overload_create(func);
-- 
2.5.0



More information about the mesa-dev mailing list