From b3d269f5ae1844b542d8e875d7177c5eff3a29f2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Nov 2014 14:14:32 -0800 Subject: [PATCH] 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. --- src/gallium/drivers/vc4/vc4_program.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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; -- 2.11.0