Debian Codegraph @

drivers/metal/metal_device_profile.h

raw symbols SCIP
1 /**************************************************************************/
2 /* metal_device_profile.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/os/mutex.h"
34 #include "core/string/ustring.h"
35 #include "core/templates/hash_map.h"
36 #include "core/typedefs.h"
37
38 class MinOsVersion {
39 uint32_t version;
40
41 public:
42 String to_compiler_os_version() const;
43 bool is_null() const { return version == UINT32_MAX; }
44 bool is_valid() const { return version != UINT32_MAX; }
45
46 MinOsVersion(const String &p_version);
47 constexpr explicit MinOsVersion(uint32_t p_version) :
48 version(p_version) {}
49 constexpr MinOsVersion(uint32_t p_major, uint32_t p_minor, uint32_t p_patch = 0) :
50 version(p_major * 10000 + p_minor * 100 + p_patch) {}
51 constexpr MinOsVersion() :
52 version(UINT32_MAX) {}
53
54 bool operator>(uint32_t p_other) {
55 return version > p_other;
56 }
57 constexpr operator uint32_t() const { return version; }
58 };
59
60 namespace os_version {
61
62 constexpr MinOsVersion MACOS_26_0(26'00'00);
63 constexpr MinOsVersion MACOS_15_0(15'00'00);
64 constexpr MinOsVersion MACOS_14_0(14'00'00);
65 constexpr MinOsVersion MACOS_13_0(13'00'00);
66 constexpr MinOsVersion MACOS_12_0(12'00'00);
67 constexpr MinOsVersion MACOS_11_0(11'00'00);
68
69 constexpr MinOsVersion IOS_26_0(26'00'00);
70 constexpr MinOsVersion IOS_18_0(18'00'00);
71 constexpr MinOsVersion IOS_17_0(17'00'00);
72 constexpr MinOsVersion IOS_16_0(16'00'00);
73 constexpr MinOsVersion IOS_15_0(15'00'00);
74
75 constexpr MinOsVersion VISIONOS_26_0(26'00'00);
76 constexpr MinOsVersion VISIONOS_02_4(02'04'00);
77
78 } //namespace os_version
79
80 /// @brief A minimal structure that defines a device profile for Metal.
81 ///
82 /// This structure is used by the `RenderingShaderContainerMetal` class to
83 /// determine options for compiling SPIR-V to Metal source. It currently only
84 /// contains the minimum properties required to transform shaders from SPIR-V to Metal
85 /// and potentially compile to a `.metallib`.
86 struct MetalDeviceProfile {
87 enum class Platform : uint32_t {
88 macOS = 0,
89 iOS = 1,
90 visionOS = 2,
91 };
92
93 /*! @brief The GPU family.
94 *
95 * NOTE: These values match Apple's MTLGPUFamily
96 */
97 enum class GPU : uint32_t {
98 Apple1 = 1001,
99 Apple2 = 1002,
100 Apple3 = 1003,
101 Apple4 = 1004,
102 Apple5 = 1005,
103 Apple6 = 1006,
104 Apple7 = 1007,
105 Apple8 = 1008,
106 Apple9 = 1009,
107 };
108
109 enum class ArgumentBuffersTier : uint32_t {
110 Tier1 = 0,
111 Tier2 = 1,
112 };
113
114 struct Features {
115 uint32_t msl_version = 0;
116 bool use_argument_buffers = false;
117 bool simdPermute = false;
118 };
119
120 Platform platform = Platform::macOS;
121 GPU gpu = GPU::Apple4;
122 MinOsVersion min_os_version;
123 Features features;
124
125 static const MetalDeviceProfile *get_profile(Platform p_platform, GPU p_gpu, MinOsVersion p_min_os_version);
126
127 MetalDeviceProfile() = default;
128
129 private:
130 static Mutex profiles_lock; ///< Mutex to protect access to the profiles map.
131
132 struct ProfileKey {
133 friend struct HashMapHasherDefaultImpl<ProfileKey>;
134 union {
135 struct {
136 uint32_t min_os_version;
137 uint16_t platform;
138 uint16_t gpu;
139 };
140 uint64_t value = 0;
141 };
142
143 ProfileKey() = default;
144 ProfileKey(MinOsVersion p_min_os_version, Platform p_platform, GPU p_gpu) :
145 min_os_version(p_min_os_version), platform((uint16_t)p_platform), gpu((uint16_t)p_gpu) {}
146
147 _FORCE_INLINE_ uint32_t hash() const {
148 return hash_one_uint64(value);
149 }
150
151 bool operator==(const ProfileKey &p_other) const {
152 return value == p_other.value;
153 }
154 };
155
156 static HashMap<ProfileKey, MetalDeviceProfile> profiles;
157 };