yum-mirror/slang

Making it easier to work with shaders

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

Lujin WangFix mesh shader OutputIndices subscript error by adding missing ref accessor (#7929)cd9e1f671

master
1.8 KiB54 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target spirv -profile sm_6_6 -stage mesh -entry main
2
3struct MeshOutput
4{
5    float4 position : SV_Position;
6    float3 color : COLOR0;
7}
8
9// Uniform variable for time-based animation
10uniform uint iTime;
11
12[shader("mesh")]
13[outputtopology("triangle")]
14[numthreads(1, 1, 1)]
15void main(
16    in uint tig : SV_GroupIndex,
17    OutputVertices<MeshOutput, 3> vertices,
18    OutputIndices<uint3, 1> triangles
19)
20{
21    // Set the number of vertices and primitives
22    SetMeshOutputCounts(3, 1);
23
24    // Define the triangle indices
25    triangles[0] = uint3(0, 1, 2);
26
27    // Use uiColor as in the original shader
28    // This line should now work after the fix - it was causing the "subscript had no getter" error
29    uint uiColor = triangles[0].x + iTime;
30
31    // Create triangle vertices with time-based animation
32    float timeOffset = float(iTime) * 0.01; // Convert to float and scale
33    float colorOffset = float(uiColor) * 0.005; // Use uiColor for color variation
34
35    // Vertex 0 - Red vertex (top) with uiColor influence
36    vertices[0].position = float4(0.0, 0.5 + sin(timeOffset) * 0.1, 0.0, 1.0);
37    vertices[0].color = float3(1.0, (sin(colorOffset) + 1.0) * 0.5, 0.0); // Red with green modulation from uiColor
38
39    // Vertex 1 - Green vertex (bottom left)
40    vertices[1].position = float4(-0.5, -0.5, 0.0, 1.0);
41    vertices[1].color = float3(0.0, 1.0, 0.0); // Green
42
43    // Vertex 2 - Blue vertex (bottom right)
44    vertices[2].position = float4(0.5, -0.5, 0.0, 1.0);
45    vertices[2].color = float3(0.0, 0.0, 1.0); // Blue
46}
47
48// CHECK: OpCapability MeshShadingEXT
49// CHECK: OpExtension "SPV_EXT_mesh_shader"
50// CHECK: OpEntryPoint MeshEXT %main "main"
51// CHECK: OpExecutionMode %main OutputPrimitivesEXT 1
52// CHECK: OpExecutionMode %main OutputVertices 3
53// CHECK: OpExecutionMode %main LocalSize 1 1 1
54// CHECK: OpExecutionMode %main OutputTrianglesEXT