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

Extending apple_metal_library rule #2502

Open
mxpv opened this issue Jul 18, 2024 · 0 comments
Open

Extending apple_metal_library rule #2502

mxpv opened this issue Jul 18, 2024 · 0 comments

Comments

@mxpv
Copy link

mxpv commented Jul 18, 2024

I've been playing with Bazel and apple_metal_library rule for a small project to compile MSL shaders. While it serves its purpose, I found it pretty challenging to generate symbols companion file for the metal library. These are pretty useful during development stages. So I'm curious if there are any suggestions or room for a PR :)

Internally apple_metal_library works in two phases:

  • generate air files (like xcrun -sdk macosx metal -o Shadow.ir -c Shadow.metal {COPTS})
  • and then combining set of air files into a library (like xcrun -sdk macosx metallib -o LightsAndShadow.metallib Lights.metalar Shadow.ir)

So to support debug symbols generation with multiple commands, we need:

  • Add -frecord-sources COPTS in step 1.
  • Add -frecord-sources to step 2 (so add anothe COPTS for linking stage?)
  • Separate the sources from the library and create a companion symbol file by running the metal-dsymutil command. (like % xcrun -sdk macosx metal-dsymutil -flat -remove-source LightsAndShadow.metallib)

This is quite complex.

Slightly easier option would be to simplify current implementation and reduce it to just one command:

For current scenario, the command would look like:

% xcrun -sdk macosx metal -o default.metallib Shadow.metal PointLights.metal DirectionalLight.metal

With debug symbols:

% xcrun -sdk macosx metal -o default.metallib -frecord-sources=flat Shadow.metal PointLights.metal DirectionalLight.metal

Which can be satisfied via existing COPTS param.

apple_metal_library(
    name = "metal_lib",
    copts = ["-w", "-frecord-sources=flat"], # or param symbols = True?
    hdrs = ["shared.h"],
    srcs = ["shader1.metal", "shader2.metal"],
    outs = ["test.metallib", "test.metallibsym"] 
)

cc: @aaronsky

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

No branches or pull requests

1 participant