Cannot debug shaders compiled on Windows

I'm using shaders compiled with Metal Developer Tools for Windows. Compiled shaders look fine, but cannot see the shader source from GPU frame capture in Xcode, and cannot debug these shaders. (I tried options "-MO" and "-gline-tables-only", but nothing changed.)

Could you tell me how can I debug the shaders compiled on Windows?

Below is my environment.

  • Mac mini (M1, 2020)
  • Xcode 12.5.1
  • Metal Developer Tools for Windows 1.2

Replies

Hi, I think you need to add the "record-sources" flag with the "flat" option.

  • Thank you for advice.

    I cannot find any document about "record-sources" nor "flat". From where can I set these options?

    I tried to compile with "record-sources" or "flat" and I got error. And I also tried "gembed-source" but cannot see and debug shader source in Xcode.)

  • The option would be -frecord-sources, which is equivalent to the -MO you mentioned in your original post. You have to use -frecord-sources for both the compile and link commands if they are separate (e.g. metal -c then metal). So I’m not sure what you used above, so you may try that. Alternatively, option -frecord-sources=flat saves the sources into a companion .metallibsym file instead of into the .metallib file (which may not be be necessary in your case; for more details, this article). The second thing is that there was a fix in the latest Xcode 13 Beta 5 which may affect the display of sources from Windows, so I would ensure that you are on the latest toolchain. I hope that helps!

  • Thank you. I found options for -frecord-sources=flat in Metal Developer Tools 2.0 beta 5 (I used 1.2 before). And I tried with Xcode 13 beta 5 but sources is not displayed on Xcode yet. I use newLibraryWithData to load shaders so I guess .metallibsym is not loaded in application. Is there any way to load .metallibsym manually?

Add a Comment

Thank you for trying with beta 5.

For saving sources to a .metallibsym file, please see this article.

For saving sources to a .metallib file, please use metal -frecord-sources without =flat.

If the commands described above do not result in Xcode 13 beta 5 displaying your sources, it would be helpful to detail all your steps in a Feedback Assistant request.

This doesn't work for me. I've tried with both frecord-sources and the flat equivalent, and the older -MO flag as well. With both the latest beta & release versions of the metal developer tools and with latest xcode release 13.2.1

When loading it into xcode frame debugger, it shows "No source" and if I look at the filepath of the lib it shows the path on windows. Could that be the reason ? I assume the source should be embedded and it shouldn't care about the filepath of the original metal file.

Thanks

If you use the flat option, then according to this article, it will result in a companion .metallibsym file. That is the file that Xcode will ask for. Since the original path was on Windows, and you're debugging on Mac, then you would need to add a path to the directory where this file is located on your Mac. You can do this by clicking the Add button (+) in the Import External Sources dialog.