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

Support metallib from CLI? #39

Open
TheSpydog opened this issue Oct 31, 2024 · 0 comments · May be fixed by #40
Open

Support metallib from CLI? #39

TheSpydog opened this issue Oct 31, 2024 · 0 comments · May be fixed by #40

Comments

@TheSpydog
Copy link
Collaborator

TheSpydog commented Oct 31, 2024

The SDL_GPU Metal backend accepts two shader formats -- MSL and metallib. MSL is the plain-text shader which is compiled at runtime via Metal APIs. Metallib is essentially the compiled bytecode form of MSL.

The only way to obtain metallib binaries is to use the Xcode Metal compiler or the Metal Developer Tools for Windows. Apple does not provide any libraries for shader compilation and there is no way to serialize a runtime-compiled Metal library into metallib format. The compilation process is extremely sparsely documented and there is no official reference material; even xcrun metal --help isn't very helpful since it shows the full list of options for clang, not for Metal specifically.

So basically Metal offline compilation is a huge pain. But, of course, it's more efficient than runtime compilation. So it'd be nice if we could support it from in some capacity from the shadercross CLI to save developers the trouble of figuring out the magic invocations themselves.

On Windows/Mac, we could invoke the Metal compiler executable directly if the destination format is METALLIB. Due to the proprietary license (and massive binary size), we can't ship the Metal shader toolchain with shadercross, so we'd have to ask the developer to install the toolchain themselves. No idea what to do about Linux though since it's not officially supported... Maybe there's some way to run the Windows Metal toolchain with Wine?

There's also the question of how to define which platforms the generated metallib code should support. You can compile binaries for macOS, iOS Simulator, tvOS, and tvOS Simulator. I suppose we could add a "shader model"-style optional command line flag for this.

@TheSpydog TheSpydog linked a pull request Oct 31, 2024 that will close this issue
3 tasks
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

Successfully merging a pull request may close this issue.

1 participant