Metal: Wait for finish when buffers are updated #120050

Closed
Jeroen Bakker wants to merge 2 commits from Jeroen-Bakker/blender:metal/barrier-buffer-update-b into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 5 additions and 4 deletions

View File

@ -579,6 +579,10 @@ void MTLStateManager::issue_barrier(eGPUBarrier barrier_bits)
BLI_assert(ctx);
ctx->main_command_buffer.insert_memory_barrier(barrier_bits, before_stages, after_stages);
if (barrier_bits & GPU_BARRIER_BUFFER_UPDATE) {
GPU_finish();
}
}
MTLFence::~MTLFence()

View File

@ -426,16 +426,13 @@ void MTLStorageBuf::read(void *data)
else {
/** Direct storage buffer read. */
/* If we have a synchronization event from a prior memory sync, ensure memory is fully synced.
* Otherwise, assume read is synchronous and stall until in-flight work is complete. */
* Otherwise, assume read is asynchronous. */
if (gpu_write_fence_ != nil) {
/* Ensure the GPU updates are visible to the host before reading. */
while (gpu_write_fence_.signaledValue < host_read_signal_value_) {
BLI_time_sleep_ms(1);
}
}
else {
GPU_finish();
}
/* Managed buffers need to be explicitly flushed back to host. */
if (metal_buffer_->get_resource_options() & MTLResourceStorageModeManaged) {