diff --git a/source/blender/gpu/intern/gpu_codegen.cc b/source/blender/gpu/intern/gpu_codegen.cc index a62f787ba32..d7a4902f718 100644 --- a/source/blender/gpu/intern/gpu_codegen.cc +++ b/source/blender/gpu/intern/gpu_codegen.cc @@ -786,7 +786,7 @@ GPUPass *GPU_generate_pass(GPUMaterial *material, pass->shader = nullptr; pass->refcount = 1; pass->create_info = codegen.create_info; - /* Ensure the CreateInfo is finalized in the main thread. */ + /* Finalize before adding the pass to the cache, to prevent race conditions. */ pass->create_info->finalize(); pass->engine = engine; pass->hash = codegen.hash_get(); diff --git a/source/blender/gpu/intern/gpu_shader_builder.cc b/source/blender/gpu/intern/gpu_shader_builder.cc index 1a8d6656fb7..51097e42726 100644 --- a/source/blender/gpu/intern/gpu_shader_builder.cc +++ b/source/blender/gpu/intern/gpu_shader_builder.cc @@ -17,7 +17,6 @@ #include "gpu_shader_create_info_private.hh" #include "BLI_string_ref.hh" -#include "BLI_threads.h" #include "BLI_vector.hh" #include "CLG_log.h" @@ -46,7 +45,6 @@ bool ShaderBuilder::bake_create_infos(const char *name_starts_with_filter) void ShaderBuilder::init_system() { CLG_init(); - BLI_threadapi_init(); ghost_system_ = GHOST_CreateSystemBackground(); GPU_backend_ghost_system_set(ghost_system_); } @@ -109,7 +107,6 @@ void ShaderBuilder::exit_context() void ShaderBuilder::exit_system() { GHOST_DisposeSystem(ghost_system_); - BLI_threadapi_exit(); CLG_exit(); } diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc index 42834777034..77d4b0356d0 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.cc +++ b/source/blender/gpu/intern/gpu_shader_create_info.cc @@ -95,18 +95,13 @@ bool ShaderCreateInfo::is_vulkan_compatible() const /** \} */ -void ShaderCreateInfo::finalize() +void ShaderCreateInfo::finalize(const bool recursive) { if (finalized_) { return; } finalized_ = true; -#if 0 - /* TODO(Miguel Pozo): This triggers for image renders. */ - BLI_assert(BLI_thread_is_main()); -#endif - Set deps_merged; validate_vertex_attributes(); @@ -117,8 +112,12 @@ void ShaderCreateInfo::finalize() const ShaderCreateInfo &info = *reinterpret_cast( gpu_shader_create_info_get(info_name.c_str())); - /* Recursive. */ - const_cast(info).finalize(); + if (recursive) { + const_cast(info).finalize(recursive); + } + else { + BLI_assert(info.finalized_); + } interface_names_size_ += info.interface_names_size_; @@ -585,6 +584,10 @@ void gpu_shader_create_info_init() #endif } + for (ShaderCreateInfo *info : g_create_infos->values()) { + info->finalize(true); + } + /* TEST */ // gpu_shader_create_info_compile(nullptr); } diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh index baaaafa6e4c..15f3501ab34 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.hh +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -1268,8 +1268,10 @@ struct ShaderCreateInfo { * descriptors. This avoids tedious traversal in shader source creation. * \{ */ - /* WARNING: Recursive. */ - void finalize(); + /* WARNING: Recursive evaluation is not thread safe. + * Non-recursive evaluation expects their dependencies to be already finalized. + * (All statically declared CreateInfos are automatically finalized at startup) */ + void finalize(const bool recursive = false); std::string check_error() const; bool is_vulkan_compatible() const; diff --git a/source/blender/gpu/opengl/gl_compilation_subprocess.cc b/source/blender/gpu/opengl/gl_compilation_subprocess.cc index 6ca9998e0b6..1ba34891394 100644 --- a/source/blender/gpu/opengl/gl_compilation_subprocess.cc +++ b/source/blender/gpu/opengl/gl_compilation_subprocess.cc @@ -10,7 +10,6 @@ # include "BLI_fileops.hh" # include "BLI_hash.hh" # include "BLI_path_utils.hh" -# include "BLI_threads.h" # include "CLG_log.h" # include "GHOST_C-api.h" # include "GPU_context.hh" @@ -154,7 +153,6 @@ void GPU_compilation_subprocess_run(const char *subprocess_name) # endif CLG_init(); - BLI_threadapi_init(); std::string name = subprocess_name; SharedMemory shared_mem(name, compilation_subprocess_shared_memory_size, false); @@ -284,7 +282,6 @@ void GPU_compilation_subprocess_run(const char *subprocess_name) GPU_context_discard(gpu_context); GHOST_DisposeGPUContext(ghost_system, ghost_context); GHOST_DisposeSystem(ghost_system); - BLI_threadapi_exit(); } namespace blender::gpu {