Blender
V5.3
source
blender
gpu
metal
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
13
namespace
blender::gpu
{
14
15
MTLWorkInFlight::MTLWorkInFlight
(
unsigned
int
max_in_flight)
16
{
17
MTLContext
*ctx =
MTLContext::get
();
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
24
MTLWorkInFlight::~MTLWorkInFlight
()
25
{
26
if
(gpu_fence_ != nil) {
27
[gpu_fence_ release];
28
gpu_fence_ = nil;
29
}
30
}
31
32
void
MTLWorkInFlight::reset
()
33
{
34
async_timeline_values_.fill(0);
35
work_index_ = 0;
36
}
37
38
void
MTLWorkInFlight::begin_work
()
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) {
44
BLI_time_sleep_ms
(1);
45
}
46
}
47
}
48
}
49
50
void
MTLWorkInFlight::end_work
()
51
{
52
/* Perform render step between samples to allow flushing of freed GPUBackend resources. */
53
MTLContext
*ctx =
MTLContext::get
();
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
BLI_time.hh
Platform independent time functions.
blender::gpu::MTLCommandBufferManager::encode_signal_event
void encode_signal_event(id< MTLEvent > event, uint64_t value)
Definition
mtl_command_buffer.mm:752
blender::gpu::MTLContext
Definition
mtl_context.hh:620
blender::gpu::MTLContext::get
static MTLContext * get()
Definition
mtl_context.hh:738
blender::gpu::MTLContext::device
id< MTLDevice > device
Definition
mtl_context.hh:637
blender::gpu::MTLContext::flush
void flush() override
Definition
mtl_context.mm:448
blender::gpu::MTLContext::main_command_buffer
MTLCommandBufferManager main_command_buffer
Definition
mtl_context.hh:651
blender::gpu::MTLWorkInFlight::~MTLWorkInFlight
~MTLWorkInFlight() override
Definition
mtl_work_in_flight.mm:24
blender::gpu::MTLWorkInFlight::reset
void reset() override
Definition
mtl_work_in_flight.mm:32
blender::gpu::MTLWorkInFlight::begin_work
void begin_work() override
Definition
mtl_work_in_flight.mm:38
blender::gpu::MTLWorkInFlight::end_work
void end_work() override
Definition
mtl_work_in_flight.mm:50
blender::gpu::MTLWorkInFlight::MTLWorkInFlight
MTLWorkInFlight(unsigned int max_in_flight)
Definition
mtl_work_in_flight.mm:15
mtl_work_in_flight.hh
blender::gpu
Definition
blf_internal_types.hh:35
blender::BLI_assert
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
blender::uint64_t
unsigned __int64 uint64_t
Definition
BKE_text.h:91
blender::BLI_time_sleep_ms
void BLI_time_sleep_ms(int ms)
Definition
time.cc:91
Generated on
for Blender by
doxygen
1.18.0