Metal Fragment Shader Reflection

We are converting some shaders from HLSL to Metal using dxc to compile to spir-v and then spirv-cross to convert to .metal. The output looks pretty reasonable to me although I am still a newbie to .metal. This is all happening on a PC using the Metal tools for Windows.

On iOS when I load the first vertex shader it looks reasonable and the input attributes are reflected in both the vertex attributes and also the general attributes.

However, when I then attempt to load the fragment shader it finds the function successfully, but both the vertex attributes and stage input attributes are non-existent (obviously expected for the vertex attributes).

I've taken a look at the .metal file and it seems to be doing the correct thing. It has multiple inputs to the function, none of which seem to be reflected.

We are compiling the functions independently as it would be somewhat non-trivial in our code base to compile them into a single library, but my fear is that somehow it is unhappy about this.

I've been digging into this and it seems like we maybe have to work backwards and have a PSO before we can query the reflection. The documentation seems to just throw out things and let you guess how to use them unless you are doing things the most straight-forward way (i.e. you don't have a multi-platform title with a bunch of pre-existing code that expects things to be done in a slightly different way).

Also, is it even possible to do entirely offline shader reflection then? It doesn't really seem like it, unless we can somehow use the command line commands to examine the bindings in the .air/.metallib files.

Just use the spriv tools to generate your reflection data. It's a shame that Apple's MSL can't output spir-v. So then end up having to write everything in HLSL or GLSL.

Metal Fragment Shader Reflection
 
 
Q