Blender  V3.3
cycles/device/metal/util.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2021-2022 Blender Foundation */
3 
4 #pragma once
5 
6 #ifdef WITH_METAL
7 
8 # include <Metal/Metal.h>
9 # include <string>
10 
11 # include "device/metal/device.h"
12 # include "device/metal/kernel.h"
13 # include "device/queue.h"
14 
15 # include "util/thread.h"
16 
17 # define metal_printf VLOG(4) << string_printf
18 
20 
21 enum MetalGPUVendor {
22  METAL_GPU_UNKNOWN = 0,
23  METAL_GPU_APPLE = 1,
24  METAL_GPU_AMD = 2,
25  METAL_GPU_INTEL = 3,
26 };
27 
28 enum AppleGPUArchitecture {
29  APPLE_UNKNOWN,
30  APPLE_M1,
31  APPLE_M2,
32 };
33 
34 /* Contains static Metal helper functions. */
35 struct MetalInfo {
36  static vector<id<MTLDevice>> const &get_usable_devices();
37  static int get_apple_gpu_core_count(id<MTLDevice> device);
38  static MetalGPUVendor get_device_vendor(id<MTLDevice> device);
39  static AppleGPUArchitecture get_apple_gpu_architecture(id<MTLDevice> device);
40  static int optimal_sort_partition_elements(id<MTLDevice> device);
41  static string get_device_name(id<MTLDevice> device);
42 };
43 
44 /* Pool of MTLBuffers whose lifetime is linked to a single MTLCommandBuffer */
45 class MetalBufferPool {
46  struct MetalBufferListEntry {
47  MetalBufferListEntry(id<MTLBuffer> buffer, id<MTLCommandBuffer> command_buffer)
48  : buffer(buffer), command_buffer(command_buffer)
49  {
50  }
51 
52  MetalBufferListEntry() = delete;
53 
54  id<MTLBuffer> buffer;
55  id<MTLCommandBuffer> command_buffer;
56  };
57  std::vector<MetalBufferListEntry> buffer_free_list;
58  std::vector<MetalBufferListEntry> buffer_in_use_list;
59  thread_mutex buffer_mutex;
60  size_t total_temp_mem_size = 0;
61 
62  public:
63  MetalBufferPool() = default;
64  ~MetalBufferPool();
65 
66  id<MTLBuffer> get_buffer(id<MTLDevice> device,
67  id<MTLCommandBuffer> command_buffer,
68  NSUInteger length,
69  MTLResourceOptions options,
70  const void *pointer,
71  Stats &stats);
72  void process_command_buffer_completion(id<MTLCommandBuffer> command_buffer);
73 };
74 
76 
77 #endif /* WITH_METAL */
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
CCL_NAMESPACE_BEGIN struct Options options
ccl_global float * buffer
T length(const vec_base< T, Size > &a)
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition: thread.h:27