forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstk-chk.slang
55 lines (42 loc) · 1.12 KB
/
stk-chk.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
//TEST(compute):COMPARE_COMPUTE:-cpu -g0
// Tests slang-llvm can deal with large items on stack.
// On some targets this requires special handling (_chkstk on windows for example)
struct LargeStruct
{
int values[4096];
};
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;
//TEST_INPUT:ubuffer(data=[9 1000 27 34], stride=4):name inputBuffer
StructuredBuffer<int> inputBuffer;
LargeStruct _calcStruct(int a)
{
LargeStruct s;
int t = a;
for (int i = 0; i < 4096; ++i)
{
s.values[i] = t;
// Munge
t = t ^ (i * t) + (i - a) * 17 + inputBuffer[t & 3];
}
return s;
}
int _calcValue(LargeStruct s)
{
int v = 0;
for (int i = 0; i < 4096; ++i)
{
v ^= s.values[i];
}
return v + 1;
}
int _calc1(int a)
{
return _calcValue(_calcStruct(_calcValue(_calcStruct(_calcValue(_calcStruct(a ^ 19))))));
}
[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
int index = int(dispatchThreadID.x);
outputBuffer[index] = _calc1(index) + 1;
}