yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -task -output-using-type -dx12 -profile sm_6_6 -render-features mesh-shader 2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -task -output-using-type -vk -profile sm_6_5 -render-features mesh-shader 3 4// Similar to task-simple, except that the payload is declared as a groupshared 5// variable. During lowerin to GLSL and SPIR-V we'll have to identify this as 6// the variable being passed to DispatchMesh and emit it using the 7// taskPayloadSharedEXT rate. 8 9// CHECK: 0 10// CHECK-NEXT: 1 11// CHECK-NEXT: 8 12// CHECK-NEXT: 27 13 14//TEST_INPUT: ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 15 16RWStructuredBuffer<float> outputBuffer; 17 18cbuffer Uniforms 19{ 20 float4x4 modelViewProjection; 21} 22 23// 24// Task shader 25// 26 27struct MeshPayload 28{ 29 int exponent; 30}; 31 32groupshared MeshPayload p; 33 34[numthreads(1, 1, 1)] 35[shader("amplification")] 36void taskMain(in uint tig : SV_GroupIndex) 37{ 38 p.exponent = 3; 39 DispatchMesh(1,1,1,p); 40} 41 42 43// 44// Mesh shader 45// 46 47const static float2 positions[3] = { 48 float2(0.0, -0.5), 49 float2(0.5, 0.5), 50 float2(-0.5, 0.5) 51}; 52 53const static float3 colors[3] = { 54 float3(1.0, 1.0, 0.0), 55 float3(0.0, 1.0, 1.0), 56 float3(1.0, 0.0, 1.0) 57}; 58 59struct Vertex 60{ 61 float4 pos : SV_Position; 62 float3 color : Color; 63 int index : Index; 64 int value : Value; 65}; 66 67const static uint MAX_VERTS = 12; 68const static uint MAX_PRIMS = 4; 69 70[outputtopology("triangle")] 71[numthreads(12, 1, 1)] 72void meshMain( 73 in uint tig : SV_GroupIndex, 74 in payload MeshPayload meshPayload, 75 OutputVertices<Vertex, MAX_VERTS> verts, 76 OutputIndices<uint3, MAX_PRIMS> triangles) 77{ 78 const uint numVertices = 12; 79 const uint numPrimitives = 4; 80 SetMeshOutputCounts(numVertices, numPrimitives); 81 82 if(tig < numVertices) 83 { 84 const int tri = tig / 3; 85 verts[tig] = {float4(positions[tig % 3], 0, 1), colors[tig % 3], tri, int(pow(tri, meshPayload.exponent))}; 86 } 87 88 if(tig < numPrimitives) 89 triangles[tig] = tig * 3 + uint3(0,1,2); 90} 91 92// 93// Fragment Shader 94// 95 96struct Fragment 97{ 98 float4 color : SV_Target; 99}; 100 101Fragment fragmentMain(Vertex input) 102{ 103 outputBuffer[input.index] = input.value; 104 105 Fragment output; 106 output.color = float4(input.color, 1.0); 107 return output; 108} 109