forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroupshared.slang
41 lines (32 loc) · 966 Bytes
/
groupshared.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
// groupshared.slang
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out, name=gBuffer
RWStructuredBuffer<int> gBuffer;
static const int A = 4;
static const int B = 1;
static const int THREAD_COUNT = A * B;
groupshared int gA[THREAD_COUNT];
int test(int val)
{
gA[val] = val;
GroupMemoryBarrierWithGroupSync();
val = gA[val ^ 1];
/* TODO: once function-scope `static` works
static groupshared int gB[THREAD_COUNT];
gB[val] = val;
GroupMemoryBarrierWithGroupSync();
val = gB[val ^ 2];
*/
return val;
}
[numthreads(THREAD_COUNT, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
uint tid = dispatchThreadID.x;
int val = int(tid);
val = test(val);
gBuffer[tid] = val;
}