|
| 1 | +//TEST(compute):COMPARE_RENDER_COMPUTE: |
| 2 | + |
| 3 | +//TEST_INPUT: global_type AssembledVertex |
| 4 | +//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(1),glbinding(0),out |
| 5 | + |
| 6 | +// Testing associated types in a varying parameter field |
| 7 | + |
| 8 | +interface IColorSet |
| 9 | +{ |
| 10 | + float3 getColor(); |
| 11 | +} |
| 12 | + |
| 13 | +struct NoColorSet : IColorSet |
| 14 | +{ |
| 15 | + float3 getColor() { return float3(0.0); } |
| 16 | +}; |
| 17 | + |
| 18 | +struct SingleColorSet : IColorSet |
| 19 | +{ |
| 20 | + float3 color; |
| 21 | + float3 getColor() { return color; } |
| 22 | +}; |
| 23 | + |
| 24 | +interface IVertexFormat |
| 25 | +{ |
| 26 | + associatedtype ColorSet : IColorSet; |
| 27 | + ColorSet getColorSet(); |
| 28 | + float3 getPosition(); |
| 29 | + float2 getUv(); |
| 30 | +} |
| 31 | + |
| 32 | +type_param TVertex : IVertexFormat; |
| 33 | + |
| 34 | +cbuffer Uniforms |
| 35 | +{ |
| 36 | + float4x4 modelViewProjection; |
| 37 | +} |
| 38 | +RWStructuredBuffer<float> outputBuffer; |
| 39 | + |
| 40 | +struct AssembledVertex : IVertexFormat |
| 41 | +{ |
| 42 | + typedef SingleColorSet ColorSet; |
| 43 | + float3 position; |
| 44 | + SingleColorSet colorSet; |
| 45 | + float2 uv; |
| 46 | + ColorSet getColorSet() { return colorSet; } |
| 47 | + float3 getPosition() { return position; } |
| 48 | + float2 getUv() { return uv; } |
| 49 | +}; |
| 50 | + |
| 51 | +struct CoarseVertex |
| 52 | +{ |
| 53 | + TVertex.ColorSet color; |
| 54 | + float2 uv; |
| 55 | +}; |
| 56 | + |
| 57 | +struct Fragment |
| 58 | +{ |
| 59 | + float4 color; |
| 60 | +}; |
| 61 | + |
| 62 | + |
| 63 | +// Vertex Shader |
| 64 | + |
| 65 | +struct VertexStageInput |
| 66 | +{ |
| 67 | + TVertex assembledVertex : A; |
| 68 | +}; |
| 69 | + |
| 70 | +struct VertexStageOutput |
| 71 | +{ |
| 72 | + CoarseVertex coarseVertex : CoarseVertex; |
| 73 | + float4 sv_position : SV_Position; |
| 74 | +}; |
| 75 | + |
| 76 | +VertexStageOutput vertexMain(VertexStageInput input) |
| 77 | +{ |
| 78 | + VertexStageOutput output; |
| 79 | + |
| 80 | + float3 position = input.assembledVertex.getPosition(); |
| 81 | + output.sv_position = mul(modelViewProjection, float4(position, 1.0)); |
| 82 | + output.coarseVertex.uv = input.assembledVertex.getUv(); |
| 83 | + output.coarseVertex.color = input.assembledVertex.getColorSet(); |
| 84 | + return output; |
| 85 | +} |
| 86 | + |
| 87 | +// Fragment Shader |
| 88 | + |
| 89 | +struct FragmentStageInput |
| 90 | +{ |
| 91 | + CoarseVertex coarseVertex : CoarseVertex; |
| 92 | +}; |
| 93 | + |
| 94 | +struct FragmentStageOutput |
| 95 | +{ |
| 96 | + Fragment fragment : SV_Target; |
| 97 | +}; |
| 98 | + |
| 99 | +FragmentStageOutput fragmentMain(FragmentStageInput input) |
| 100 | +{ |
| 101 | + FragmentStageOutput output; |
| 102 | + float3 color = input.coarseVertex.color.getColor(); |
| 103 | + float2 uv = input.coarseVertex.uv; |
| 104 | + output.fragment.color = float4(color, 1.0); |
| 105 | + outputBuffer[0] = 1.0; |
| 106 | + return output; |
| 107 | +} |
0 commit comments