Bug 29199

Summary: Using negation as an argument to a shader function sometimes negates twice
Product: Mesa Reporter: Neil Roberts <nroberts>
Component: glsl-compilerAssignee: Ian Romanick <idr>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: medium    
Version: git   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Add a shader which does a negation as one of the arguments to dot

Description Neil Roberts 2010-07-21 11:40:04 UTC
In some situations (I'm not exactly sure what) if you use the unary negate operator in one of the arguments to a function then Mesa generates opcodes which do the negation twice (once in a MOV and once as part of a swizzle).

For example, something like this:

vec3 vec_a;
vec3 vec_b;

/* .... */

float result = dot(-vec_a, vec_b);

generates the following instructions:

MOV TEMP[1].xyz, TEMP[1].-x-y-z-w;           <-- negation once with MOV
MOV (-1 -0 -0 -0)
DP3 TEMP[0].w, TEMP[1].-x-y-z-w, UNIFORM[1]; <-- negation again with swizzle
DP3 -1 = (1 0 0) . (-1 0 0)

Attached is a test for piglit.
Comment 1 Neil Roberts 2010-07-21 11:41:33 UTC
Created attachment 37276 [details] [review]
Add a shader which does a negation as one of the arguments to dot

This is basically doing:

 vec3 a_vec;
 vec3 b_vec;
 /* some random calculations */
 float result = dot(-a_vec, b_vec);

But for some reason it currently gets compiled as if it was:

 vec3 a_vec;
 vec3 b_vec;
 /* some random calculations */
 float result = dot(--a_vec, b_vec);

Ie, the negation gets done twice.
Comment 2 Ian Romanick 2010-12-14 17:26:29 UTC
I added this test case to piglit, but it seems to pass with both i965 and swrast.  It seems likely that this was fixed somewhere over the last 5 months, but who knows which commit did it.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.