Blender V5.3
mtl_work_in_flight.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_time.hh"
10
11#include "mtl_work_in_flight.hh"
12
13namespace blender::gpu {
14
15MTLWorkInFlight::MTLWorkInFlight(unsigned int max_in_flight)
16{
18 BLI_assert(ctx);
19 gpu_fence_ = [ctx->device newSharedEvent];
20 async_timeline_values_.resize(max_in_flight);
21 async_timeline_values_.fill(0);
22}
23
25{
26 if (gpu_fence_ != nil) {
27 [gpu_fence_ release];
28 gpu_fence_ = nil;
29 }
30}
31
33{
34 async_timeline_values_.fill(0);
35 work_index_ = 0;
36}
37
39{
40 uint64_t async_timeline_prev = async_timeline_values_[work_index_];
41 if (async_timeline_prev > 0) {
42 if (gpu_fence_ != nil) {
43 while (gpu_fence_.signaledValue < async_timeline_prev) {
45 }
46 }
47 }
48}
49
51{
52 /* Perform render step between samples to allow flushing of freed GPUBackend resources. */
54 BLI_assert(ctx);
55 ctx->main_command_buffer.encode_signal_event(gpu_fence_, ++current_signal_value_);
56 ctx->flush();
57 async_timeline_values_[work_index_] = current_signal_value_;
58 work_index_ = (work_index_ + 1) % async_timeline_values_.size();
59}
60
61} // namespace blender::gpu
Platform independent time functions.
void encode_signal_event(id< MTLEvent > event, uint64_t value)
static MTLContext * get()
MTLCommandBufferManager main_command_buffer
MTLWorkInFlight(unsigned int max_in_flight)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
void BLI_time_sleep_ms(int ms)
Definition time.cc:91