yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)Enable metal tests (#8446)8086adc90

master
1.7 KiB76 linesraw
1//TEST:SIMPLE(filecheck=METAL): -entry meshMain -stage mesh -target metal
2//TEST:SIMPLE(filecheck=METALLIB): -entry meshMain -stage mesh -target metallib
3
4// METALLIB-NOT: error :
5// METALLIB: @meshMain
6
7//
8// Mesh shader
9//
10
11const static float2 positions[3] = {
12    float2(0.0, -0.5),
13    float2(0.5, 0.5),
14    float2(-0.5, 0.5)
15};
16
17const static float3 colors[3] = {
18    float3(1.0, 1.0, 0.0),
19    float3(0.0, 1.0, 1.0),
20    float3(1.0, 0.0, 1.0)
21};
22
23struct MeshPayload
24{
25    int exponent;
26};
27
28
29struct Vertex
30{
31    float4 pos : SV_Position;
32    float3 color : Color;
33    int index : Index;
34    int value : Value;
35};
36
37struct Primitive
38{
39    uint prim : SV_PrimitiveID;
40};
41
42const static uint MAX_VERTS = 12;
43const static uint MAX_PRIMS = 4;
44
45[outputtopology("triangle")]
46[shader("mesh")]
47[numthreads(12, 1, 1)]
48void meshMain(
49    in uint tig: SV_GroupIndex,
50    in payload MeshPayload meshPayload,
51    // METAL: const MeshPayload_0 object_data* meshPayload_0
52    OutputVertices<Vertex, MAX_VERTS> verts,
53    OutputIndices<uint3, MAX_PRIMS> triangles,
54    OutputPrimitives<Primitive, MAX_PRIMS> primitives
55    )
56{
57    const uint numVertices = 12;
58    const uint numPrimitives = 4;
59    SetMeshOutputCounts(numVertices, numPrimitives);
60
61    if (tig < numVertices)
62    {
63        const int tri = tig / 3;
64        verts[tig] = { float4(positions[tig % 3], 0, 1), colors[tig % 3], tri, int(pow(tri, meshPayload.exponent)) };
65    }
66
67    if (tig < numPrimitives)
68    {
69        // METAL: _slang_mesh.set_index({{.*}}+0,{{.*}}[0]);
70        // METAL: _slang_mesh.set_index({{.*}}+1,{{.*}}[1]);
71        // METAL: _slang_mesh.set_index({{.*}}+2,{{.*}}[2]);
72        triangles[tig] = tig * 3 + uint3(0, 1, 2);
73        // METAL: _slang_mesh.set_primitive({{.*}}
74        primitives[tig] = { tig };
75    }
76}