From 1e0908bd7107dfbdac912b693c3ab9bd6e1dc8b3 Mon Sep 17 00:00:00 2001 From: 16-Bit-Dog <67922228+16-Bit-Dog@users.noreply.github.com> Date: Fri, 10 Oct 2025 13:09:24 -0400 Subject: Addition of `Load`/`Store` coherent operations (#8395) Fixes: https://github.com/shader-slang/slang/issues/7634 Duplicate of PR https://github.com/shader-slang/slang/pull/8052 Primary Changes: * Added `storeCoherent` and `loadCoherent` for coherent load/store via pointers. This is backed by `IRMemoryScopeAttr` which is an `IRAttr` attached to `IRLoad` and `IRStore` * Logic in `source\slang\slang-emit-spirv.cpp` for load/store emitting has been reworked to be less messy and more maintainable * Add to `hlsl.meta.slang` coop vector and coop matrix coherent load/store operations Secondary Changes: * Added a missing load/store test for coop matrix: `tests\cooperative-matrix\load-store-pointer.slang` --------- Co-authored-by: ArielG-NV Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Nathan V. Morrical --- .../coherent-load-store-pointer.slang | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/cooperative-vector/coherent-load-store-pointer.slang (limited to 'tests/cooperative-vector') diff --git a/tests/cooperative-vector/coherent-load-store-pointer.slang b/tests/cooperative-vector/coherent-load-store-pointer.slang new file mode 100644 index 000000000..40efeee1a --- /dev/null +++ b/tests/cooperative-vector/coherent-load-store-pointer.slang @@ -0,0 +1,38 @@ +//TEST:SIMPLE(filecheck=SPIRV):-stage compute -entry computeMain -target spirv + +// coherent CoopVec operations crash the Nvidia driver. +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -render-feature cooperative-vector -emit-spirv-directly + +// Ensure SPIRV emits coherent operations here +// SPIRV: MakePointerVisible +// SPIRV: MakePointerAvailable + +//TEST_INPUT: set inputBuffer = ubuffer(data=[1 2 3 4 5 6 7 8 9 10 11 12], stride=4); +uniform int32_t* inputBuffer; + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0 0 0 0 0], stride=4); +uniform int32_t* outputBuffer; + +// CHECK: 9 +// CHECK-NEXT: A +// CHECK-NEXT: B +// CHECK-NEXT: C +// CHECK-NEXT: 1 +// CHECK-NEXT: 2 +// CHECK-NEXT: 3 +// CHECK-NEXT: 4 + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain() +{ + //// First half of input. + let a = coopVecLoadCoherent<4, int32_t>(inputBuffer, 0, MemoryScope::Device); + //// Second half of input. + let b = coopVecLoadCoherent<4, int32_t>(inputBuffer + 4, 4 * 4, MemoryScope::Device); + //// Store second half of input to first half of output buffer. + b.storeCoherent(outputBuffer, 0, MemoryScope::Device); + //// Store first half of input to second half of output buffer. + a.storeCoherent(outputBuffer, 4 * 4, MemoryScope::Device); +} + -- cgit v1.2.3