| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
struct MetalDeviceProfile { |
| 87 |
enum class Platform : uint32_t { |
| 88 |
macOS = 0, |
| 89 |
iOS = 1, |
| 90 |
visionOS = 2, |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 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; |
| 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 |
}; |