diff options
author | Samuel Iglesias Gonsalvez <[email protected]> | 2015-06-11 12:32:26 +0200 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2015-08-03 09:40:50 -0700 |
commit | 418c004f802e63ca4e9f3456a46498d2fc543854 (patch) | |
tree | 45904a9d62c917c03b186fd8d08eb8e6021b54d0 | |
parent | 19cf934f7f18237e1a212b0a019026d5d36c6fac (diff) |
nir: Fix output swizzle in get_mul_for_src
Avoid copying an overwritten swizzle, use the original values.
Example:
Former swizzle[] = xyzw
src->swizzle[] = zyxx
The expected output swizzle = zyxx but if we reuse swizzle in the loop,
then output swizzle would be zyzz.
Signed-off-by: Samuel Iglesias Gonsalvez <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
-rw-r--r-- | src/glsl/nir/nir_opt_peephole_ffma.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/glsl/nir/nir_opt_peephole_ffma.c b/src/glsl/nir/nir_opt_peephole_ffma.c index 798506b7595..a823adbb465 100644 --- a/src/glsl/nir/nir_opt_peephole_ffma.c +++ b/src/glsl/nir/nir_opt_peephole_ffma.c @@ -76,6 +76,7 @@ static nir_alu_instr * get_mul_for_src(nir_alu_src *src, int num_components, uint8_t swizzle[4], bool *negate, bool *abs) { + uint8_t swizzle_tmp[4]; assert(src->src.is_ssa && !src->abs && !src->negate); nir_instr *instr = src->src.ssa->parent_instr; @@ -116,8 +117,18 @@ get_mul_for_src(nir_alu_src *src, int num_components, if (!alu) return NULL; + /* Copy swizzle data before overwriting it to avoid setting a wrong swizzle. + * + * Example: + * Former swizzle[] = xyzw + * src->swizzle[] = zyxx + * + * Expected output swizzle = zyxx + * If we reuse swizzle in the loop, then output swizzle would be zyzz. + */ + memcpy(swizzle_tmp, swizzle, 4*sizeof(uint8_t)); for (unsigned i = 0; i < num_components; i++) - swizzle[i] = swizzle[src->swizzle[i]]; + swizzle[i] = swizzle_tmp[src->swizzle[i]]; return alu; } |