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

Metal: Compile MTLLibrary on demand when pipeline is created #103185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stuartcarnie
Copy link
Contributor

@stuartcarnie stuartcarnie commented Feb 22, 2025

Closes #103006

This changes the default shader loading strategy for mobile Apple platforms, implemented in the Metal driver, to compile the MTLLibrary on demand when the pipeline is created. This reduces cold startup time on IPHONE target OSs (iOS, tvOS and visionOS).

Normally, the MTLLibrary is compiled from Metal source asynchronously when Godot calls
RenderingDeviceDriverMetal::shader_create_from_bytecode; however, this changes this behaviour on mobile platforms to do it on demand when the pipeline is created. As noted in #96052, Godot will ask to create many more shaders from bytecode than are initially required. Mobile OSs like iOS are limited to compiling two shader libraries concurrently, which results in a significant bottleneck.

This is not the default for macOS, as it can concurrently compile many shaders at once, resulting in faster startup times for the Godot editor.

This changes the default shader loading strategy, implemented in the
Metal driver, to compile the `MTLLibrary` on demand when the pipeline
is created, which reduces cold startup time on IPHONE target OSs.

Normally, the `MTLLibrary` is compiled from Metal source asynchronously
when Godot calls
`RenderingDeviceDriverMetal::shader_create_from_bytecode`; however, this
changes this behaviour on mobile platforms to do it on demand when the
pipeline is created, as noted in godotengine#96052, Godot will ask to create
many more shaders from bytecode than are initially required. Mobile
OSs like iOS are limited to compiling to shader libraries concurrently,
which results in a significant bottleneck.

This is not the default for macOS, as it can concurrently compile many
shaders at once, resulting in faster startup times for the Godot editor.
@stuartcarnie stuartcarnie requested a review from a team as a code owner February 22, 2025 19:01
stuartcarnie added a commit to stuartcarnie/godot that referenced this pull request Feb 22, 2025
@Chaosus Chaosus added this to the 4.x milestone Feb 23, 2025
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.

[4.4 beta 4] iOS: Metal shader compilation warnings and unexpected compilation amount
2 participants