diff --git a/Makefile.am b/Makefile.am index dccd89dd3..39221850f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -250,6 +250,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-centroid.shader_test \ tests/hlsl/sm1-const-allocation.shader_test \ tests/hlsl/sm1-const-folding.shader_test \ tests/hlsl/sm1-interstage-interface.shader_test \ diff --git a/tests/hlsl/sm1-centroid.shader_test b/tests/hlsl/sm1-centroid.shader_test new file mode 100644 index 000000000..69c07504d --- /dev/null +++ b/tests/hlsl/sm1-centroid.shader_test @@ -0,0 +1,181 @@ +[require] +shader model < 4.0 + +[rtv 0] +format r32g32b32a32-float +size (2dms, 4, 640, 480) + +[input layout] +0 r32g32-float POSITION + +% The pixels in the second leftmost column lose two of their samples on the left, in addition to the center. +% x = (1 + 0.1 - 320) / 320 = -0.9965625. +[vb 0] +-0.9965625 1.0 +3.0 1.0 +-0.9965625-3.0 + +[vertex shader] +void main(float2 pos : POSITION, out float4 out_pos : SV_Position, out float2 t : TEXCOORD0) +{ + out_pos = float4(pos, 0.0f, 1.0f); + t = float2(pos.x * 320.0f + 320.0f, -pos.y * 240.0f + 240.0f); +} + +% Center interpolation. +[pixel shader] +static const float2 sample_pos = {-0.001f, 0.000f}; + +float4 main(float2 t : TEXCOORD0) : SV_Target +{ + float2 ref = round(t); + bool first_col = ref.x == 1.0f; + float2 diff = t.xy - ref; + float2 expected = first_col ? sample_pos : 0.0f; + float2 err = abs(diff - expected); + return floor(1000.0f * float4(err, 0.0f, 0.0f)); +} + +[test] +clear rtv 0 1.0 1.0 1.0 1.0 +draw triangle list 3 +probe (1, 1) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 1) f32(0.0, 0.0, 0.0, 0.0) +probe (1, 478) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 479) f32(0.0, 0.0, 0.0, 0.0) + +% Centroid interpolation. +% The WARP driver doesn't seem to support centroid interpolation for SM < 4. +[pixel shader todo] +static const float2 sample_pos = {-0.001f, 0.000f}; + +float4 main(centroid float2 t : TEXCOORD0) : SV_Target +{ + float2 ref = round(t); + bool first_col = ref.x == 1.0f; + float2 diff = t.xy - ref; + float2 expected = first_col ? sample_pos : 0.0f; + float2 err = abs(diff - expected); + return floor(1000.0f * float4(err, 0.0f, 0.0f)); +} + +[test] +clear rtv 0 1.0 1.0 1.0 1.0 +todo draw triangle list 3 +todo probe (1, 1) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 1) f32(0.0, 0.0, 0.0, 0.0) +todo probe (1, 478) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 479) f32(0.0, 0.0, 0.0, 0.0) + +% The WARP driver doesn't seem to support centroid interpolation for SM < 4. +[pixel shader todo] +static const float2 sample_pos = {-0.001f, 0.000f}; + +float4 main(float2 t : TEXCOORD0_centRoid) : SV_Target +{ + float2 ref = round(t); + bool first_col = ref.x == 1.0f; + float2 diff = t.xy - ref; + float2 expected = first_col ? sample_pos : 0.0f; + float2 err = abs(diff - expected); + return floor(1000.0f * float4(err, 0.0f, 0.0f)); +} + +[test] +clear rtv 0 1.0 1.0 1.0 1.0 +todo draw triangle list 3 +todo probe (1, 1) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 1) f32(0.0, 0.0, 0.0, 0.0) +todo probe (1, 478) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 479) f32(0.0, 0.0, 0.0, 0.0) + +% The WARP driver doesn't seem to support centroid interpolation for SM < 4. +[pixel shader todo] +static const float2 sample_pos = {-0.001f, 0.000f}; + +struct ps_in +{ + float2 t : TEXCOORD0_centRoid; +}; + +float4 main(ps_in data) : SV_Target +{ + float2 ref = round(data.t); + bool first_col = ref.x == 1.0f; + float2 diff = data.t.xy - ref; + float2 expected = first_col ? sample_pos : 0.0f; + float2 err = abs(diff - expected); + return floor(1000.0f * float4(err, 0.0f, 0.0f)); +} + +[test] +clear rtv 0 1.0 1.0 1.0 1.0 +todo draw triangle list 3 +todo probe (1, 1) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 1) f32(0.0, 0.0, 0.0, 0.0) +todo probe (1, 478) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 479) f32(0.0, 0.0, 0.0, 0.0) + +% The "_centroid" semantic modifier can be specified together with the "centroid" prefix attribute. +% The WARP driver doesn't seem to support centroid interpolation for SM < 4. +[pixel shader todo] +static const float2 sample_pos = {-0.001f, 0.000f}; + +float4 main(centroid float2 t : TEXCOORD0_centroid) : SV_Target +{ + float2 ref = round(t); + bool first_col = ref.x == 1.0f; + float2 diff = t.xy - ref; + float2 expected = first_col ? sample_pos : 0.0f; + float2 err = abs(diff - expected); + return floor(1000.0f * float4(err, 0.0f, 0.0f)); +} + +[test] +clear rtv 0 1.0 1.0 1.0 1.0 +todo draw triangle list 3 +todo probe (1, 1) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 1) f32(0.0, 0.0, 0.0, 0.0) +todo probe (1, 478) f32(0.5, 0.5, 0.5, 0.5) +probe (638, 479) f32(0.0, 0.0, 0.0, 0.0) + +% The semantic name is this case is "TEXCOORD_centroid", which is not valid for SM < 4. +[pixel shader fail] +float4 main(float2 t : TEXCOORD_centroid0) : SV_Target +{ + return t.x; +} + +% The semantic name is this case is "TEXCOORD0_centroid" as well, which is not valid for SM < 4. +[pixel shader fail] +float4 main(float2 t : TEXCOORD0_centroid_centroid) : SV_Target +{ + return t.x; +} + +% The centroid mode can only be applied to texcoord registers in SM2, +% and cannot be applied to any semantic registers in SM3. + +[pixel shader fail(sm<3) todo] +float4 main(centroid float2 t : COLOR) : SV_Target +{ + return t.x; +} + +% The following semantics are invalid in SM2. + +[require] +shader model >= 3.0 +shader model < 4.0 + +[pixel shader fail todo] +float4 main(centroid float t : VFACE) : SV_Target +{ + return t; +} + +[pixel shader fail todo] +float4 main(centroid float3 t : VPOS) : SV_Target +{ + return t.x; +}