EEVEE-Next: Async read back statistic and result buffers #120048

Open
Jeroen Bakker wants to merge 1 commits from Jeroen-Bakker/blender:metal/barrier-buffer-update into main

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

View File

@ -931,6 +931,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
inst_.manager->submit(irradiance_bounds_ps_);
GPU_memory_barrier(GPU_BARRIER_BUFFER_UPDATE);
capture_info_buf_.async_flush_to_host();
capture_info_buf_.read();
auto ordered_int_bits_to_float = [](int32_t int_value) -> float {
@ -974,6 +975,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
/* Allocate surfel pool. */
GPU_memory_barrier(GPU_BARRIER_BUFFER_UPDATE);
capture_info_buf_.async_flush_to_host();
capture_info_buf_.read();
if (capture_info_buf_.surfel_len == 0) {
/* No surfel to allocated. */
@ -1023,6 +1025,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
/* Sync with any other following pass using the surfel buffer. */
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
/* Read back so that following push_update will contain correct surfel count. */
capture_info_buf_.async_flush_to_host();
capture_info_buf_.read();
DRW_stats_group_end();
@ -1162,7 +1165,9 @@ void IrradianceBake::read_surfels(LightProbeGridCacheFrame *cache_frame)
}
GPU_memory_barrier(GPU_BARRIER_BUFFER_UPDATE);
capture_info_buf_.async_flush_to_host();
capture_info_buf_.read();
surfels_buf_.async_flush_to_host();
surfels_buf_.read();
cache_frame->surfels_len = capture_info_buf_.surfel_len;

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) {