Skip to content

nir/algebraic: Fix some min/max of b2f replacements related

Ian Romanick requested to merge idr/mesa:review/issue-1346 into master

fmin(-A, -B) is -fmax(A, B), and fmax(-A, -B) is -fmin(A, B). Therefore the logic joining A and B should toggle between ior and iand for the negated versions.

At the very least, a shader from Euro Truck Simulator 2 in shader-db is affected by this. The KIL instruction in the (ARB assembly) shader ends up with the wrong logic. This is probably the source of #1346 (closed).

That said, the issue mentions that Mesa 18.0.5 works, but commit 68420d83 ("nir: Simplify min and max of b2f") was added in 17.3. Moreover, I was not able to reproduce the error in the ETS2 shader from shader-db from any Mesa commit near the time the original fd.o bugzilla was submitted (December 2018). 🤷

In fact, the current error in that shader starts with 9167324a ("nir/algebraic: Mark some logic-joined comparison reductions as exact"). That's a bit of a red herring as 9167324a just sets off a chain of replacements that eventually leads to the incorrect min/max of b2f patterns fixed by this commit.

The other affected shaders in the shader-db results are from Cargo Commander. These are also ARB assembly shaders.

I think any ARB assembly shader that uses the pattern

        SLT    r0, ...;
        ...
        KIL    -r0;

will suffer from issues related to this.

This change fixes the piglit tests/spec/arb_fragment_program/kil-of-slt.shader_test test added in piglit!454 (merged).

Fixes: 68420d83 ("nir: Simplify min and max of b2f")
Closes: #1346 (closed)

Merge request reports