From d58243d9041947c99f18b82385e62c082507decb Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Sat, 17 May 2025 02:26:44 +0000 Subject: Support Vulkan memory model (#7057) The user can explicitly use Vulkan memory model, or it will be automatically used when cooperative-matrix is used. When vulkan memory model is used, two keywords, "Coherent" and "Volatile", are not allowed. There are many differences regarding atomic and texture but this PR has changes limited to support `globallycoherent` keyword. When variables with `globallycoherent` is used with `OpLoad`, it will use additional options, `MakePointerAvailable|NonPrivatePointer`, that will provide the same effect. For `OpStore`, it will use `MakePointerVisible|NonPrivatePointer`. --- tests/spirv/coherent-2.slang | 3 +++ tests/spirv/coherent-texture.slang | 24 ++++++++++++++++++++++++ tests/spirv/coherent.slang | 2 ++ 3 files changed, 29 insertions(+) create mode 100644 tests/spirv/coherent-texture.slang (limited to 'tests/spirv') diff --git a/tests/spirv/coherent-2.slang b/tests/spirv/coherent-2.slang index 425ca0fe1..d68b38ad0 100644 --- a/tests/spirv/coherent-2.slang +++ b/tests/spirv/coherent-2.slang @@ -1,6 +1,7 @@ // Test that globallycoherent works on arrays of uavs. //TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry main -emit-spirv-directly +//TEST:SIMPLE(filecheck=VK_MEM_MODEL): -target spirv -stage compute -entry main -emit-spirv-directly -capability vk_mem_model globallycoherent RWByteAddressBuffer buffer[]; @@ -14,4 +15,6 @@ void main(int tid : SV_DispatchThreadID) // CHECK-DAG: OpDecorate %buffer Coherent // CHECK-DAG: OpDecorate %[[VAR1:[a-zA-Z0-9_]+]] NonUniform // CHECK: %[[VAR1]] = OpAccessChain %{{.*}} %buffer + + //VK_MEM_MODEL: OpLoad {{.*}} MakePointerVisible|NonPrivatePointer } diff --git a/tests/spirv/coherent-texture.slang b/tests/spirv/coherent-texture.slang new file mode 100644 index 000000000..ab1ce260f --- /dev/null +++ b/tests/spirv/coherent-texture.slang @@ -0,0 +1,24 @@ +//TEST:SIMPLE(filecheck=SPIRV): -target spirv-asm -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=VK_MEM_MODEL): -target spirv-asm -entry computeMain -stage compute -capability vk_mem_model + +//SPIRV: OpDecorate {{.*}} Coherent + +//VK_MEM_MODEL-NOT: OpDecorate {{.*}} Coherent +//VK_MEM_MODEL: OpImageRead %{{.*}} MakeTexelVisible|NonPrivateTexel % +//VK_MEM_MODEL: OpImageWrite %{{.*}} MakeTexelAvailable|NonPrivateTexel % +//VK_MEM_MODEL: OpImageRead %{{.*}} MakeTexelVisible|NonPrivateTexel % +//VK_MEM_MODEL: OpImageWrite %{{.*}} MakeTexelAvailable|NonPrivateTexel % + +globallycoherent +RWTexture2D outputTexture2D; + +[numthreads(1,1,1)] +void computeMain() +{ + // This line issues kIROp_ImageLoad/Store + outputTexture2D[0].xz = outputTexture2D[0].yw; + + // The current implementation uses spirv_asm for subscription, + // which goes through a different part of implementation in slang-emit-spirv.cpp. + outputTexture2D[uint2(0,0)] = outputTexture2D[uint2(1,1)]; +} diff --git a/tests/spirv/coherent.slang b/tests/spirv/coherent.slang index ba58b713b..33a559700 100644 --- a/tests/spirv/coherent.slang +++ b/tests/spirv/coherent.slang @@ -1,6 +1,7 @@ // Test that globallycoherent works. //TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry main -emit-spirv-directly +//TEST:SIMPLE(filecheck=VK_MEM_MODEL): -target spirv -stage compute -entry main -emit-spirv-directly -capability vk_mem_model struct S { @@ -17,4 +18,5 @@ void main(int tid : SV_DispatchThreadID) output[tid] = buffer[0].member; // CHECK-DAG: OpMemberDecorate {{.*}} 0 Coherent // CHECK-DAG: OpDecorate %buffer Coherent + // VK_MEM_MODEL: OpLoad {{.*}} MakePointerVisible|NonPrivatePointer } -- cgit v1.2.3