Skip to content

Commit abeb375

Browse files
authored
Support explicit [vk::location(n)] binding on metal/wgsl. (#5907)
1 parent 0f5a2ce commit abeb375

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

docs/user-guide/a2-02-metal-target-specific.md

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ Since metal does not differentiate a constant buffer, a shader resource (read-on
276276

277277
`spaceN` specifiers inside `register` semantics are ignored.
278278

279+
The `[vk::location(N)]` attributes on stage input/output parameters are respected.
280+
279281
## Specialization Constants
280282

281283
Specialization constants declared with the `[SpecializationConstant]` or `[vk::constant_id]` attribute will be translated into a `function_constant` when generating Metal source.

docs/user-guide/a2-03-wgsl-target-specific.md

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ The `[vk::binding(index,set)]` attribute is respected when emitting WGSL code, a
163163

164164
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.
165165

166+
The `[vk::location(N)]` attributes on stage input/output parameters are respected.
167+
166168
## Specialization Constants
167169

168170
Specialization constants declared with the `[SpecializationConstant]` or `[vk::constant_id]` attribute will be translated into a global `override` declaration when generating WGSL source.

source/slang/slang-parameter-binding.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,8 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameterDecl(
19091909
// `location`s in declaration order coincidentally matches
19101910
// the `SV_Target` order.
19111911
//
1912-
if (isKhronosTarget(context->getTargetRequest()))
1912+
if (isKhronosTarget(context->getTargetRequest()) ||
1913+
isMetalTarget(context->getTargetRequest()) || isWGPUTarget(context->getTargetRequest()))
19131914
{
19141915
if (auto locationAttr = decl->findModifier<GLSLLocationAttribute>())
19151916
{

tests/metal/explicit-location.slang

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//TEST:SIMPLE(filecheck=MTL): -target metal
2+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry vertMain -stage vertex
3+
4+
// MTL: attribute(3)
5+
// WGSL: @location(3)
6+
7+
struct Vertex
8+
{
9+
[vk::location(0)] float4 pos;
10+
[vk::location(3)] float2 uv;
11+
}
12+
13+
[shader("vertex")]
14+
float4 vertMain(Vertex vin) : SV_Position
15+
{
16+
return vin.pos + vin.uv.x;
17+
}

0 commit comments

Comments
 (0)