yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaMesh shader refactoring and bugfixes (#3702)d40931cc8

master
2.6 KiB116 linesraw
1// component-write.slang
2
3// This tests that writing to individual components of the output struct works
4
5//TEST:SIMPLE(filecheck=SPIRV): -target spirv-assembly -entry main -stage mesh -profile glsl_450+spirv_1_4
6
7// DXC is stricter than we are about passing references to individual mesh shader outputs
8// We could get around this by doing what we do for GLSL, i.e. use a temporary
9// variable to pass as the out parameter, and then copy that into the array
10// after the function call.
11//TEST_DISABLED:CROSS_COMPILE:-target dxil-assembly  -entry main -stage mesh -profile sm_6_6
12
13// SPIRV: OpEntryPoint MeshEXT %main
14
15const static uint MAX_VERTS = 3;
16const static uint MAX_PRIMS = 1;
17
18struct Texes
19{
20    float2 tex1;
21    float4 tex2;
22}
23
24struct Vertex
25{
26    float4 pos : SV_Position;
27    float3 col : Color;
28    Texes  ts  : Coord;
29};
30
31void everything<let N : uint>(OutputVertices<Vertex, N> vs)
32{
33    vs[0] = {float4(0), float3(1)};
34}
35
36void just_one(out Vertex v)
37{
38    v = {float4(0), float3(1)};
39}
40
41void just_two(out Vertex v, out Vertex w)
42{
43    v = {float4(0), float3(1)};
44    w = v;
45}
46
47void part_of_one(out float4 p)
48{
49    p = float4(1,2,3,4);
50}
51
52void write_struct(out Texes t)
53{
54    t.tex1 = float2(0);
55    t.tex2 = float4(1);
56}
57
58// Split out the things to test to avoid main becoming an unreadable jumble
59void a<let N : uint>(OutputVertices<Vertex, N> vs)
60{
61    // Test passing a reference to the entire array
62    everything(vs);
63}
64
65void b<let N : uint>(OutputVertices<Vertex, N> vs)
66{
67    // test passing two references to the same element
68    just_two(vs[0], vs[0]);
69}
70
71void c<let N : uint>(OutputVertices<Vertex, N> vs, uint tig)
72{
73    // Test passing a reference to an element
74    just_one(vs[tig]);
75}
76
77void d<let N : uint>(OutputVertices<Vertex, N> vs, uint tig)
78{
79    // Test passing references to different elements (to check that the operand
80    // rewriting doesn't mess the order)
81    just_two(vs[tig], vs[0]);
82}
83
84void e<let N : uint>(OutputVertices<Vertex, N> vs, uint tig)
85{
86    // Test passing a scalar member and a struct member and a struct member's member
87    part_of_one(vs[tig].pos);
88    write_struct(vs[tig].ts);
89    part_of_one(vs[tig].ts.tex2);
90}
91
92[outputtopology("triangle")]
93[numthreads(3, 1, 1)]
94void main(
95    in uint tig : SV_GroupIndex,
96    OutputVertices<Vertex, MAX_VERTS> verts,
97    OutputIndices<uint3, MAX_PRIMS> triangles
98    )
99{
100    const uint numVertices = 3;
101    const uint numPrimitives = 1;
102    SetMeshOutputCounts(numVertices, numPrimitives);
103
104    if(tig < numVertices) {
105        a(verts);
106        b(verts);
107        c(verts, tig);
108        d(verts, tig);
109        e(verts, tig);
110    }
111
112    if(tig < numPrimitives) {
113        triangles[tig] = uint3(0,1,2);
114    }
115}
116