Fix: Cycles crash on Metal GPU with ASAN builds

Running a very simple files when Blender is built with the
WITH_COMPILER_ASAN=ON and WITH_CYCLES_KERNEL_ASAN=ON CMake options
leads to ASAN reporting an unknown-crash at line where the worker
pool is being filled in.

It is not entirely clear if it is a real issue in the code, since
placing debug prints with `this` address report proper addresses,
however there is no harm on capturing `this` pointer by value and
it does solve the ASAN reporting issues.

It is possible to reproduce the ASAN crash with the following steps:
- Start with --factory-startup
- Enable Metal device in User Preferences
- Switch render device to GPU Compute
- Switch viewport more to Rendered

Pull Request: https://projects.blender.org/blender/blender/pulls/119867
This commit is contained in:
Sergey Sharybin 2024-03-25 11:36:15 +01:00 committed by Sergey Sharybin
parent 7e2d54e786
commit bffcb000e8
1 changed files with 3 additions and 3 deletions

View File

@ -106,7 +106,7 @@ struct ShaderCache {
friend ShaderCache *get_shader_cache(id<MTLDevice> mtlDevice);
void compile_thread_func(int thread_index);
void compile_thread_func();
using PipelineCollection = std::vector<unique_ptr<MetalKernelPipeline>>;
@ -174,7 +174,7 @@ void ShaderCache::wait_for_all()
}
}
void ShaderCache::compile_thread_func(int /*thread_index*/)
void ShaderCache::compile_thread_func()
{
while (running) {
@ -309,7 +309,7 @@ void ShaderCache::load_kernel(DeviceKernel device_kernel,
metal_printf("Spawning %d Cycles kernel compilation threads\n", max_mtlcompiler_threads);
for (int i = 0; i < max_mtlcompiler_threads; i++) {
compile_threads.push_back(std::thread([&] { compile_thread_func(i); }));
compile_threads.push_back(std::thread([this] { this->compile_thread_func(); }));
}
}
}