yum-mirror/slang

Making it easier to work with shaders

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

16-Bit-DogAddition of `Load`/`Store` coherent operations (#8395)1e0908bd7

master
1.5 KiB40 linesraw
1//TEST:SIMPLE(filecheck=SPIRV):-stage compute -entry computeMain -target spirv -capability vk_mem_model
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -emit-spirv-directly -capability vk_mem_model
3
4// Tests if we optimize redundant store's correctly
5
6//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<int> outputBuffer;
8//TEST_INPUT:ubuffer(data=[0 0], stride=4),name=buffer
9uniform int* buffer;
10
11[numthreads(128, 1, 1)]
12void computeMain(uint3 group_thread_id: SV_GroupThreadID)
13{
14    Ptr<int, Access::ReadWrite, AddressSpace::Device> ptr = __getAddress(buffer[0]);
15    if (group_thread_id.x == 0)
16    {
17        // This store will not optimize out, Device > Invocation.
18        // SPIRV: OpStore %ptr %int_1
19        storeCoherent<4, MemoryScope::Device>(ptr, 1);
20        // SPIRV-NEXT: OpStore %ptr %int_2
21        storeCoherent<4, MemoryScope::Invocation>(ptr, 2);
22
23        // Both of these stores will optimize out, Subgroup > Invocation.
24        // SPIRV-NOT: OpStore {{.*}} %int_3
25        *(ptr + 1) = 3;
26        // SPIRV-NOT: OpStore {{.*}} %int_4
27        storeCoherent<4, MemoryScope::Invocation>(ptr + 1, 4);
28        // SPIRV: OpStore {{.*}} %int_5
29        storeCoherent<4, MemoryScope::Workgroup>(ptr + 1, 5);
30    }
31    AllMemoryBarrierWithGroupSync();
32    if (group_thread_id.x == 127)
33    {
34        // CHECK: 1
35        outputBuffer[0] = (*ptr == 1 || *ptr == 2) ? 1 : 0;
36
37        // CHECK-NEXT: 5
38        outputBuffer[1] = loadCoherent<4, MemoryScope::Workgroup>(ptr+1);
39    }
40}