Debian Codegraph @

drivers/metal/metal_device_profile.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* metal_device_profile.cpp */
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 #include "metal_device_profile.h"
32
33 #include "metal_utils.h"
34
35 Mutex MetalDeviceProfile::profiles_lock;
36 HashMap<MetalDeviceProfile::ProfileKey, MetalDeviceProfile> MetalDeviceProfile::profiles;
37
38 const MetalDeviceProfile *MetalDeviceProfile::get_profile(Platform p_platform, GPU p_gpu, MinOsVersion p_min_os_version) {
39 DEV_ASSERT(p_platform == Platform::macOS || p_platform == Platform::iOS || p_platform == Platform::visionOS);
40
41 MutexLock lock(profiles_lock);
42
43 ProfileKey key(p_min_os_version, p_platform, p_gpu);
44 if (MetalDeviceProfile *profile = profiles.getptr(key)) {
45 return profile;
46 }
47
48 MetalDeviceProfile res;
49 res.platform = p_platform;
50 res.gpu = p_gpu;
51 res.min_os_version = p_min_os_version;
52
53 switch (p_platform) {
54 case Platform::macOS: {
55 if (p_min_os_version >= os_version::MACOS_26_0) {
56 res.features.msl_version = MSL_VERSION_40;
57 } else if (p_min_os_version >= os_version::MACOS_15_0) {
58 res.features.msl_version = MSL_VERSION_32;
59 } else if (p_min_os_version >= os_version::MACOS_14_0) {
60 res.features.msl_version = MSL_VERSION_31;
61 } else if (p_min_os_version >= os_version::MACOS_13_0) {
62 res.features.msl_version = MSL_VERSION_30;
63 } else if (p_min_os_version >= os_version::MACOS_12_0) {
64 res.features.msl_version = MSL_VERSION_24;
65 } else {
66 res.features.msl_version = MSL_VERSION_23;
67 }
68 res.features.use_argument_buffers = p_min_os_version >= os_version::MACOS_13_0;
69 res.features.simdPermute = true;
70 } break;
71
72 case Platform::iOS: {
73 if (p_min_os_version >= os_version::IOS_26_0) {
74 res.features.msl_version = MSL_VERSION_40;
75 } else if (p_min_os_version >= os_version::IOS_18_0) {
76 res.features.msl_version = MSL_VERSION_32;
77 } else if (p_min_os_version >= os_version::IOS_17_0) {
78 res.features.msl_version = MSL_VERSION_31;
79 } else if (p_min_os_version >= os_version::IOS_16_0) {
80 res.features.msl_version = MSL_VERSION_30;
81 } else if (p_min_os_version >= os_version::IOS_15_0) {
82 res.features.msl_version = MSL_VERSION_24;
83 } else {
84 res.features.msl_version = MSL_VERSION_23;
85 }
86
87 switch (p_gpu) {
88 case GPU::Apple1:
89 case GPU::Apple2:
90 case GPU::Apple3:
91 case GPU::Apple4:
92 case GPU::Apple5: {
93 res.features.simdPermute = false;
94 res.features.use_argument_buffers = false;
95 } break;
96 case GPU::Apple6:
97 case GPU::Apple7:
98 case GPU::Apple8:
99 case GPU::Apple9: {
100 res.features.use_argument_buffers = p_min_os_version >= os_version::IOS_16_0;
101 res.features.simdPermute = true;
102 } break;
103 }
104 } break;
105
106 case Platform::visionOS: {
107 if (p_min_os_version >= os_version::VISIONOS_26_0) {
108 res.features.msl_version = MSL_VERSION_40;
109 } else if (p_min_os_version >= os_version::VISIONOS_02_4) {
110 res.features.msl_version = MSL_VERSION_32;
111 } else {
112 ERR_FAIL_V_MSG(nullptr, "visionOS 2.4 is the minimum supported version for visionOS.");
113 }
114
115 switch (p_gpu) {
116 case GPU::Apple8:
117 case GPU::Apple9: {
118 res.features.use_argument_buffers = true;
119 res.features.simdPermute = true;
120 } break;
121 default: {
122 CRASH_NOW_MSG("visionOS hardware has a minimum Apple8 GPU.");
123 }
124 }
125 } break;
126 }
127
128 return &profiles.insert(key, res)->value;
129 }