From 0b5190226b3061597f0fd88ca6b1f304f2c6af38 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:44:33 -0400 Subject: fix `WorkgroupSize()` compiler failiure (#4505) in some cases was not destroying the hoisted to global `WorkgroupSize()` function removed capability requirement on `gl_WorkGroupSize` since no longer appies (kIROp of `WorkgroupSize` is implemented for all targets) change when destroying inst --- source/slang/glsl.meta.slang | 2 +- .../slang/slang-ir-translate-glsl-global-var.cpp | 3 +++ tests/bugs/gh-4504.slang | 23 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/bugs/gh-4504.slang diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 85d39493b..cf314fcdc 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -126,7 +126,7 @@ public property uint3 gl_NumWorkGroups { public property uint3 gl_WorkGroupSize { [__unsafeForceInlineEarly] - [require(glsl_spirv, GLSL_430_SPIRV_1_0_compute)] + [require(compute)] get { return WorkgroupSize(); diff --git a/source/slang/slang-ir-translate-glsl-global-var.cpp b/source/slang/slang-ir-translate-glsl-global-var.cpp index 42e70ac78..8cb7fa8e9 100644 --- a/source/slang/slang-ir-translate-glsl-global-var.cpp +++ b/source/slang/slang-ir-translate-glsl-global-var.cpp @@ -262,7 +262,10 @@ namespace Slang // We need to introduce a global variable and assign value to it in each entry point. if (!workgroupSizeInst->hasUses()) + { + workgroupSizeInst->removeAndDeallocate(); return; + } builder.setInsertBefore(workgroupSizeInst); auto globalVar = builder.createGlobalVar(workgroupSizeInst->getFullType()); diff --git a/tests/bugs/gh-4504.slang b/tests/bugs/gh-4504.slang new file mode 100644 index 000000000..d6fc28e0c --- /dev/null +++ b/tests/bugs/gh-4504.slang @@ -0,0 +1,23 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -dx12 -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -glsl -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +// note: `WorkgroupSize()` resolves into a compile time constant, +// it is possible `size.x == 5` and others will resolve into `true` +// at compile time. A compute test is required. +[shader("compute")] +[numthreads(5, 2, 1)] +void computeMain(uint3 threadId: SV_DispatchThreadID) +{ + // CHECK: 1 + int3 size = WorkgroupSize(); + outputBuffer[0] = true + && size.x == 5 + && size.y == 2 + && size.z == 1 + ; +} \ No newline at end of file -- cgit v1.2.3