Minimizing Filament Startup Time on iOS by Precompiling Metal Shaders #8940
-
Hi there! I wanted to ask if it's possible to compile Filament with the Metal backend in such a way that precompiled .metallib shaders are embedded to help reduce application startup time. Context: Calling Material::compile() on the materials from a GLTFAsset ahead of time does help eliminate the runtime stutter — but doing this adds delay presenting a model for a time i cannot afford. What I’ve tried: I came across MATEDIT and its external-compile command, which seems to allow replacing text-based shaders with precompiled binaries, but I found it a bit hard to wrap my head around. I also noticed a preferredShaderLanguage option on the Engine, which made me wonder if there’s a recommended way to bake in .metallib shaders. I'm especially interested in precompiling the core ubershaders (from Filament’s standard glTF material set), but ideally would also like to precompile the post-processing shaders (e.g., SSAO, Bloom, TAA) if possible. Questions: 2 Is embedding precompiled .metallib shaders into .mat or .filamat files officially supported (targeting just metal be or metal + other)? 3 Will such materials fully skip the runtime Metal shader compilation step? 4 Can post-processing shaders (like SSAO, Bloom, TAA) be handled the same way? 5 Is it possible (and recommended) to customize the Filament CMake build to automate the external .metallib generation and embedding? If so, where should I start? Thanks for your work and any guidance you can share — I really appreciate it! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Sebastian,
Precompiling Metal shaders is a good low-hanging fruit to start with.
Yes, this is supported with the matedit tool (see below on instructions for use). Right now it only makes sense for the Metal backend.
They will skip the expensive part, yes. Precompiled .metallib binaries still need to be transformed (by Metal) to a GPU-specific binary, but this step is much faster.
Yes.
We haven't done this, but it's certainly possible. This bit of CMake inside filament/CMakeLists.txt handles compiling internal Filament materials. We do something similar here for materials embedded in the samples. Finally, here we compile materials for gltfio. Essentially, what you'll want to do is check that you're on a macOS host add another chained
See below. Using mateditYou can invoke matedit on a compiled material like so:
my_compile_script.sh might look like this:
After running |
Beta Was this translation helpful? Give feedback.
Hi Sebastian,
Precompiling Metal shaders is a good low-hanging fruit to start with.
Yes, this is supported with the matedit tool (see below on instructions for use). Right now it only makes sense for the Metal backend.
They will skip the expensive part, yes. Precompiled .metallib binaries still need to be transformed (by Metal) to a GPU-specific binary, but this step is much faster.