Mesa (master): glsl: Fix variable_referenced() for vector_{extract, insert} expressions

Iago Toral Quiroga itoral at kemper.freedesktop.org
Wed Oct 14 06:10:16 UTC 2015


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

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Mon Oct  5 11:42:43 2015 +0200

glsl: Fix variable_referenced() for vector_{extract,insert} expressions

We get these when we operate on vector variables with array accessors
(i.e. things like a[0] where 'a' is a vec4). When we call variable_referenced()
on these expressions we want to return a reference to 'a' instead of NULL.

This fixes a problem where we pass a[0] as the first argument to an atomic
SSBO function that expects a buffer variable. In order to check this, we use
variable_referenced(), but that is currently returning NULL in this case, since
the underlying rvalue is a vector_extract expression.

Tested-by: Markus Wick <markus at selfnet.de>
Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>

---

 src/glsl/ir.cpp |   16 ++++++++++++++++
 src/glsl/ir.h   |    2 ++
 2 files changed, 18 insertions(+)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 2c45b9e..4c22843 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -662,6 +662,22 @@ ir_expression::get_operator(const char *str)
    return (ir_expression_operation) -1;
 }
 
+ir_variable *
+ir_expression::variable_referenced() const
+{
+   switch (operation) {
+      case ir_binop_vector_extract:
+      case ir_triop_vector_insert:
+         /* We get these for things like a[0] where a is a vector type. In these
+          * cases we want variable_referenced() to return the actual vector
+          * variable this is wrapping.
+          */
+         return operands[0]->variable_referenced();
+      default:
+         return ir_rvalue::variable_referenced();
+   }
+}
+
 ir_constant::ir_constant()
    : ir_rvalue(ir_type_constant)
 {
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 43a2bf0..9c9f22d 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1731,6 +1731,8 @@ public:
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
 
+   virtual ir_variable *variable_referenced() const;
+
    ir_expression_operation operation;
    ir_rvalue *operands[4];
 };




More information about the mesa-commit mailing list