Skip to content

Metal: Upgrade metal-cpp#119582

Draft
stuartcarnie wants to merge 1 commit into
godotengine:masterfrom
stuartcarnie:metal_cpp_upgrade
Draft

Metal: Upgrade metal-cpp#119582
stuartcarnie wants to merge 1 commit into
godotengine:masterfrom
stuartcarnie:metal_cpp_upgrade

Conversation

@stuartcarnie
Copy link
Copy Markdown
Contributor

@stuartcarnie stuartcarnie commented May 19, 2026

Code-size reduction

This commit upgrade metal-cpp to an improved, generated version that utilises compiler and linker optimisations introduced in Xcode 14 to resolve selectors at link time. One of those optimisations reduces code size by generating stubs to Objective-C selectors. Call sites now perform direct branches to the stub.

Compilation

The previous version was template heavy, so this should compile a little faster, but it was not measured to verify.

Patching

We no longer have to patch metal-cpp, as we can customise what APIs are generated in the config.yaml.

API availability

The generator includes API availability attributes on types and members, which is pulled from the official SDK headers. This ensures compiler warnings are generated when using APIs that may not be available on other OS releases, avoiding runtime bugs.

🤖 AI disclosure

I used API to assist with writing the generate.py code generator.

@stuartcarnie stuartcarnie requested a review from a team as a code owner May 19, 2026 20:31
@bruvzg
Copy link
Copy Markdown
Member

bruvzg commented May 19, 2026

that dispatches via linker-synthesized selector stubs (_objc_msgSend$<sel>)

This might be incompatible with OSXCross, at least was in the past. We use custom build of MoltenVK built with -fno-objc-msgsend-selector-stubs because of this.

# Code-size reduction
This commit upgrade metal-cpp to an improved, generated version that
utilises compiler and linker optimisations introduced in Xcode 14 to
resolve selectors at link time. One of those optimisations reduces code
size by generating stubs to Objective-C selectors. Call sites now
perform direct branches to the stub.

# Patching
We no longer have to patch metal-cpp, as we can customise what APIs are
generated in the `config.yaml`.

# API availability

Finally, the generator has the option to enable API availability, which
pulls availability attributes from SDK headers. This ensures compiler
warnings are generated when using APIs that may not be available on
older OS releases, avoiding runtime bugs.
@stuartcarnie
Copy link
Copy Markdown
Contributor Author

that dispatches via linker-synthesized selector stubs (_objc_msgSend$<sel>)

This might be incompatible with OSXCross, at least was in the past. We use custom build of MoltenVK built with -fno-objc-msgsend-selector-stubs because of this.

Interesting, as we don't compile Godot with that flag?

I'm also replacing the compiler tool-chain in this PR, which uses a new lld, so that shouldn't be a problem there either.

I'll test it with my local build-container setup to verify.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants