From: Eric Anholt Date: Wed, 12 Nov 2014 22:14:32 +0000 (-0800) Subject: vc4: Avoid reusing a pointer from c->outputs[] after add_output(). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b3d269f5ae1844b542d8e875d7177c5eff3a29f2;p=mesa.git vc4: Avoid reusing a pointer from c->outputs[] after add_output(). add_output() can resize the qreg array, so we might use a stale pointer. --- diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index 1cc6e9615b4..ef0d5b89c93 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -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;