Debug symbols in metallib

Hello,

I’ve started testing the Metal Shader Converter to convert my HLSL shaders to metallib directly, and I was wondering if the option ’-frecord-sources’ was supported in any way?

Usually I’m compiling my shaders as follows (from Metal):

xcrun -sdk macosx metal -c -frecord-sources shaders/shaders.metal -o shaders/shaders.air
xcrun -sdk macosx metallib shaders/shaders.air -o shaders/shaders.metallib

The -frecord-sources allow me to see the source when debugging and profiling a Metal frame.

Now with DXC we have a similar option, I can compile a typical HLSL shader with embedded debug symbols with:

dxc -T vs_6_0 -E VSMain shaders/triangle.hlsl -Fo shaders/triangle.dxil -Zi -O0 -Qembed_debug

The important options here are ’-Zi` and ’-Qembed_debug’, as they make sure debug symbols are embedded in the DXIL.

It seems that right now Metal Shader Converter doesn’t pass through the DXIL debug information, and I was wondering if it was possible. I’ve looked at all the options in the utility and haven’t seen anything that looked like it.

Right now debug symbols in my shaders is a must-have, so I’ll explore other routes to convert my HLSL shaders to Metal (I’ve been testing spir-v cross to do the conversion, I haven’t actually tested the debug symbols yet, I’ll report back later).

Thank you for your time!

As promised, here's the result of using spirv-cross to get the shader symbols.

A few caveats first, I can't get the original source shader to show up, it seems to be the intermediate result from the HLSL -> SPIR-V compilation. I'll bring this up with the DXC repository directly.

So tested toolchain is:

HLSL -> SPIRV -> AIR -> METALLIB, here's an example of a script to compile a pixel shader:

dxc -T ps_6_0 -E PSMain -spirv shaders/triangle.hlsl -Zi -Qembed_debug -O0 -Fo shaders/triangle.frag.spirv
spirv-cross --msl shaders/triangle.frag.spirv --output shaders/triangle.frag.metal
xcrun -sdk macosx metal -c -frecord-sources shaders/triangle.frag.metal -o shaders/triangle.frag.air
xcrun -sdk macosx metallib shaders/triangle.frag.air -o shaders/triangle.frag.metallib

As you can see, it's a lot more steps than metal shader converter, but after all those steps you can get some sort of shader symbols in xcode when debugging a metal frame, which is better than nothing:

Please let me know if I can provide files, projects or anything that can help supporting shader symbols directly with metal shader converter.

Cheers,

Alex

spirv-cross MSL output is converting SPIRV IL which is completely different than the MSL that will result from DX IL conversion. You have to pick whether you want debugging of quite unreadable transpiled MSL from spirv-cross with all comments stripped, or whatever shader converter generates (probably not even debuggable MSL).

HLSL -> DXC -> DXIL -> metal-shaderconverter -> metallib (containing Metal IL)

@Alecazam that's the whole point of my post, right now Metal Shader Converter doesn't produce any kind of debug information, it's completely stripped out, making debugging the shaders or profiling them impossible in its current state. The only workaround I have right now is the one I've outlined in my 1st answer, to use spir-v cross, with the caveats outlined (spir-v looking debug info, etc.)

Darn, I came here looking for a way to debug HLSL --> DXIL --> Metallib and I guess it's not really a thing yet :-/

Debug symbols in metallib
 
 
Q