summaryrefslogtreecommitdiffstats
path: root/tests/spirv/mesh-primitive.slang
blob: 2cc9d9824bd85daf3d140d0a81c18ff9f474b651 (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
62
63
64
//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly

// CHECK: OpDecorate %primitives_color Location 0
// CHECK: OpDecorate %primitives_color PerPrimitive
// CHECK: OpDecorate %prim_color Location 0
// CHECK: OpDecorate %prim_color Flat

const static uint MAX_VERTS = 6;
const static uint MAX_PRIMS = 2;

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

struct Vertex
{
  float4 pos : SV_Position;
};

struct Primitive
{
  [[vk::location(0)]] float3 color;
}

[outputtopology("triangle")]
[numthreads(MAX_VERTS, 1, 1)]
[shader("mesh")]
void entry_mesh(
    in uint tig : SV_GroupThreadID,
    OutputVertices<Vertex, MAX_VERTS> verts,
    OutputIndices<uint3, MAX_PRIMS> triangles,
    OutputPrimitives<Primitive, MAX_PRIMS> primitives)
{
    const uint numVertices = MAX_VERTS;
    const uint numPrimitives = MAX_PRIMS;
    SetMeshOutputCounts(numVertices, numPrimitives);

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

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

struct FragmentOut
{
    [[vk::location(0)]] float3 color;
};

[shader("fragment")]
FragmentOut entry_fragment(in nointerpolation Primitive prim)
{
    FragmentOut frag_out;
    frag_out.color = prim.color;
    return frag_out;
}