yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
ad379b7c5
master
1// hello.slang 2 3// Test that a simple mesh shader compiles 4 5//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage mesh -profile glsl_450+spirv_1_4 6//TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage mesh -profile sm_6_6 7 8// DXIL: call void @dx.op.setMeshOutputCounts 9// DXIL: call void @dx.op.storeVertexOutput.f32 10// DXIL: call void @dx.op.emitIndices 11// SPIRV: OpEntryPoint MeshEXT %main 12 13// SPIRV-DAG: OpExecutionMode %main OutputVertices 3 14// SPIRV-DAG: OpExecutionMode %main OutputPrimitives{{NV|EXT}} 1 15// SPIRV-DAG: OpExecutionMode %main OutputTriangles{{NV|EXT}} 16 17// SPIRV: OpSetMeshOutputsEXT 18 19const static float2 positions[3] = { 20 float2(0.0, -0.5), 21 float2(0.5, 0.5), 22 float2(-0.5, 0.5) 23}; 24 25const static float3 colors[3] = { 26 float3(1.0, 1.0, 0.0), 27 float3(0.0, 1.0, 1.0), 28 float3(1.0, 0.0, 1.0) 29}; 30 31struct Vertex 32{ 33 float4 pos : SV_Position; 34 float3 color : Color; 35}; 36 37const static uint MAX_VERTS = 3; 38const static uint MAX_PRIMS = 1; 39 40[outputtopology("triangle")] 41[numthreads(3, 1, 1)] 42void main( 43 in uint tig : SV_GroupIndex, 44 OutputVertices<Vertex, MAX_VERTS> verts, 45 OutputIndices<uint3, MAX_PRIMS> triangles 46 ) 47{ 48 const uint numVertices = 3; 49 const uint numPrimitives = 1; 50 SetMeshOutputCounts(numVertices, numPrimitives); 51 52 if(tig < numVertices) { 53 verts[tig] = {float4(positions[tig], 0, 1), colors[tig]}; 54 } 55 56 if(tig < numPrimitives) { 57 triangles[tig] = uint3(0,1,2); 58 } 59} 60