yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
1e0908bd7
master
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 -output-using-type 3 4// Tests if we optimize redundant load's correctly 5 6//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer 7RWStructuredBuffer<int> outputBuffer; 8//TEST_INPUT:ubuffer(data=[0 0 0 11 10], stride=4),name=buffer 9uniform int* buffer; 10 11[numthreads(2, 1, 1)] 12void computeMain(uint3 group_thread_id: SV_GroupThreadID) 13{ 14 Ptr<int, Access::ReadWrite, AddressSpace::Device> ptr = __getAddress(buffer[0]); 15 16 // Consider the load from this store-load pattern as redundant since 17 // the load is a sub-set memory-scope of the memory-scope of the store. 18 // Invocation == Invocation. 19 *ptr = 8; 20 outputBuffer[0] = loadCoherent<4, MemoryScope::Invocation>(ptr); 21 // CHECK: 8 22 // SPIRV: OpStore %ptr %int_8 23 // SPIRV-NOT: OpLoad 24 // SPIRV: %[[#OUTPUT_BUFFER1:]] = OpAccessChain {{.*}} %outputBuffer %{{.*}} %int_0 25 // SPIRV: OpStore %[[#OUTPUT_BUFFER1]] %int_8 26 27 // Consider the load from this store-load pattern as redundant since 28 // the load is a sub-set memory-scope of the memory-scope of the store. 29 // Device > Workgroup. 30 let offset1 = ptr + 1; 31 storeCoherent<4, MemoryScope::Device>(offset1, 9); 32 outputBuffer[1] = loadCoherent<4, MemoryScope::Workgroup>(offset1); 33 // CHECK-NEXT: 9 34 // SPIRV: %[[#PTR_OFFSET:]] = OpPtrAccessChain {{.*}} %ptr %int_1 35 // SPIRV: OpStore %[[#PTR_OFFSET]] %int_9 36 // SPIRV-NOT: OpLoad 37 // SPIRV: %[[#OUTPUT_BUFFER2:]] = OpAccessChain {{.*}} %outputBuffer %{{.*}} %int_1 38 // SPIRV: OpStore %[[#OUTPUT_BUFFER2]] %int_9 39 40 // Consider the following store-load pattern as not redundant since the data stored 41 // may not be the same data that will be loaded if Workgroup-scope contains 42 // different data than the Subgroup-scope. 43 // Subgroup < Workgroup. 44 let offset2 = ptr + 2; 45 storeCoherent<4, MemoryScope::Subgroup>(offset2, buffer[3]); 46 if(group_thread_id.x == 1) 47 { 48 storeCoherent<4, MemoryScope::Invocation>(offset2, buffer[4]); 49 let result = loadCoherent<4, MemoryScope::Workgroup>(offset2); 50 outputBuffer[2] = (result == 11 || result == 10) ? 12 : 0; 51 } 52 // CHECK-NEXT: 12 53 // SPIRV: OpStore {{.*}}MakePointerAvailable{{.*}} 4 %int_3 54 // SPIRV: OpStore {{.*}}MakePointerAvailable{{.*}} 4 %int_4 55 // SPIRV: OpLoad {{.*}}MakePointerVisible{{.*}} 4 %int_2 56}