summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2024-10-08 15:41:51 +0300
committerGitHub <noreply@github.com>2024-10-08 15:41:51 +0300
commit842dee3b6b62c7eb37134e3e27b2ebebdde99b42 (patch)
treecf377b9a0f0dc913087af44407d5118fa17b2005
parent3de8afe1687b164a1bb8116d8301d427e699abc2 (diff)
WGSL emitter: Specify private address space for global non-handle variable declarations (#5236)
Closes issue #5229.
-rw-r--r--source/slang/slang-emit-wgsl.cpp15
-rw-r--r--tests/compute/parameter-block.slang1
2 files changed, 15 insertions, 1 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp
index 66e802571..a05e03afc 100644
--- a/source/slang/slang-emit-wgsl.cpp
+++ b/source/slang/slang-emit-wgsl.cpp
@@ -602,6 +602,21 @@ void WGSLSourceEmitter::emitVarKeywordImpl(IRType * type, IRInst* varDecl)
m_writer->emit("storage, read");
m_writer->emit(">");
}
+ else if(varDecl->getOp() == kIROp_GlobalVar)
+ {
+ // Global ("module-scope") non-handle variables need to specify storage space
+
+ // https://www.w3.org/TR/WGSL/#var-decls
+ // "
+ // Variables in the private, storage, uniform, workgroup, and handle address
+ // spaces must only be declared in module scope, while variables in the function
+ // address space must only be declared in function scope. The address space must
+ // be specified for all address spaces except handle and function. The handle
+ // address space must not be specified. Specifying the function address space is
+ // optional.
+ // "
+ m_writer->emit("<private>");
+ }
}
void WGSLSourceEmitter::_emitType(IRType* type, DeclaratorInfo* declarator)
diff --git a/tests/compute/parameter-block.slang b/tests/compute/parameter-block.slang
index baa420665..2922f0813 100644
--- a/tests/compute/parameter-block.slang
+++ b/tests/compute/parameter-block.slang
@@ -3,7 +3,6 @@
//TEST(compute):COMPARE_COMPUTE:-vk -shaderobj
//TEST(compute):COMPARE_COMPUTE:-shaderobj
//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl -render-features argument-buffer-tier-2
-//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -wgpu
// Ensure that Slang `ParameterBlock` type is lowered
// to HLSL in the fashion that we expect.