From 9b430a327dd3ea7b11db126d12df12a176e0161d Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 27 Sep 2024 16:57:53 -0700 Subject: [PATCH] Fix bug in `translateGlslGlobalVar()`. --- .../slang/slang-ir-translate-glsl-global-var.cpp | 7 +++++-- tests/bugs/gh-5027.slang | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/bugs/gh-5027.slang diff --git a/source/slang/slang-ir-translate-glsl-global-var.cpp b/source/slang/slang-ir-translate-glsl-global-var.cpp index 8cb7fa8e90..4b2196e379 100644 --- a/source/slang/slang-ir-translate-glsl-global-var.cpp +++ b/source/slang/slang-ir-translate-glsl-global-var.cpp @@ -17,6 +17,8 @@ namespace Slang buildEntryPointReferenceGraph(referencingEntryPoints, module); List entryPoints; + List getWorkGroupSizeInsts; + // Traverse the module to find all entry points. // If we see a `GetWorkGroupSize` instruction, we will materialize it. // @@ -25,9 +27,10 @@ namespace Slang if (inst->getOp() == kIROp_Func && inst->findDecoration()) entryPoints.add(inst); else if (inst->getOp() == kIROp_GetWorkGroupSize) - materializeGetWorkGroupSize(module, referencingEntryPoints, inst); + getWorkGroupSizeInsts.add(inst); } - + for (auto inst : getWorkGroupSizeInsts) + materializeGetWorkGroupSize(module, referencingEntryPoints, inst); IRBuilder builder(module); for (auto entryPoint : entryPoints) diff --git a/tests/bugs/gh-5027.slang b/tests/bugs/gh-5027.slang new file mode 100644 index 0000000000..ade58564bc --- /dev/null +++ b/tests/bugs/gh-5027.slang @@ -0,0 +1,16 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-d3d11 -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +in uint3 gid : SV_GroupID; + +[numthreads(1,1,1)] +void computeMain() +{ + uint expr = WorkgroupSize().x + gid.x; + // CHECK: type: uint32_t + // CHECK: 2 + outputBuffer[0] = expr + 1; +} \ No newline at end of file