vc4: Avoid reusing a pointer from c->outputs[] after add_output().
authorEric Anholt <eric@anholt.net>
Wed, 12 Nov 2014 22:14:32 +0000 (14:14 -0800)
committerEric Anholt <eric@anholt.net>
Thu, 13 Nov 2014 02:24:10 +0000 (18:24 -0800)
add_output() can resize the qreg array, so we might use a stale pointer.

src/gallium/drivers/vc4/vc4_program.c

index 1cc6e9615b40eae63a12da8dd260522f84fe3fa1..ef0d5b89c93f6e2cebadfed84cfa31cb5ce78371 100644 (file)
@@ -1822,12 +1822,11 @@ emit_stub_vpm_read(struct vc4_compile *c)
 static void
 emit_ucp_clipdistance(struct vc4_compile *c)
 {
-        struct qreg *clipvertex;
-
+        unsigned cv;
         if (c->output_clipvertex_index != -1)
-                clipvertex = &c->outputs[c->output_clipvertex_index];
+                cv = c->output_clipvertex_index;
         else if (c->output_position_index != -1)
-                clipvertex = &c->outputs[c->output_position_index];
+                cv = c->output_position_index;
         else
                 return;
 
@@ -1846,12 +1845,14 @@ emit_ucp_clipdistance(struct vc4_compile *c)
                            plane,
                            TGSI_SWIZZLE_X);
 
+
                 struct qreg dist = qir_uniform_f(c, 0.0);
                 for (int i = 0; i < 4; i++) {
+                        struct qreg pos_chan = c->outputs[cv + i];
                         struct qreg ucp =
                                 add_uniform(c, QUNIFORM_USER_CLIP_PLANE,
                                             plane * 4 + i);
-                        dist = qir_FADD(c, dist, qir_FMUL(c, clipvertex[i], ucp));
+                        dist = qir_FADD(c, dist, qir_FMUL(c, pos_chan, ucp));
                 }
 
                 c->outputs[output_index] = dist;