yum-mirror/slang

Making it easier to work with shaders

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

Tim FoleyRemove support for explicit register/binding syntax on TEST_INPUT (#1132)2ea64ff4f

master
2.0 KiB111 linesraw
1//TEST:CPP_COMPILER_COMPILE: -profile cs_5_0 -entry computeMain -target callable
2
3enum Color
4{
5    Red,
6    Green = 2,
7    Blue,
8}
9
10int test(int val)
11{
12    Color c = Color.Red;
13
14    if(val > 1)
15    {
16        c = Color.Green;
17    }
18
19    if(c == Color.Red)
20    {
21        if(val & 1)
22        {
23            c = Color.Blue;
24        }
25    }
26
27    switch(c)
28    {
29    case Color.Red:
30        val = 1;
31        break;
32
33    case Color.Green:
34        val = 2;
35        break;
36
37    case Color.Blue:
38        val = 3;
39        break;
40
41    default:
42        val = -1;
43        break;
44    }
45
46    return (val << 4) + int(c);
47}
48
49float sum(float a[3])
50{
51    float total = a[0];
52    for (int i = 1; i < 3; ++i)
53    {
54        total += a[i];
55    }
56    return total;
57}
58
59struct Thing
60{
61    int a;
62    float b;
63};
64
65//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out
66RWStructuredBuffer<int> outputBuffer;
67
68RWStructuredBuffer<int> outputBuffer2;
69
70
71[numthreads(4, 1, 1)]
72void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
73{
74    uint tid = dispatchThreadID.x;
75
76    Thing thing = { 10, -1.0 };
77
78    float array[3] = { thing.a, 2, 3};
79
80    float anotherArray[] = { 1, 2, 5 };
81
82    array[0] += anotherArray[1];
83
84    matrix<float, 2, 3> mat = { { sum(array), 1, 2 }, { 3, 4, 5} };
85    vector<float, 2> vec = { float(tid + 1), float(tid + 2) };
86
87
88    vector<float, 3> vec2 = max(sin(mul(vec, mat)), float3(1, 2, -1));
89    vector<float, 3> vec3 = mul(vec, mat);
90    
91    float3 vec4 = lerp(vec2, vec3, float3(tid * (1.0f / 4), 1, 1));
92    
93    float3 crossVec = normalize(cross(vec4, vec4));
94    
95    vec2.x = fmod(crossVec.y, crossVec.x);
96    
97    vec2 = fmod(vec2, crossVec);
98    
99    vec2 += (-vec2.zyx) * 2 + crossVec * length(crossVec) + reflect(vec4, normalize(crossVec));
100    
101    vector<bool, 3> z = vec2 > 0;
102
103    int val = (int(tid) + (any(z) ? 1 : 0) + (all(z) ? 2 : 0)) % 100;
104    
105    val = asint(asfloat(asuint(asfloat(val))));
106    
107    val = test(val);
108
109    outputBuffer[tid] = val + int(dot(vec2, vec4));
110    outputBuffer2[tid] = int(tid);
111}