[Mesa-dev] [PATCH 2/3] glsl: handle partial swizzles in opt_dead_code_local correctly

Marek Olšák maraeo at gmail.com
Wed Nov 9 12:12:40 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

---
 src/compiler/glsl/opt_dead_code_local.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/compiler/glsl/opt_dead_code_local.cpp b/src/compiler/glsl/opt_dead_code_local.cpp
index fc979af..a403879 100644
--- a/src/compiler/glsl/opt_dead_code_local.cpp
+++ b/src/compiler/glsl/opt_dead_code_local.cpp
@@ -99,23 +99,26 @@ public:
    }
 
    virtual ir_visitor_status visit(ir_swizzle *ir)
    {
       ir_dereference_variable *deref = ir->val->as_dereference_variable();
       if (!deref)
 	 return visit_continue;
 
       int used = 0;
       used |= 1 << ir->mask.x;
-      used |= 1 << ir->mask.y;
-      used |= 1 << ir->mask.z;
-      used |= 1 << ir->mask.w;
+      if (ir->mask.num_components > 1)
+         used |= 1 << ir->mask.y;
+      if (ir->mask.num_components > 2)
+         used |= 1 << ir->mask.z;
+      if (ir->mask.num_components > 3)
+         used |= 1 << ir->mask.w;
 
       use_channels(deref->var, used);
 
       return visit_continue_with_parent;
    }
 
    virtual ir_visitor_status visit_leave(ir_emit_vertex *)
    {
       /* For the purpose of dead code elimination, emitting a vertex counts as
        * "reading" all of the currently assigned output variables.
-- 
2.7.4



More information about the mesa-dev mailing list