Blender V4.3
cycles/device/metal/util.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#ifdef WITH_METAL
8
9# include <Metal/Metal.h>
10# include <string>
11
12# include "device/metal/device.h"
13# include "device/metal/kernel.h"
14# include "device/queue.h"
15
16# include "util/thread.h"
17
18# define metal_printf VLOG(4) << string_printf
19
21
22enum AppleGPUArchitecture {
23 APPLE_M1,
24 APPLE_M2,
25 APPLE_M2_BIG,
26 APPLE_M3,
27 /* Keep APPLE_UNKNOWN at the end of this enum to ensure that unknown future architectures get
28 * the most recent defaults when using comparison operators. */
29 APPLE_UNKNOWN,
30};
31
32/* Contains static Metal helper functions. */
33struct MetalInfo {
34 static vector<id<MTLDevice>> const &get_usable_devices();
35 static int get_apple_gpu_core_count(id<MTLDevice> device);
36 static AppleGPUArchitecture get_apple_gpu_architecture(id<MTLDevice> device);
37 static int optimal_sort_partition_elements();
38 static string get_device_name(id<MTLDevice> device);
39};
40
41/* Pool of MTLBuffers whose lifetime is linked to a single MTLCommandBuffer */
42class MetalBufferPool {
43 struct MetalBufferListEntry {
44 id<MTLBuffer> buffer;
45 id<MTLCommandBuffer> command_buffer;
46 };
47 std::vector<MetalBufferListEntry> temp_buffers;
48 thread_mutex buffer_mutex;
49 size_t total_temp_mem_size = 0;
50
51 public:
52 ~MetalBufferPool();
53
54 id<MTLBuffer> get_buffer(id<MTLDevice> device,
55 id<MTLCommandBuffer> command_buffer,
56 NSUInteger length,
57 MTLResourceOptions options,
58 const void *pointer,
59 Stats &stats);
60 void process_command_buffer_completion(id<MTLCommandBuffer> command_buffer);
61};
62
64
65#endif /* WITH_METAL */
CCL_NAMESPACE_BEGIN struct Options options
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29