Fix: Leak of GHOST GPU contexts in Metal backend

Need to respect the ownership and lifetime of objects.

Pull Request: https://projects.blender.org/blender/blender/pulls/130282
This commit is contained in:
Sergey Sharybin
2024-11-14 17:18:55 +01:00
committed by Sergey Sharybin
parent 75ab1c2daf
commit f70ec20ab8
2 changed files with 11 additions and 4 deletions

View File

@@ -442,7 +442,8 @@ class MTLParallelShaderCompiler {
std::mutex queue_mutex;
std::deque<ParallelWork *> parallel_work_queue;
void parallel_compilation_thread_func(GPUContext *blender_gpu_context);
void parallel_compilation_thread_func(GPUContext *blender_gpu_context,
GHOST_ContextHandle ghost_gpu_context);
BatchHandle create_batch(size_t batch_size);
void add_item_to_batch(ParallelWork *work_item, BatchHandle batch_handle);
void add_parallel_item_to_queue(ParallelWork *add_parallel_item_to_queuework_item,

View File

@@ -1940,13 +1940,14 @@ void MTLParallelShaderCompiler::create_compile_threads()
GPU_context_active_set(main_thread_context);
/* Create a new thread */
compile_threads.push_back(std::thread([this, per_thread_context] {
this->parallel_compilation_thread_func(per_thread_context);
compile_threads.push_back(std::thread([this, per_thread_context, ghost_gpu_context] {
this->parallel_compilation_thread_func(per_thread_context, ghost_gpu_context);
}));
}
}
void MTLParallelShaderCompiler::parallel_compilation_thread_func(GPUContext *blender_gpu_context)
void MTLParallelShaderCompiler::parallel_compilation_thread_func(
GPUContext *blender_gpu_context, GHOST_ContextHandle ghost_gpu_context)
{
/* Contexts can only be created on the main thread so we have to
* pass one in and make it active here */
@@ -2006,6 +2007,11 @@ void MTLParallelShaderCompiler::parallel_compilation_thread_func(GPUContext *ble
}
GPU_context_discard(blender_gpu_context);
GHOST_SystemHandle ghost_system = reinterpret_cast<GHOST_SystemHandle>(
GPU_backend_ghost_system_get());
BLI_assert(ghost_system);
GHOST_DisposeGPUContext(ghost_system, ghost_gpu_context);
}
BatchHandle MTLParallelShaderCompiler::create_batch(size_t batch_size)