You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Implement shader caching
* 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
This commit is contained in:
@@ -40,6 +40,7 @@ RenderingDevice *RenderingDevice::get_singleton() {
|
||||
|
||||
RenderingDevice::ShaderCompileFunction RenderingDevice::compile_function = nullptr;
|
||||
RenderingDevice::ShaderCacheFunction RenderingDevice::cache_function = nullptr;
|
||||
RenderingDevice::ShaderGetCacheKeyFunction RenderingDevice::get_cache_key_function = nullptr;
|
||||
|
||||
void RenderingDevice::shader_set_compile_function(ShaderCompileFunction p_function) {
|
||||
compile_function = p_function;
|
||||
@@ -49,6 +50,10 @@ void RenderingDevice::shader_set_cache_function(ShaderCacheFunction p_function)
|
||||
cache_function = p_function;
|
||||
}
|
||||
|
||||
void RenderingDevice::shader_set_get_cache_key_function(ShaderGetCacheKeyFunction p_function) {
|
||||
get_cache_key_function = p_function;
|
||||
}
|
||||
|
||||
Vector<uint8_t> RenderingDevice::shader_compile_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language, String *r_error, bool p_allow_cache) {
|
||||
if (p_allow_cache && cache_function) {
|
||||
Vector<uint8_t> cache = cache_function(p_stage, p_source_code, p_language);
|
||||
@@ -62,6 +67,13 @@ Vector<uint8_t> RenderingDevice::shader_compile_from_source(ShaderStage p_stage,
|
||||
return compile_function(p_stage, p_source_code, p_language, r_error, &device_capabilities);
|
||||
}
|
||||
|
||||
String RenderingDevice::shader_get_cache_key() const {
|
||||
if (get_cache_key_function) {
|
||||
return get_cache_key_function(&device_capabilities);
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
RID RenderingDevice::_texture_create(const Ref<RDTextureFormat> &p_format, const Ref<RDTextureView> &p_view, const TypedArray<PackedByteArray> &p_data) {
|
||||
ERR_FAIL_COND_V(p_format.is_null(), RID());
|
||||
ERR_FAIL_COND_V(p_view.is_null(), RID());
|
||||
|
||||
Reference in New Issue
Block a user