Closed Ravbug closed 1 year ago
newBinding.desc_set = msl.get_decoration(resource.id, spv::Decoration::DecorationDescriptorSet);
You're not using newBinding.binding.
options.enable_decoration_binding = true;
Is not supposed to be used when you use explicit binding API.
The issue I'm running into is if I don't have options.enable_decoration_binding = true
, the texture indices are ordered by first use rather than by the order they are declared in the shader. Is there a way to ensure that the indices match the order the uniforms are listed in the GLSL? For example, if I have:
uniform sampler2D colorSampler;
uniform sampler2D normalSampler;
uniform sampler2D positionSampler;
I want the resulting Metal shader to have
fragment dirlight_frag_out dirlight_frag(texture2d<float> colorSampler [[texture(0)]], texture2d<float> normalSampler [[texture(1)]], texture2d<float> positionSampler [[texture(2)]], sampler colorSamplerSmplr [[sampler(0)]], sampler normalSamplerSmplr [[sampler(1)]], sampler positionSamplerSmplr [[sampler(2)]])
Resolved by setting explicit binding positions (binding = n) in the input shader.
I am trying to transpile this GLSL shader to MSL:
I am using the following code to do it:
However, this results in all textures and samplers being set to the same
[[texture(n)]]
and[[sampler(n)]]
(2):I noticed when stepping into
add_msl_resource_binding
thattuple
is always set to the same value, which results in only one entry total added toresource_bindings
. However, when I tried to setnewBinding.binding
ornewBinding.desc_set
to an increasing number, all texture indices got set to 0.How can I set spirv-cross to give each texture-sampler pair an increasing index?