yum-mirror/slang

Making it easier to work with shaders

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

Yong HeWarning on lossy implicit casts. (#2367)adaea0e99

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