[Mesa-stable] [PATCH] nir: Zero undefined variables when zero_undefiend_variables is set

Jason Ekstrand jason at jlekstrand.net
Fri Feb 27 12:26:40 PST 2015


Cc: 10.5 <mesa-stable at lists.freedesktop.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=89292
---
 src/glsl/nir/nir_lower_vars_to_ssa.c        | 34 +++++++++++++++++++++--------
 src/mesa/drivers/common/meta_tex_subimage.c |  2 +-
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c
index 8af7530..cf88c58 100644
--- a/src/glsl/nir/nir_lower_vars_to_ssa.c
+++ b/src/glsl/nir/nir_lower_vars_to_ssa.c
@@ -675,15 +675,31 @@ get_ssa_def_for_block(struct deref_node *node, nir_block *block,
    if (node->def_stack && node->def_stack_tail >= node->def_stack)
       return *node->def_stack_tail;
 
-   /* If we got here then we don't have a definition that dominates the
-    * given block.  This means that we need to add an undef and use that.
-    */
-   nir_ssa_undef_instr *undef =
-      nir_ssa_undef_instr_create(state->mem_ctx,
-                                 glsl_get_vector_elements(node->type));
-   nir_instr_insert_before_cf_list(&state->impl->body, &undef->instr);
-   def_stack_push(node, &undef->def, state);
-   return &undef->def;
+   nir_ssa_def *def;
+   if (getenv("zero_undefined_variables")) {
+      /* The user wants us to zero all undefined variables.  We'll do so
+       * while printing a (hopefully) helpful warning.
+       */
+      fprintf(stderr, "Undefined variable\n");
+
+      nir_load_const_instr *load =
+         nir_load_const_instr_create(state->mem_ctx,
+                                     glsl_get_vector_elements(node->type));
+      memset(&load->value, 0, sizeof(load->value));
+      nir_instr_insert_before_cf_list(&state->impl->body, &load->instr);
+      def = &load->def;
+   } else {
+      /* If we got here then we don't have a definition that dominates the
+       * given block.  This means that we need to add an undef and use that.
+       */
+      nir_ssa_undef_instr *undef =
+         nir_ssa_undef_instr_create(state->mem_ctx,
+                                    glsl_get_vector_elements(node->type));
+      nir_instr_insert_before_cf_list(&state->impl->body, &undef->instr);
+      def = &undef->def;
+   }
+   def_stack_push(node, def, state);
+   return def;
 }
 
 /* Given a block and one of its predecessors, this function fills in the
diff --git a/src/mesa/drivers/common/meta_tex_subimage.c b/src/mesa/drivers/common/meta_tex_subimage.c
index 5ae12c8..0aeb2c9 100644
--- a/src/mesa/drivers/common/meta_tex_subimage.c
+++ b/src/mesa/drivers/common/meta_tex_subimage.c
@@ -312,7 +312,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
       return false;
 
    /* Only stash the current FBO */
-   _mesa_meta_begin(ctx, 0);
+   _mesa_meta_begin(ctx, MESA_META_SCISSOR);
 
    _mesa_GenFramebuffers(2, fbos);
 
-- 
2.3.0



More information about the mesa-stable mailing list