-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Implement shader caching #49050
Implement shader caching #49050
Conversation
static String _get_cache_key_function_glsl(const RenderingDevice::Capabilities *p_capabilities) { | ||
String version; | ||
version = "SpirVGen=" + itos(glslang::GetSpirvGeneratorVersion()) + ", major=" + itos(p_capabilities->version_major) + ", minor=" + itos(p_capabilities->version_minor) + " , subgroup_size=" + itos(p_capabilities->subgroup_operations) + " , subgroup_ops=" + itos(p_capabilities->subgroup_operations) + " , subgroup_in_shaders=" + itos(p_capabilities->subgroup_in_shaders); | ||
return version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiview settings need to be added here too but as there are a few more coming I'll do that as part of the multiview stereo render PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super cool! looks like a sound approach to me. Couldn't find anything obvious that stuck out just doing a quick code review.
I benchmarked it. Note that the times reported also include shutdown time (which takes about 3.5 seconds on average on the I didn't notice any visual regressions so far in my testing. System information
Godot versionsAll binaries were compiled with the same Clang version and SCons options.
Project manager
Empty project
ConclusionThe new shader caching helps noticeably, but there's still more work to do to get back to |
While this doesn't sound good, I'm not sure of the value of benchmarking an empty project. You need a complex reference scene with lighting and many materials. Godot 3 has severe game lag (as in no one would play it), where it will seize the engine to recompile the shaders. No logging, no debugging, monitors don't update. No information unless you build a custom engine with printk logging directly in the renderer. It even lags in the editor, 20-300ms each time. The work done so far to cache shaders in #46330 hasn't yet been more effective than using hacky work arounds. My hope is that vulkan and the shader caching here finally eliminates this performance lag. However if it's not tested against a complex reference scene that currently lags in Godot 3, how will we know if the root problem this and other PRs attempt to address is resolved? |
Edit: Made wording clearer Note that this PR is a great improvement, but as of now still doesn't fully resolve the underlying startup performance problems. As Calinou noted they are still not optimal and also first time startups can still be improved. Otherwise thank you very much for the hard work that went into this. |
@nathanfranke This is not advertised as a "fix" for startup time issues. It improves startup times significantly, but there are many other fixes that can be made to further reduce startup times. That doesn't mean that shader caching shouldn't be merged as is. The real potential gain from this is not so much startup time, but avoid shader compilation stutters in-game (or at most having them happen only the first time the game is played, if we can't do shader pre-compilation at startup). |
Not super important but this should likely use the cache dir instead of config dir? ( |
f112191
to
dbbf888
Compare
* Shader compilation is now cached. Subsequent loads take less than a millisecond. * Improved game, editor and project manager startup time. * Editor uses .godot/shader_cache to store shaders. * Game uses user://shader_cache * Project manager uses $config_dir/shader_cache * Options to tweak shader caching in project settings. * Editor path configuration moved from EditorSettings to new class, EditorPaths, so it can be available early on (before shaders are compiled). * Reworked ShaderCompilerRD to ensure deterministic shader code creation (else shader may change and cache will be invalidated). * Added shader compression with SMOLV: https://github.com/aras-p/smol-v
dbbf888
to
0d2e029
Compare
Thanks! |
I just noticed that Calinou also reported results for 3.4 - does that mean this is not Vulkan-only, as I originally guessed? |
@Zireael07 No, Calinou was comparing with the current 3.x branch, which doesn't have this change, for the sake of comparison (just like he compared with the then-current master without this PR for the sake of comparison). |
Also because we have a huge performance decrease between 3.x and the master and this PR addresses some of that. So a comparison was made to see how close are we getting to the old performance. |
With Godot 4 the .godot folder is introduced for import and shader_cache files. See i.e. godotengine/godot#49050 When Godot 4 is the de-facto standard all other entries can most likely be removed.
Please test.