summaryrefslogtreecommitdiff
path: root/tests/pipeline/rasterization/mesh/primitive-output.slang
blob: 5bc62f263abfa1391ceaedc5706d69f47789039c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// hello.slang

// Test that a simple mesh shader compiles

//TEST:SIMPLE(filecheck=SPV_CHECK):-target spirv -profile glsl_450+spirv_1_4 -entry main -stage mesh -skip-spirv-validation

//SPV_CHECK-NOT: SPV_NV_mesh_shader
//SPV_CHECK: SPV_EXT_mesh_shader
//SPV_CHECK: CullPrimitiveEXT

const static float2 positions[3] = {
    float2(0.0, -0.5),
    float2(0.5, 0.5),
    float2(-0.5, 0.5)
};  

const static float3 colors[3] = {
    float3(1.0, 1.0, 0.0),
    float3(0.0, 1.0, 1.0),
    float3(1.0, 0.0, 1.0)
};

struct Vertex
{
    float4 pos : SV_Position;
    float3 color : Color;
};

struct Prim
{
    float3 triangleNormal : Normal;
    uint id : SV_PrimitiveID;
    bool cull : SV_CullPrimitive;
};

const static uint MAX_VERTS = 3;
const static uint MAX_PRIMS = 1;

[outputtopology("triangle")]
[numthreads(3, 1, 1)]
void main(
    in uint tig : SV_GroupIndex,
    OutputIndices<uint3, MAX_PRIMS> triangles,
    OutputVertices<Vertex, MAX_VERTS> verts,
    OutputPrimitives<Prim, MAX_PRIMS> primitives
    )
{
    const uint numVertices = 3;
    const uint numPrimitives = 1;
    SetMeshOutputCounts(numVertices, numPrimitives);

    if(tig < numVertices) {
        verts[tig] = {float4(positions[tig], 0, 1), colors[tig]};
    }

    if(tig < numPrimitives) {
        triangles[tig] = uint3(0,1,2);
        primitives[tig] = {float3(0,0,1), tig, false};
    }
}