Blender V5.0
graphics_interop.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifdef WITH_METAL
6
8
10
12
13MetalDeviceGraphicsInterop::MetalDeviceGraphicsInterop(MetalDeviceQueue *queue)
14 : queue_(queue), device_(static_cast<MetalDevice *>(queue->device))
15{
16}
17
18MetalDeviceGraphicsInterop::~MetalDeviceGraphicsInterop() = default;
19
20void MetalDeviceGraphicsInterop::set_buffer(GraphicsInteropBuffer &interop_buffer)
21{
22 if (interop_buffer.is_empty()) {
23 mem_.mtlBuffer = nullptr;
24 size_ = 0;
25 return;
26 }
27
28 need_zero_ |= interop_buffer.take_zero();
29
30 if (!interop_buffer.has_new_handle()) {
31 return;
32 }
33
34 mem_.mtlBuffer = reinterpret_cast<id<MTLBuffer>>(interop_buffer.take_handle());
35 size_ = interop_buffer.get_size();
36}
37
38device_ptr MetalDeviceGraphicsInterop::map()
39{
40 if (mem_.mtlBuffer && need_zero_) {
41 memset([mem_.mtlBuffer contents], 0, size_);
42 need_zero_ = false;
43 }
44
45 return device_ptr(&mem_);
46}
47
48void MetalDeviceGraphicsInterop::unmap() {}
49
51
52#endif
#define CCL_NAMESPACE_END
uint64_t device_ptr
Definition types_base.h:44