diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-18 15:34:52 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-18 15:34:52 -0800 |
| commit | abeb3758f35a48c2012dd3c39d704409c679a652 (patch) | |
| tree | c26e8e0c88ab0b1d60c78a4b764b8a891bb37cf2 | |
| parent | 0f5a2ce2ecf79fba79a9d20c9e3bcd4c31ee45bb (diff) | |
Support explicit `[vk::location(n)]` binding on metal/wgsl. (#5907)
| -rw-r--r-- | docs/user-guide/a2-02-metal-target-specific.md | 2 | ||||
| -rw-r--r-- | docs/user-guide/a2-03-wgsl-target-specific.md | 2 | ||||
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 3 | ||||
| -rw-r--r-- | tests/metal/explicit-location.slang | 17 |
4 files changed, 23 insertions, 1 deletions
diff --git a/docs/user-guide/a2-02-metal-target-specific.md b/docs/user-guide/a2-02-metal-target-specific.md index e2602eb77..f63b985b5 100644 --- a/docs/user-guide/a2-02-metal-target-specific.md +++ b/docs/user-guide/a2-02-metal-target-specific.md @@ -276,6 +276,8 @@ Since metal does not differentiate a constant buffer, a shader resource (read-on `spaceN` specifiers inside `register` semantics are ignored. +The `[vk::location(N)]` attributes on stage input/output parameters are respected. + ## Specialization Constants Specialization constants declared with the `[SpecializationConstant]` or `[vk::constant_id]` attribute will be translated into a `function_constant` when generating Metal source. diff --git a/docs/user-guide/a2-03-wgsl-target-specific.md b/docs/user-guide/a2-03-wgsl-target-specific.md index 743928a5f..b88c28648 100644 --- a/docs/user-guide/a2-03-wgsl-target-specific.md +++ b/docs/user-guide/a2-03-wgsl-target-specific.md @@ -163,6 +163,8 @@ The `[vk::binding(index,set)]` attribute is respected when emitting WGSL code, a If the `[vk::binding()]` attribute is not specified by a `:register()` semantic is present, Slang will derive the binding from the `register` semantic the same way as the SPIRV and GLSL backends. +The `[vk::location(N)]` attributes on stage input/output parameters are respected. + ## Specialization Constants Specialization constants declared with the `[SpecializationConstant]` or `[vk::constant_id]` attribute will be translated into a global `override` declaration when generating WGSL source. diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 33fa24f11..825e0f4af 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -1909,7 +1909,8 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameterDecl( // `location`s in declaration order coincidentally matches // the `SV_Target` order. // - if (isKhronosTarget(context->getTargetRequest())) + if (isKhronosTarget(context->getTargetRequest()) || + isMetalTarget(context->getTargetRequest()) || isWGPUTarget(context->getTargetRequest())) { if (auto locationAttr = decl->findModifier<GLSLLocationAttribute>()) { diff --git a/tests/metal/explicit-location.slang b/tests/metal/explicit-location.slang new file mode 100644 index 000000000..35930cfce --- /dev/null +++ b/tests/metal/explicit-location.slang @@ -0,0 +1,17 @@ +//TEST:SIMPLE(filecheck=MTL): -target metal +//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry vertMain -stage vertex + +// MTL: attribute(3) +// WGSL: @location(3) + +struct Vertex +{ + [vk::location(0)] float4 pos; + [vk::location(3)] float2 uv; +} + +[shader("vertex")] +float4 vertMain(Vertex vin) : SV_Position +{ + return vin.pos + vin.uv.x; +}
\ No newline at end of file |
