forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope-operator.slang
78 lines (62 loc) · 1.22 KB
/
scope-operator.slang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// scope.slang
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
// Confirm that scoping on enums and types works
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;
enum Color
{
Red,
Green = 2,
Blue,
}
struct Thing
{
int a;
struct Another
{
int b;
}
};
int test(int val)
{
Color c = Color.Red;
Thing::Another another;
another.b = 20;
if(val > 1)
{
c = Color.Green;
}
if(c == Color::Red)
{
if((val & 1) != 0)
{
c = Color::Blue;
}
}
switch(c)
{
case Color::Red:
val = 1;
break;
case Color::Green:
val = 2;
break;
case Color::Blue:
val = 3;
break;
default:
val = -1;
break;
}
return (val << 4) + int(c) + another.b - 20;
}
[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
uint tid = dispatchThreadID.x;
int val = int(tid);
val = test(val);
outputBuffer[tid] = val;
}