[PATCH vkd3d 5/5] tests: Test a number of simple HLSL operations.

Matteo Bruni matteo.mystral at gmail.com
Thu Sep 2 15:06:52 CDT 2021


On Tue, Aug 31, 2021 at 7:21 PM Zebediah Figura (she/her)
<zfigura at codeweavers.com> wrote:
>
> On 8/31/21 9:40 AM, Giovanni Mascellani wrote:
> > diff --git a/tests/hlsl-operations.shader_test b/tests/hlsl-operations.shader_test
> > new file mode 100644
> > index 00000000..3c8036b5
> > --- /dev/null
> > +++ b/tests/hlsl-operations.shader_test
> > @@ -0,0 +1,86 @@
> > +[pixel shader]
> > +float4 main(uniform float zero, uniform float one, uniform float x, uniform float y,
> > +            float4 pos : SV_POSITION) : SV_TARGET
> > +{
> > +    int izero = zero;
> > +    int ione = one;
> > +    int ix = x;
> > +    int iy = y;
> > +    uint uzero = zero;
> > +    uint uone = one;
> > +    uint ux = x;
> > +    uint uy = y;
> > +
> > +    if (pos.x == 0.5)
> > +        return float4(x + y, x - y, x * y, x / y);
> > +    if (pos.x == 1.5)
> > +        return float4(ix + iy, ix - iy, ix * iy, ix / iy);
> > +    if (pos.x == 2.5)
> > +        return float4(ux + uy, ux - uy, ux * uy, ux / uy);
> > +    if (pos.x == 3.5)
> > +        return float4(x % y, +x, -x, y / x);
> > +    if (pos.x == 4.5)
> > +        return float4(ix % iy, +ix, -ix, iy / ix);
> > +    if (pos.x == 5.5)
> > +        return float4(ux % uy, +ux, -ux, uy / ux);
> > +    if (pos.x == 6.5)
> > +        return float4(x == y, x != y, x < y, x <= y);
> > +    if (pos.x == 7.5)
> > +        return float4(x > y, x >= y, !x, !zero);
> > +    if (pos.x == 8.5)
> > +        return float4(ix == iy, ix != iy, ix < iy, ix <= iy);
> > +    if (pos.x == 9.5)
> > +        return float4(ix > iy, ix >= iy, !ix, !izero);
> > +    if (pos.x == 10.5)
> > +        return float4(ix & iy, ix | iy, ix ^ iy, ~ix);
> > +    if (pos.x == 11.5)
> > +        return float4(ix >> 2, ix << 2, iy >> 2, iy << 2);
> > +    if (pos.x == 12.5)
> > +        return float4(ux == uy, ux != uy, ux < uy, ux <= uy);
> > +    if (pos.x == 13.5)
> > +        return float4(ux > uy, ux >= uy, !ux, !uzero);
> > +    if (pos.x == 14.5)
> > +        return float4(ux & uy, ux | uy, ux ^ uy, ~ux);
> > +    if (pos.x == 15.5)
> > +        return float4(ux >> 2, ux << 2, uy >> 2, uy << 2);
> > +    if (pos.x == 16.5)
> > +        return float4(zero && zero, zero && one, one && zero, one && one);
> > +    if (pos.x == 17.5)
> > +        return float4(zero || zero, zero || one, one || zero, one || one);
> > +    if (pos.x == 18.5)
> > +        return float4(izero && izero, izero && ione, ione && izero, ione && ione);
> > +    if (pos.x == 19.5)
> > +        return float4(izero || izero, izero || ione, ione || izero, ione || ione);
> > +    if (pos.x == 20.5)
> > +        return float4(uzero && uzero, uzero && uone, uone && uzero, uone && uone);
> > +    if (pos.x == 21.5)
> > +        return float4(uzero || uzero, uzero || uone, uone || uzero, uone || uone);
> > +
> > +    return float4(0.0, 0.0, 0.0, 0.0);
> > +}
> > +
> > +[test]
> > +uniform 0 float4 0.0 1.0 5.0 15.0
> > +draw quad
> > +probe rgba (0, 0) (20.0, -10.0, 75.0, 0.33333333) 1
> > +probe rgba (1, 0) (20.0, -10.0, 75.0, 0.0)
> > +probe rgba (2, 0) (20.0, 4294967300.0, 75.0, 0.0)
> > +probe rgba (3, 0) (5.0, 5.0, -5.0, 3.0) 1
> > +probe rgba (4, 0) (5.0, 5.0, -5.0, 3.0)
> > +probe rgba (5, 0) (5.0, 5.0, 4294967300.0, 3.0)
> > +probe rgba (6, 0) (0.0, 1.0, 1.0, 1.0)
> > +probe rgba (7, 0) (0.0, 0.0, 0.0, 1.0)
> > +probe rgba (8, 0) (0.0, 1.0, 1.0, 1.0)
> > +probe rgba (9, 0) (0.0, 0.0, 0.0, 1.0)
> > +probe rgba (10, 0) (5.0, 15.0, 10.0, -6.0)
> > +probe rgba (11, 0) (1.0, 20.0, 3.0, 60.0)
> > +probe rgba (12, 0) (0.0, 1.0, 1.0, 1.0)
> > +probe rgba (13, 0) (0.0, 0.0, 0.0, 1.0)
> > +probe rgba (14, 0) (5.0, 15.0, 10.0, 4294967300.0)
> > +probe rgba (15, 0) (1.0, 20.0, 3.0, 60.0)
> > +probe rgba (16, 0) (0.0, 0.0, 0.0, 1.0)
> > +probe rgba (17, 0) (0.0, 1.0, 1.0, 1.0)
> > +probe rgba (18, 0) (0.0, 0.0, 0.0, 1.0)
> > +probe rgba (19, 0) (0.0, 1.0, 1.0, 1.0)
> > +probe rgba (20, 0) (0.0, 0.0, 0.0, 1.0)
> > +probe rgba (21, 0) (0.0, 1.0, 1.0, 1.0)
> >
>
> Some of these operations work with SM2-3, but not all of them. We don't
> currently have tests for anything other than 4.0, but ideally we'd like
> to compile all tests on all targets possible.
>
> Not to mention that this is kind of a lot, and I'm not convinced that we
> won't want more tests for any given operation. If nothing else it'd be
> nice to split these into arithmetic, shift, logical, and bitwise tests.

Agreed. It just occurred to me that this kind of shader with a
sequence of branches is a nightmare to generate in ps_2_0 (where there
is no control flow at all). Also there's the issue with pixel
coordinates being offset by 0.5 in d3d9 vs d3d11. And the general
troubles with equality comparisons with floats. All in addition to the
missing vpos in ps_2_0 mentioned by Zeb for patch 2/5.
These concerns can all be worked around to some degree but also make
the whole thing a bit brittle.

I think it would be nicer to rework these tests to split them up
somewhat and avoid branches / conditionals as much as possible. The
tests might calculate e.g. the sum of all the partial results and just
output that for every pixels. Maybe add some comments to explain some
intermediate results when not obvious at a glance.



More information about the wine-devel mailing list