Closed chaoticbob closed 3 weeks ago
I have a question about the suggestion:
I am assuming register
syntax means only: register(slot, space)
, example: Texture2D<float4> v : register(slot, space);
and not including: register(profile, slot)
, example: Texture2D<float4> v : register(cs_6_0, t0) : register( ps_6_0, t0) : register(gs_5_0, t99);
?
(Texture2D<float4> v : register(cs_6_0, t0) : register(ps_6_0, t0) : register(gs_5_0, t99);
is 'supported' but is non functional in DXC)
Yes, that's right: register(slot, space)
where slot
is come combination of the resource type and register index and space
is just spaceN
where N
is the space index.
I've never used the register(profile, slot)
variation. I think I've only seen it in older shader code.
I don't think this compiler option exists, I wasn't able to find anything in the help for it. If it does exist please let me know what the option is.
Currently, when compiling for to SPIR-V for Vulkan, Slang does not support resource declaration using
register(X, [Y])
where X is the binding number and Y is the set number. Slang requires the usage of[[vk::binding(X, [Y])]]
to specify the binding and set numbers. If[[vk::binding()]]
is absent andregister()
is present, the behavior I've observed is thatregister()
is ignored (with a warning) and resource binding numbers are auto assigned based on declaration order.The current behavior might unexpected for some users. It's understandable that Slang wants users to be deliberate with the usage of
[[vk::binding()]]
but it's really inconvenient having to add that decoration to every shader resource in shader source that' shared between Vulkan and other graphics APIs. In cases where the same values are used forregister()
and [[vk::binding()]]` it's just the same information that's duplicated...and if incorrectly duplicated could lead to some really annoying bugs to track down.Additionally, for some users it may be non-obvious that having only
register()
won't do the thing they're expecting and instead binding numbers will be auto assigned. This can easily produce a mismatch between the shader and the graphics API that results in a device lost. For example the snippet below where the register binding numbers are all over the place and auto assignment would just assigns based on declaration order, see spirv-reflect output below.I think having something like
-fvk-allow-register-bindings
that allowsregister(X, [Y])
for binding and set if[[vk::binding(X, [Y])]]
isn't present would make shader source sharing much easier and reduce the barrier to entry for on-ramping.Shader snippet:
SPIRV-Reflect of resources of above shader snippet - binding numbers are auto assigned.