From 1293db75361d753f93f3e4366b106288dcd8ba13 Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Fri, 10 May 2024 00:51:05 +1000 Subject: [PATCH] tests/hlsl: Add a test for SV_PrimitiveId inputs and outputs. --- Makefile.am | 1 + tests/hlsl/primitive-id.shader_test | 76 +++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/hlsl/primitive-id.shader_test diff --git a/Makefile.am b/Makefile.am index 83acddb60..3102a7829 100644 --- a/Makefile.am +++ b/Makefile.am @@ -215,6 +215,7 @@ vkd3d_shader_tests = \ tests/hlsl/pointer-cast.shader_test \ tests/hlsl/pow.shader_test \ tests/hlsl/precise-modifier.shader_test \ + tests/hlsl/primitive-id.shader_test \ tests/hlsl/rasteriser-ordered-views.shader_test \ tests/hlsl/rcp.shader_test \ tests/hlsl/reflect.shader_test \ diff --git a/tests/hlsl/primitive-id.shader_test b/tests/hlsl/primitive-id.shader_test new file mode 100644 index 000000000..225159c05 --- /dev/null +++ b/tests/hlsl/primitive-id.shader_test @@ -0,0 +1,76 @@ +[require] +shader model >= 4.0 +geometry-shader + +[vertex shader] +struct vs_data +{ + float4 pos : SV_Position; + float4 color : COLOR; +}; + +void main(out struct vs_data vs_output) +{ + vs_output.pos = float4(0.0, 0.0, 1.0, 1.0); + vs_output.color = float4(0.0, 0.0, 1.0, 1.0); +} + +[geometry shader] +struct gs_data +{ + float4 pos : SV_Position; + float4 color : COLOR; +}; + +struct gs_out +{ + float4 pos : SV_Position; + float4 color : COLOR; + uint prim_id : SV_PrimitiveId; +}; + + [maxvertexcount(4)] +void main(point struct gs_data vin[1], in uint prim_id : SV_PrimitiveId, inout TriangleStream vout) +{ + float offset = 0.2 * vin[0].pos.w; + gs_out v; + + v.color = vin[0].color; + /* This only confirms that prim_id is zero. */ + v.color.x = prim_id * 0.25f; + + v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0); + v.prim_id = 0; + vout.Append(v); + v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0); + v.prim_id = 1; + vout.Append(v); + v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0); + vout.Append(v); + v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0); + vout.Append(v); +} + +[pixel shader] +struct ps_data +{ + float4 pos : SV_Position; + float4 color : COLOR; + uint prim_id : SV_PrimitiveId; +}; + +float4 main(struct ps_data ps_input) : SV_Target +{ + float4 color = ps_input.color; + color.y = ps_input.prim_id * 0.25f; + return color; +} + +[test] +todo(glsl | sm>=6) bug(mvk) draw point list 1 +probe rtv 0 (320, 190) f32(0.0, 0.0, 0.0, 0.0) +probe rtv 0 (255, 240) f32(0.0, 0.0, 0.0, 0.0) +probe rtv 0 (319, 241) f32(0.0, 0.0, 1.0, 1.0) +probe rtv 0 (321, 239) f32(0.0, 0.25, 1.0, 1.0) +probe rtv 0 (385, 240) f32(0.0, 0.0, 0.0, 0.0) +probe rtv 0 (320, 290) f32(0.0, 0.0, 0.0, 0.0)