yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
8086adc90
master
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mesh -output-using-type -dx12 -profile sm_6_6 -render-features mesh-shader 2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mesh -output-using-type -vk -profile sm_6_5 -render-features mesh-shader 3//TEST(compute, metal):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mesh -output-using-type -metal -render-features mesh-shader 4 5// See https://github.com/shader-slang/slang/issues/3401 6 7// CHECK: 0 8// CHECK-NEXT: 1 9// CHECK-NEXT: 4 10// CHECK-NEXT: 9 11 12//TEST_INPUT: ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 13 14RWStructuredBuffer<float> outputBuffer; 15 16cbuffer Uniforms 17{ 18 float4x4 modelViewProjection; 19} 20 21const static float2 positions[3] = { 22 float2(0.0, -0.5), 23 float2(0.5, 0.5), 24 float2(-0.5, 0.5) 25}; 26 27const static float3 colors[3] = { 28 float3(1.0, 1.0, 0.0), 29 float3(0.0, 1.0, 1.0), 30 float3(1.0, 0.0, 1.0) 31}; 32struct Vertex 33{ 34 float4 pos : SV_Position; 35 float3 color : Color; 36 int index : Index; 37 int value : Value; 38}; 39 40const static uint MAX_VERTS = 12; 41const static uint MAX_PRIMS = 4; 42 43[outputtopology("triangle")] 44[shader("mesh")] 45[numthreads(3, 1, 1)] 46void meshMain( 47 in uint tig : SV_GroupIndex, 48 OutputVertices<Vertex, MAX_VERTS> verts, 49 OutputIndices<uint3, MAX_PRIMS> triangles) 50{ 51 const uint numVertices = 12; 52 const uint numPrimitives = 4; 53 SetMeshOutputCounts(numVertices, numPrimitives); 54 55 for(uint i = tig; i < numVertices; ++i) 56 { 57 const int tri = i / 3; 58 verts[i] = {float4(positions[i % 3], 0, 1), colors[i % 3], tri, tri*tri}; 59 } 60 61 for(uint i = tig; i < numPrimitives; ++i) 62 { 63 triangles[i] = i * 3 + uint3(0,1,2); 64 } 65} 66 67// 68// Fragment Shader 69// 70 71struct Fragment 72{ 73 float4 color : SV_Target; 74}; 75 76Fragment fragmentMain(Vertex input) 77{ 78 outputBuffer[input.index] = input.value; 79 80 Fragment output; 81 output.color = float4(input.color, 1.0); 82 return output; 83}