yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
2.0 KiB87 linesraw
1//T-EST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mesh -output-using-type -dx12 -profile sm_6_6 -render-features mesh-shader
2//T-EST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mesh -output-using-type -vk -render-features mesh-shader
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mesh -output-using-type -vk -profile sm_6_5 -render-features mesh-shader
4
5// To test a simple mesh shader, we'll generate 4 triangles, the vertices of
6// each one will hold the triangle index and a value (the square). The fragment
7// shader will write the value to the specified index of the output buffer.
8
9// CHECK:      0
10// CHECK-NEXT: 1
11// CHECK-NEXT: 4
12// CHECK-NEXT: 9
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// Mesh shader
25//
26
27const static float2 positions[3] = {
28  float2(0.0, -0.5),
29  float2(0.5, 0.5),
30  float2(-0.5, 0.5)
31};
32
33const static float3 colors[3] = {
34  float3(1.0, 1.0, 0.0),
35  float3(0.0, 1.0, 1.0),
36  float3(1.0, 0.0, 1.0)
37};
38
39struct Vertex
40{
41  float4 pos : SV_Position;
42  float3 color : Color;
43  int index : Index;
44  int value : Value;
45};
46
47const static uint MAX_VERTS = 12;
48const static uint MAX_PRIMS = 4;
49
50[outputtopology("triangle")]
51[numthreads(12, 1, 1)]
52void meshMain(
53    in uint tig : SV_GroupIndex,
54    OutputVertices<Vertex, MAX_VERTS> verts,
55    OutputIndices<uint3, MAX_PRIMS> triangles)
56{
57    const uint numVertices = 12;
58    const uint numPrimitives = 4;
59    SetMeshOutputCounts(numVertices, numPrimitives);
60
61    if(tig < numVertices)
62    {
63        const int tri = tig / 3;
64        verts[tig] = {float4(positions[tig % 3], 0, 1), colors[tig % 3], tri, tri*tri};
65    }
66
67    if(tig < numPrimitives)
68        triangles[tig] = tig * 3 + uint3(0,1,2);
69}
70
71//
72// Fragment Shader
73//
74
75struct Fragment
76{
77    float4 color : SV_Target;
78};
79
80Fragment fragmentMain(Vertex input)
81{
82	outputBuffer[input.index] = input.value;
83
84	Fragment output;
85	output.color = float4(input.color, 1.0);
86	return output;
87}