diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-31 17:47:20 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-01 01:47:20 +0000 |
| commit | 075e6c25826cd0a1df26bd36af4afe865673a790 (patch) | |
| tree | 9df1cd4bcc33025dc6249a806e10e303ec0940b6 | |
| parent | 823b6a84a0252c2977699d64334dadbcb47683bd (diff) | |
Fix reflection for metal vector [[id]] location. (#5943)
| -rw-r--r-- | source/slang/slang-type-layout.cpp | 13 | ||||
| -rw-r--r-- | tests/metal/vector-argument-buffer-layout.slang | 18 |
2 files changed, 31 insertions, 0 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index c6acf5250..98a324d96 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1898,6 +1898,19 @@ struct MetalArgumentBufferElementLayoutRulesImpl : ObjectLayoutRulesImpl, Defaul return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 1); } + SimpleLayoutInfo GetVectorLayout( + BaseType elementType, + SimpleLayoutInfo elementInfo, + size_t elementCount) override + { + SLANG_UNUSED(elementType); + SLANG_UNUSED(elementInfo); + SLANG_UNUSED(elementCount); + + // A vector occupies one [[id]] slot in a metal argument buffer. + return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 1); + } + virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override { diff --git a/tests/metal/vector-argument-buffer-layout.slang b/tests/metal/vector-argument-buffer-layout.slang new file mode 100644 index 000000000..698fd30d8 --- /dev/null +++ b/tests/metal/vector-argument-buffer-layout.slang @@ -0,0 +1,18 @@ +//TEST:REFLECTION(filecheck=CHECK): -target metal +//CHECK: "binding": {"kind": "metalArgumentBufferElement", "index": 0} +//CHECK: "binding": {"kind": "metalArgumentBufferElement", "index": 1} + +struct Params +{ + float3 dir; + float4 color; +} + +RWStructuredBuffer<float> o; +ParameterBlock<Params> gParams; + +[numthreads(1,1,1)] +void computeMain() +{ + o[0] = gParams.dir.x; +}
\ No newline at end of file |
