yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiaInitial work around groupshared (#2224)117f5e554

master
748 B30 linesraw
1// rate-param.slang
2//DISABLE_TEST:SIMPLE: -target hlsl -entry computeMain -stage compute 
3
4//TEST_INPUT:ubuffer(data=[0 0 0 0 ], stride=4):out,name outputBuffer
5RWStructuredBuffer<int> outputBuffer;
6
7groupshared uint gs_values[4];
8
9void someFunction(inout groupshared uint a[4], int index, int value)
10{
11    a[index] += value;
12}
13
14[shader("compute")]
15[numthreads(4, 1, 1)]
16void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
17{
18    int index = (int)dispatchThreadID.x;
19       
20    // Initialize
21    gs_values[3 - index] = index;   
22       
23    GroupMemoryBarrierWithGroupSync();
24       
25    someFunction(gs_values, index, index * 2 + 1);
26       
27    GroupMemoryBarrierWithGroupSync();
28       
29    outputBuffer[index] = gs_values[index];
30}