Fix: Finalize CreateInfos at startup
Prevents race conditions on ShaderCreateInfo::finalize. Previoulsy fixed by #128281, but it doesn't work for the render thread.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<StringRefNull> deps_merged;
|
||||
|
||||
validate_vertex_attributes();
|
||||
@@ -117,8 +112,12 @@ void ShaderCreateInfo::finalize()
|
||||
const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>(
|
||||
gpu_shader_create_info_get(info_name.c_str()));
|
||||
|
||||
/* Recursive. */
|
||||
const_cast<ShaderCreateInfo &>(info).finalize();
|
||||
if (recursive) {
|
||||
const_cast<ShaderCreateInfo &>(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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user