diff --git a/Makefile.am b/Makefile.am index cfb225f9..9e761ef3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -170,6 +170,7 @@ vkd3d_shader_tests = \ tests/hlsl/side-effects.shader_test \ tests/hlsl/sign.shader_test \ tests/hlsl/single-numeric-initializer.shader_test \ + tests/hlsl/sm1-const-folding.shader_test \ tests/hlsl/sm6-ternary.shader_test \ tests/hlsl/sm6-uav-rwtexture.shader_test \ tests/hlsl/smoothstep.shader_test \ diff --git a/tests/hlsl/sm1-const-folding.shader_test b/tests/hlsl/sm1-const-folding.shader_test new file mode 100644 index 00000000..1766de38 --- /dev/null +++ b/tests/hlsl/sm1-const-folding.shader_test @@ -0,0 +1,146 @@ +% Test the interaction between integer constant folding and the fact +% that integers are secretly considered floats in SM1-3 + +[pixel shader] +float4 main() : SV_TARGET +{ + uint x = 3000000000u; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +probe all rgba (3.0e+009, 0.0, 0.0, 0.0) + +% The uint value is never casted to int on SM1-3, just casted to float and treated as such +[pixel shader] +float4 main() : SV_TARGET +{ + int x = 3000000000u; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +if(sm<4) todo probe all rgba (3.0e+009, 0.0, 0.0, 0.0) +if(sm>=4) probe all rgba (-1.29496730e+009, 0.0, 0.0, 0.0) + +% On SM1-5 (FXC) the literal is considered signed independently of its value and casted to uint; +% on SM1-3 compilation fails because the uint would be negative +[pixel shader fail(sm<4) todo(sm<4)] +float4 main() : SV_TARGET +{ + uint x = 3000000000; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +if(sm>=4) probe all rgba (3.0e+009, 0.0, 0.0, 0.0) + +[pixel shader] +float4 main() : SV_TARGET +{ + int x = 3000000000; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +probe all rgba (-1.29496730e+009, 0.0, 0.0, 0.0) + +[pixel shader] +float4 main() : SV_TARGET +{ + return float4(3000000000u, 0.0, 0.0, 0.0); +} + +[test] +draw quad +probe all rgba (3.0e+009, 0.0, 0.0, 0.0) + +% Unsuffixed literals can instead be considered unsigned on SM6 +[pixel shader] +float4 main() : SV_TARGET +{ + return float4(3000000000, 0.0, 0.0, 0.0); +} + +[test] +draw quad +if(sm<6) probe all rgba (-1.29496730e+009, 0.0, 0.0, 0.0) +if(sm>=6) probe all rgba (3.0e+009, 0.0, 0.0, 0.0) + +% Constant folding is done with uint semantics before converting to float; +% so constant folding seems to happen before converting integer operations to floats +[pixel shader] +float4 main() : SV_TARGET +{ + uint x = 3000000000u + 3000000000u; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +probe all rgba (1.70503270e+009, 0.0, 0.0, 0.0) + +% SM1-3 complains that uint values must be positive, but it's not clear why this is a problem here: +% the sum should be done before casting to uint, and the result of the int sum should be positive, +% so it seems that the declared type of x means something on how constant folding is done. +% I'm not sure what's happening for SM4 anyway +[pixel shader fail(sm<4) todo(sm<4)] +float4 main() : SV_TARGET +{ + uint x = 3000000000 + 3000000000; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +todo probe all rgba (2.14748365e+009, 0.0, 0.0, 0.0) + +% Again, no idea of what's happening here +[pixel shader] +float4 main() : SV_TARGET +{ + int x = 3000000000 + 3000000000; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +todo probe all rgba (-2.14748365e+009, 0.0, 0.0, 0.0) + +% This makes sense +[pixel shader] +float4 main() : SV_TARGET +{ + return float4(3000000000u + 3000000000u, 0.0, 0.0, 0.0); +} + +[test] +draw quad +probe all rgba (1.70503270e+009, 0.0, 0.0, 0.0) + +% This does not again +[pixel shader] +float4 main() : SV_TARGET +{ + return float4(3000000000 + 3000000000, 0.0, 0.0, 0.0); +} + +[test] +draw quad +todo probe all rgba (-2.14748365e+009, 0.0, 0.0, 0.0) + +% Explicit float literals use float semantics, at least +[pixel shader] +float4 main() : SV_TARGET +{ + float x = 3000000000.0 + 3000000000.0; + return float4(x, 0.0, 0.0, 0.0); +} + +[test] +draw quad +probe all rgba (6.0e+009, 0.0, 0.0, 0.0)