From d955ebce3057cef3d6355f9851334e1480c8bdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 22 May 2025 15:57:41 +0200 Subject: [PATCH] EEVEE: Default Startup Speedup Low hanging fruit optimizations for improving default startup time. Went from 7.2sec to 4sec on my system. Pull Request: https://projects.blender.org/blender/blender/pulls/139278 --- .../draw/engines/eevee/eevee_pipeline.cc | 18 ++++++++---------- .../draw/engines/eevee/eevee_pipeline.hh | 10 ++++++++++ .../draw/engines/eevee/eevee_subsurface.cc | 4 ++++ .../eevee/shaders/infos/eevee_deferred_info.hh | 12 ++++++------ .../eevee/shaders/infos/eevee_film_info.hh | 6 +++--- source/blender/gpu/GPU_debug.hh | 1 + source/blender/gpu/opengl/gl_debug.cc | 4 +++- source/blender/gpu/opengl/gl_shader.cc | 7 +++++++ 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/source/blender/draw/engines/eevee/eevee_pipeline.cc b/source/blender/draw/engines/eevee/eevee_pipeline.cc index 0ff7d630fbc..9fa1a9ad131 100644 --- a/source/blender/draw/engines/eevee/eevee_pipeline.cc +++ b/source/blender/draw/engines/eevee/eevee_pipeline.cc @@ -1275,7 +1275,7 @@ void DeferredProbePipeline::begin_sync() void DeferredProbePipeline::end_sync() { - { + if (!opaque_layer_.prepass_ps_.is_empty()) { PassSimple &pass = eval_light_ps_; pass.init(); /* Use depth test to reject background pixels. */ @@ -1388,7 +1388,13 @@ void PlanarProbePipeline::begin_sync() this->gbuffer_pass_sync(inst_); - { + closure_bits_ = CLOSURE_NONE; + closure_count_ = 0; +} + +void PlanarProbePipeline::end_sync() +{ + if (!prepass_ps_.is_empty()) { PassSimple &pass = eval_light_ps_; pass.init(); pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL); @@ -1405,14 +1411,6 @@ void PlanarProbePipeline::begin_sync() pass.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS); pass.draw_procedural(GPU_PRIM_TRIS, 1, 3); } - - closure_bits_ = CLOSURE_NONE; - closure_count_ = 0; -} - -void PlanarProbePipeline::end_sync() -{ - /* No-op for now. */ } PassMain::Sub *PlanarProbePipeline::prepass_add(::Material *blender_mat, GPUMaterial *gpumat) diff --git a/source/blender/draw/engines/eevee/eevee_pipeline.hh b/source/blender/draw/engines/eevee/eevee_pipeline.hh index e5f55ac81b7..220f3bc0a73 100644 --- a/source/blender/draw/engines/eevee/eevee_pipeline.hh +++ b/source/blender/draw/engines/eevee/eevee_pipeline.hh @@ -252,6 +252,11 @@ struct DeferredLayerBase { return count; } + eClosureBits closure_bits_get() const + { + return closure_bits_; + } + void gbuffer_pass_sync(Instance &inst); }; @@ -406,6 +411,11 @@ class DeferredPipeline { return opaque_layer_.is_empty() && refraction_layer_.is_empty(); } + eClosureBits closure_bits_get() const + { + return opaque_layer_.closure_bits_get() | refraction_layer_.closure_bits_get(); + } + private: void debug_pass_sync(); }; diff --git a/source/blender/draw/engines/eevee/eevee_subsurface.cc b/source/blender/draw/engines/eevee/eevee_subsurface.cc index 0a1ef6f8937..1baf14673f9 100644 --- a/source/blender/draw/engines/eevee/eevee_subsurface.cc +++ b/source/blender/draw/engines/eevee/eevee_subsurface.cc @@ -21,6 +21,10 @@ void SubsurfaceModule::end_sync() { data_.sample_len = 16; + if (!(inst_.pipelines.deferred.closure_bits_get() & CLOSURE_SSS)) { + return; + } + { PassSimple &pass = setup_ps_; pass.init(); diff --git a/source/blender/draw/engines/eevee/shaders/infos/eevee_deferred_info.hh b/source/blender/draw/engines/eevee/shaders/infos/eevee_deferred_info.hh index c72bfbd0961..81adc49fe59 100644 --- a/source/blender/draw/engines/eevee/shaders/infos/eevee_deferred_info.hh +++ b/source/blender/draw/engines/eevee/shaders/infos/eevee_deferred_info.hh @@ -69,8 +69,8 @@ IMAGE_FREQ(4, DEFERRED_RADIANCE_FORMAT, write, uimage2D, direct_radiance_3_img, IMAGE_FREQ(5, RAYTRACE_RADIANCE_FORMAT, write, image2D, indirect_radiance_1_img, PASS) IMAGE_FREQ(6, RAYTRACE_RADIANCE_FORMAT, write, image2D, indirect_radiance_2_img, PASS) IMAGE_FREQ(7, RAYTRACE_RADIANCE_FORMAT, write, image2D, indirect_radiance_3_img, PASS) -SPECIALIZATION_CONSTANT(bool, use_split_indirect, false) -SPECIALIZATION_CONSTANT(bool, use_lightprobe_eval, false) +SPECIALIZATION_CONSTANT(bool, use_split_indirect, true) +SPECIALIZATION_CONSTANT(bool, use_lightprobe_eval, true) SPECIALIZATION_CONSTANT(bool, use_transmission, false) SPECIALIZATION_CONSTANT(int, render_pass_shadow_id, -1) DEFINE("SPECIALIZED_SHADOW_PARAMS") @@ -127,11 +127,11 @@ ADDITIONAL_INFO(gpu_fullscreen) FRAGMENT_SOURCE("eevee_deferred_combine_frag.glsl") /* NOTE: Both light IDs have a valid specialized assignment of '-1' so only when default is * present will we instead dynamically look-up ID from the uniform buffer. */ -SPECIALIZATION_CONSTANT(bool, render_pass_diffuse_light_enabled, true) -SPECIALIZATION_CONSTANT(bool, render_pass_specular_light_enabled, true) -SPECIALIZATION_CONSTANT(bool, render_pass_normal_enabled, true) +SPECIALIZATION_CONSTANT(bool, render_pass_diffuse_light_enabled, false) +SPECIALIZATION_CONSTANT(bool, render_pass_specular_light_enabled, false) +SPECIALIZATION_CONSTANT(bool, render_pass_normal_enabled, false) SPECIALIZATION_CONSTANT(bool, use_radiance_feedback, false) -SPECIALIZATION_CONSTANT(bool, use_split_radiance, false) +SPECIALIZATION_CONSTANT(bool, use_split_radiance, true) DO_STATIC_COMPILATION() GPU_SHADER_CREATE_END() diff --git a/source/blender/draw/engines/eevee/shaders/infos/eevee_film_info.hh b/source/blender/draw/engines/eevee/shaders/infos/eevee_film_info.hh index 7f91e53f46d..c2000128224 100644 --- a/source/blender/draw/engines/eevee/shaders/infos/eevee_film_info.hh +++ b/source/blender/draw/engines/eevee/shaders/infos/eevee_film_info.hh @@ -27,9 +27,9 @@ SAMPLER(5, sampler2D, in_combined_tx) SAMPLER(6, sampler2D, cryptomatte_tx) IMAGE(0, GPU_R32F, read, image2DArray, in_weight_img) IMAGE(1, GPU_R32F, write, image2DArray, out_weight_img) -SPECIALIZATION_CONSTANT(uint, enabled_categories, 0) -SPECIALIZATION_CONSTANT(int, samples_len, 0) -SPECIALIZATION_CONSTANT(bool, use_reprojection, false) +SPECIALIZATION_CONSTANT(uint, enabled_categories, 1) +SPECIALIZATION_CONSTANT(int, samples_len, 9) +SPECIALIZATION_CONSTANT(bool, use_reprojection, true) SPECIALIZATION_CONSTANT(int, scaling_factor, 1) SPECIALIZATION_CONSTANT(int, combined_id, 0) SPECIALIZATION_CONSTANT(int, display_id, -1) diff --git a/source/blender/gpu/GPU_debug.hh b/source/blender/gpu/GPU_debug.hh index ff41c88d734..b00b6cbe656 100644 --- a/source/blender/gpu/GPU_debug.hh +++ b/source/blender/gpu/GPU_debug.hh @@ -62,6 +62,7 @@ #pragma once #define GPU_DEBUG_SHADER_COMPILATION_GROUP "Shader Compilation" +#define GPU_DEBUG_SHADER_SPECIALIZATION_GROUP "Shader Specialization" void GPU_debug_group_begin(const char *name); void GPU_debug_group_end(); diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index 4dfa28c4031..98012f52ae2 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -92,7 +92,9 @@ static void APIENTRY debug_callback(GLenum /*source*/, GPU_debug_get_groups_names(sizeof(debug_groups), debug_groups); CLG_Severity clog_severity; - if (GPU_debug_group_match(GPU_DEBUG_SHADER_COMPILATION_GROUP)) { + if (GPU_debug_group_match(GPU_DEBUG_SHADER_COMPILATION_GROUP) || + GPU_debug_group_match(GPU_DEBUG_SHADER_SPECIALIZATION_GROUP)) + { /* Do not duplicate shader compilation error/warnings. */ return; } diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index f7feeea6937..94124d22711 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -19,6 +19,7 @@ #include BLI_SYSTEM_PID_H #include "GPU_capabilities.hh" +#include "GPU_debug.hh" #include "GPU_platform.hh" #include "gpu_capabilities_private.hh" #include "gpu_shader_dependency_private.hh" @@ -1617,8 +1618,14 @@ GLShader::GLProgram &GLShader::program_get(const shader::SpecializationConstants return program; } + GPU_debug_group_begin(GPU_DEBUG_SHADER_SPECIALIZATION_GROUP); + GPU_debug_group_begin(this->name); + program.program_link(name); + GPU_debug_group_end(); + GPU_debug_group_end(); + return program; }