Compositor: Enable lock-free GPU context activation on macOS

This required to apply a small fix in the Metal texture uploader.

Without synchronization pixels of a wrong pass can be uploaded to
a wrong texture. This is because this code path is heavily reusing
temporary allocations, and at some point the allocation is not
considered as still in use, unless the command buffer used by the
texture uploader is submitted.

Ref #118919

Pull Request: https://projects.blender.org/blender/blender/pulls/118920
This commit is contained in:
Sergey Sharybin 2024-03-01 14:38:09 +01:00 committed by Sergey Sharybin
parent c3d3528280
commit 3fcd7ccbc0
2 changed files with 2 additions and 14 deletions

View File

@ -1122,6 +1122,8 @@ void gpu::MTLTexture::update_sub(
/* Decrement texture reference counts. This ensures temporary texture views are released. */
[texture_handle release];
ctx->main_command_buffer.submit(false);
/* Release temporary staging buffer allocation.
* NOTE: Allocation will be tracked with command submission and released once no longer in use.
*/

View File

@ -508,13 +508,6 @@ class RealtimeCompositor {
* to avoid them blocking each other. */
BLI_assert(!BLI_thread_is_main() || G.background);
/* The realtime compositor uses GPU module and does not rely on the draw manager, or its global
* state. This means that activation of GPU context does not require lock of the main thread.
*
* However, while this has been tested on Linux and works well, on macOS it causes to
* spontaneous invalid colors in the composite output. The Windows has not been extensively
* tested yet. */
#if defined(__linux__) || defined(_WIN32)
if (G.background) {
/* In the background mode the system context of the render engine might be nullptr, which
* forces some code paths which more tightly couple it with the draw manager.
@ -529,9 +522,6 @@ class RealtimeCompositor {
GPU_render_begin();
WM_system_gpu_context_activate(re_system_gpu_context);
GPU_context_active_set(static_cast<GPUContext *>(re_blender_gpu_context));
#else
DRW_render_context_enable(&render_);
#endif
context_->update_input_data(input_data);
@ -546,14 +536,10 @@ class RealtimeCompositor {
context_->viewer_output_to_viewer_image();
texture_pool_->free_unused_and_reset();
#if defined(__linux__) || defined(_WIN32)
GPU_flush();
GPU_render_end();
GPU_context_active_set(nullptr);
WM_system_gpu_context_release(re_system_gpu_context);
#else
DRW_render_context_disable(&render_);
#endif
}
};