Skip to content

Commit eb204c5

Browse files
committed
Metal: Compile MTLLibrary on demand when pipeline is created
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.
1 parent 394508d commit eb204c5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/metal/rendering_device_driver_metal.mm

+5
Original file line numberDiff line numberDiff line change
@@ -4082,9 +4082,14 @@ bool isArrayTexture(MTLTextureType p_type) {
40824082
context_driver(p_context_driver) {
40834083
DEV_ASSERT(p_context_driver != nullptr);
40844084

4085+
#if TARGET_OS_OSX
40854086
if (String res = OS::get_singleton()->get_environment("GODOT_MTL_SHADER_LOAD_STRATEGY"); res == U"lazy") {
40864087
_shader_load_strategy = ShaderLoadStrategy::LAZY;
40874088
}
4089+
#else
4090+
// Always use the lazy strategy on other OSs like iOS, tvOS or visionOS.
4091+
_shader_load_strategy = ShaderLoadStrategy::LAZY;
4092+
#endif
40884093
}
40894094

40904095
RenderingDeviceDriverMetal::~RenderingDeviceDriverMetal() {

0 commit comments

Comments
 (0)