filament icon indicating copy to clipboard operation
filament copied to clipboard

use metal DynamicLibrary to reduce loading time

Open Michael-Lfx opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Power up your shader pipeline with enhancements to the Metal shader compilation model — all leading to a dramatic reduction in Pipeline State Object (PSO) loading time, especially upon first launch. https://developer.apple.com/videos/play/wwdc2020/10615/

Describe the solution you'd like Cache compiled PSO to memory/files inside filament automatically.

Describe alternatives you've considered None.

OS and backend Apple only.

Michael-Lfx avatar Apr 22 '22 08:04 Michael-Lfx

Filament never does IO on its own, for something like that to happen it would require adding an interface on Engine that the app could implement to trigger the load/save of PSOs. We thought about it a few times but it hasn't been a priority since Android caches compiled GL shaders on behalf of the apps.

romainguy avatar Apr 24 '22 10:04 romainguy

Thanks for the suggestion. Closing this for now as these techniques are only available with newer iOS versions.

bejado avatar Aug 15 '22 20:08 bejado

I'm experiencing hideous (~10s) shader compilation times on first app launch on iOS (subsequent launches are fine, so I assume these have been cached).

I've seen similar reports on the Apple forum, and it seems Metal dynamic libraries are the official solution. While I'm exploring ways to address this, is it possible to extract Metal shader source from the ubershader archive to pass to a Metal dynamic library?

nmfisher avatar Sep 04 '23 14:09 nmfisher

We have clients that need to support older iOS versions, so it's unlikely we'll support Metal dynamic libraries. However, we recently added a Material::compile API which will asynchronously pre-compile shaders, which can help hide first app launch shader compilation times. We are working on supporting this API for Metal.

bejado avatar Sep 06 '23 01:09 bejado

Thanks - that sounds like a good compromise solution. In the meantime, I'm just working round the compilation time by minimizing the number of material variants in the assets. I'll keep an eye open for future PRs for the Metal implementation for Material::compile.

nmfisher avatar Sep 06 '23 01:09 nmfisher