Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide flags to configure metal compilation #5823

Open
schwa opened this issue Oct 18, 2022 · 9 comments
Open

Provide flags to configure metal compilation #5823

schwa opened this issue Oct 18, 2022 · 9 comments

Comments

@schwa
Copy link

schwa commented Oct 18, 2022

Description

It seems SPM now magically compiles .metal files into a default.metallib (see #5822)

Unfortunately there's no documented way to specify compilation flags to the metal compiler.

This means it is impossible to debug shaders using the Xcode Metal Debugger. When we try we get this error:

Unable to create shader debug session

Source is unavailable

Under the target's Build Settings, ensure the Metal Compiler Build Options produces debugging information and includes source code.

If building with the 'metal' command line tool, include the options '-gline-tables-only' and '-frecord-sources'.

I'd like to see .metalFlags or similar available to SPM

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

No response

@neonichu
Copy link
Contributor

Generally, I'm a bit skeptical about adding manifest API for Xcode specific file types. For this issue in particular, I think Xcode should just automatically do the right thing and pass debug-related flags (there's an existing bug tracking that request rdar://79153205).

cc @abertelrud

@schwa
Copy link
Author

schwa commented Oct 18, 2022

Boiling the problem down and we're left with "we cannot debug Metal shaders from SPM Packages"

I'm not concerned how that's solved. But right now it means folks can't really use SPM & metal together (see https://twitter.com/warrenm/status/1582039539123486721).

I've been trying to get it working and have resorted to using my own SPM Plugin to compile .metal https://github.com/schwa/MetalCompilerPlugin - which isn't ideal as I can't overwrite default.metallib and have to build my "debug.metallib" side by side with it.

That said I can definitely see a need to send metal compilation flags to metal from SPM - being able to configure -D macros for example seem very useful.

@schwa
Copy link
Author

schwa commented Oct 18, 2022

(As background: One technique folks have been using as well is to put their metal files in a C target, with headers in ./include and a module map to make the headers available to swift.)

@wtholliday
Copy link

Generally, I'm a bit skeptical about adding manifest API for Xcode specific file types. For this issue in particular, I think Xcode should just automatically do the right thing and pass debug-related flags (there's an existing bug tracking that request rdar://79153205).

cc @abertelrud

Yes, Xcode should just do automatically the right thing. But it doesn't. We've been hacking around this stupid problem for years now. Throw us a bone.

@schwa
Copy link
Author

schwa commented Sep 27, 2023

It's been almost a year - is there still no way to configure how SPM compiles metal code into .metallibs?

@neonichu
Copy link
Contributor

Looks like rdar://79153205 is still unresolved.

@code-per-day
Copy link

Checking the pulse on this issue, is there still no way to debug metal shaders with SwiftPM?

@wtholliday
Copy link

AFAIK, no. I've abandoned SPM for most of my code because of this. It's just too much of a headache.

@schwa
Copy link
Author

schwa commented Apr 25, 2024

I am debugging metal shaders using the SPM plugin I mentioned earlier (https://github.com/schwa/MetalCompilerPlugin). It's not a great solution (development-only plugins suck in general) but it does allow me to debug shaders.

I'd still much prefer a proper solution from Apple but this definitely does not seem overly important to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants