Mesa (master): glsl: Fix copying function's out to temp if dereferenced by array

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 14 01:04:21 UTC 2019


Module: Mesa
Branch: master
Commit: 0862929bf64222e85e8242824aecf05e494c157c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0862929bf64222e85e8242824aecf05e494c157c

Author: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
Date:   Thu Jan 10 18:16:59 2019 +0200

glsl: Fix copying function's out to temp if dereferenced by array

Function's out variable could be an array dereferenced by an array:
 func(v[w[i]]);
or something more complicated.

Copy index in any case.

Fixes: 76c27e47b906 ("glsl: Copy function out to temp if we don't directly ref a variable")

Signed-off-by: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/compiler/glsl/ast_function.cpp | 46 ++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
index 9112eecb06..2be7a8c195 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -363,31 +363,29 @@ copy_index_derefs_to_temps(ir_instruction *ir, void *data)
       ir = a->array->as_dereference();
 
       ir_rvalue *idx = a->array_index;
-      if (idx->as_dereference_variable()) {
-         ir_variable *var = idx->variable_referenced();
+      ir_variable *var = idx->variable_referenced();
 
-         /* If the index is read only it cannot change so there is no need
-          * to copy it.
-          */
-         if (var->data.read_only || var->data.memory_read_only)
-            return;
-
-         ir_variable *tmp = new(d->mem_ctx) ir_variable(idx->type, "idx_tmp",
-                                                        ir_var_temporary);
-         d->before_instructions->push_tail(tmp);
-
-         ir_dereference_variable *const deref_tmp_1 =
-            new(d->mem_ctx) ir_dereference_variable(tmp);
-         ir_assignment *const assignment =
-            new(d->mem_ctx) ir_assignment(deref_tmp_1,
-                                          idx->clone(d->mem_ctx, NULL));
-         d->before_instructions->push_tail(assignment);
-
-         /* Replace the array index with a dereference of the new temporary */
-         ir_dereference_variable *const deref_tmp_2 =
-            new(d->mem_ctx) ir_dereference_variable(tmp);
-         a->array_index = deref_tmp_2;
-      }
+      /* If the index is read only it cannot change so there is no need
+       * to copy it.
+       */
+      if (!var || var->data.read_only || var->data.memory_read_only)
+         return;
+
+      ir_variable *tmp = new(d->mem_ctx) ir_variable(idx->type, "idx_tmp",
+                                                      ir_var_temporary);
+      d->before_instructions->push_tail(tmp);
+
+      ir_dereference_variable *const deref_tmp_1 =
+         new(d->mem_ctx) ir_dereference_variable(tmp);
+      ir_assignment *const assignment =
+         new(d->mem_ctx) ir_assignment(deref_tmp_1,
+                                       idx->clone(d->mem_ctx, NULL));
+      d->before_instructions->push_tail(assignment);
+
+      /* Replace the array index with a dereference of the new temporary */
+      ir_dereference_variable *const deref_tmp_2 =
+         new(d->mem_ctx) ir_dereference_variable(tmp);
+      a->array_index = deref_tmp_2;
    }
 }
 




More information about the mesa-commit mailing list