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
Optimize shader processor #6067
Conversation
Thank god, I'm having so many issues with this right now! looks forward to trying it. Any reason I couldn't write these cached shader files to disk / localstorage? Would be nice if it could be skipped on subsequent runs |
@MAG-AdrianMeredith it looks like its only for iOS15. If you are on iOS16, it should already be running at optimal speed. Now that you brought it up, I'm also curious if there is a way to reuse once compiled shader / keys on subsequent runs of the same application. Can some of those be reused by another app, if they share a storage? We have a native wrapper that hosts multiple apps, and it could share data between them. |
We have some code that can store the generated shaders to a file, and load it / precompile ahead of time. Not a public API, and not really well implemented, so it's disabled at the moment. But I keep thinking about how to do this in a better way. Modifying material properties and then calling update() on the material is another thing that does not work too well, as it often makes the engine to reevaluate material options to see if the existing shader can still be used. This is expensive. |
Good point. We've noticed it as well and generally try to avoid updating or changing a material at runtime. We have a limited set of materials that all of our assets are using across all our games. They are always the same. |
right now I'm seeing it take almost a minute from loading (and seeing the world) to actually being able to move around because its hitching so much. Seems to be spending most of its time in "generateKey". Hopefully I'll get time to look into it further soon so I'll get back to you if I find anything. might not be be for a few weeks though |
What device are you running this on @MAG-AdrianMeredith ? |
I am considering to monkey-patch the key generation for our project. If none of our games is using e.g. a clear coat factor, then there is no need to check its value. Building around this premise, perhaps we could explicitly tell which fields can be different and used by the generator. The rest would be ignored, and assumed to be the same across all materials. However, if the majority of time is coming from say linking the program, then that won't help much. |
From my profiling, I could not see this taking too much time .. options generation is about 1ms or less. Can you please post some screenshots of what you see? |
yeah and that is the blocking call waiting for the shader to finish compiling :( You can enable tracing to see how many shaders are compiled, and how long the blocking duration is as well. In case you have many shaders, you could aim at reducing that number. Note that some browsers cache this compilation .. so often it's only expensive on the first run, and when dev tools are opened. |
The shader compilation / linking runs in the background browser threads. When we need the result, we call getProgramParameter to get info about the shader, and this is blocking till the shader is done compiling. So this is part of the compilation. |
before:
after:
For 100 shaders this makes about 1.5s difference.