On 1/25/22 05:07, 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);
+}
I don't really like this approach. For one thing, it makes it harder to validate e.g. patches 4-6 from this series (I essentially have to write my own shaders).
The complexity of the generated shader also makes it harder to read the IR to validate it's doing the right thing.
Perhaps more importantly, some of these operations are supported by all HLSL versions, but some are only supported by SM4 (notably integer operations). Anything that can be tested in sm2 or sm3 should be, and as such I'd appreciate splitting those out where possible.