-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
Metal: Stable argument buffers; GPU rendering crashes; visionOS exports #111976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Repiteo
merged 1 commit into
godotengine:master
from
stuartcarnie:metal_stable_bindings
Oct 28, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /**************************************************************************/ | ||
| /* metal_device_profile.cpp */ | ||
| /**************************************************************************/ | ||
| /* This file is part of: */ | ||
| /* GODOT ENGINE */ | ||
| /* https://godotengine.org */ | ||
| /**************************************************************************/ | ||
| /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
| /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
| /* */ | ||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | ||
| /* a copy of this software and associated documentation files (the */ | ||
| /* "Software"), to deal in the Software without restriction, including */ | ||
| /* without limitation the rights to use, copy, modify, merge, publish, */ | ||
| /* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
| /* permit persons to whom the Software is furnished to do so, subject to */ | ||
| /* the following conditions: */ | ||
| /* */ | ||
| /* The above copyright notice and this permission notice shall be */ | ||
| /* included in all copies or substantial portions of the Software. */ | ||
| /* */ | ||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
| /**************************************************************************/ | ||
|
|
||
| #include "metal_device_profile.h" | ||
AThousandShips marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include "metal_utils.h" | ||
|
|
||
| Mutex MetalDeviceProfile::profiles_lock; | ||
| HashMap<MetalDeviceProfile::ProfileKey, MetalDeviceProfile> MetalDeviceProfile::profiles; | ||
|
|
||
| const MetalDeviceProfile *MetalDeviceProfile::get_profile(Platform p_platform, GPU p_gpu, MinOsVersion p_min_os_version) { | ||
| DEV_ASSERT(p_platform == Platform::macOS || p_platform == Platform::iOS || p_platform == Platform::visionOS); | ||
|
|
||
| MutexLock lock(profiles_lock); | ||
|
|
||
| ProfileKey key(p_min_os_version, p_platform, p_gpu); | ||
| if (MetalDeviceProfile *profile = profiles.getptr(key)) { | ||
| return profile; | ||
| } | ||
|
|
||
| MetalDeviceProfile res; | ||
| res.platform = p_platform; | ||
| res.gpu = p_gpu; | ||
| res.min_os_version = p_min_os_version; | ||
|
|
||
| switch (p_platform) { | ||
| case Platform::macOS: { | ||
| if (p_min_os_version >= os_version::MACOS_26_0) { | ||
| res.features.msl_version = MSL_VERSION_40; | ||
| } else if (p_min_os_version >= os_version::MACOS_15_0) { | ||
| res.features.msl_version = MSL_VERSION_32; | ||
| } else if (p_min_os_version >= os_version::MACOS_14_0) { | ||
| res.features.msl_version = MSL_VERSION_31; | ||
| } else if (p_min_os_version >= os_version::MACOS_13_0) { | ||
| res.features.msl_version = MSL_VERSION_30; | ||
| } else if (p_min_os_version >= os_version::MACOS_12_0) { | ||
| res.features.msl_version = MSL_VERSION_24; | ||
| } else { | ||
| res.features.msl_version = MSL_VERSION_23; | ||
| } | ||
| res.features.use_argument_buffers = p_min_os_version >= os_version::MACOS_13_0; | ||
| res.features.simdPermute = true; | ||
| } break; | ||
|
|
||
| case Platform::iOS: { | ||
| if (p_min_os_version >= os_version::IOS_26_0) { | ||
| res.features.msl_version = MSL_VERSION_40; | ||
| } else if (p_min_os_version >= os_version::IOS_18_0) { | ||
| res.features.msl_version = MSL_VERSION_32; | ||
| } else if (p_min_os_version >= os_version::IOS_17_0) { | ||
| res.features.msl_version = MSL_VERSION_31; | ||
| } else if (p_min_os_version >= os_version::IOS_16_0) { | ||
| res.features.msl_version = MSL_VERSION_30; | ||
| } else if (p_min_os_version >= os_version::IOS_15_0) { | ||
| res.features.msl_version = MSL_VERSION_24; | ||
| } else { | ||
| res.features.msl_version = MSL_VERSION_23; | ||
| } | ||
|
|
||
| switch (p_gpu) { | ||
| case GPU::Apple1: | ||
| case GPU::Apple2: | ||
| case GPU::Apple3: | ||
| case GPU::Apple4: | ||
| case GPU::Apple5: { | ||
| res.features.simdPermute = false; | ||
| res.features.use_argument_buffers = false; | ||
| } break; | ||
| case GPU::Apple6: | ||
| case GPU::Apple7: | ||
| case GPU::Apple8: | ||
| case GPU::Apple9: { | ||
| res.features.use_argument_buffers = p_min_os_version >= os_version::IOS_16_0; | ||
| res.features.simdPermute = true; | ||
| } break; | ||
| } | ||
| } break; | ||
|
|
||
| case Platform::visionOS: { | ||
| if (p_min_os_version >= os_version::VISIONOS_26_0) { | ||
| res.features.msl_version = MSL_VERSION_40; | ||
| } else if (p_min_os_version >= os_version::VISIONOS_02_4) { | ||
| res.features.msl_version = MSL_VERSION_32; | ||
| } else { | ||
| ERR_FAIL_V_MSG(nullptr, "visionOS 2.4 is the minimum supported version for visionOS."); | ||
| } | ||
|
|
||
| switch (p_gpu) { | ||
| case GPU::Apple8: | ||
| case GPU::Apple9: { | ||
| res.features.use_argument_buffers = true; | ||
| res.features.simdPermute = true; | ||
| } break; | ||
| default: { | ||
| CRASH_NOW_MSG("visionOS hardware has a minimum Apple8 GPU."); | ||
| } | ||
| } | ||
| } break; | ||
| } | ||
|
|
||
| return &profiles.insert(key, res)->value; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /**************************************************************************/ | ||
| /* metal_device_profile.h */ | ||
| /**************************************************************************/ | ||
| /* This file is part of: */ | ||
| /* GODOT ENGINE */ | ||
| /* https://godotengine.org */ | ||
| /**************************************************************************/ | ||
| /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
| /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
| /* */ | ||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | ||
| /* a copy of this software and associated documentation files (the */ | ||
| /* "Software"), to deal in the Software without restriction, including */ | ||
| /* without limitation the rights to use, copy, modify, merge, publish, */ | ||
| /* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
| /* permit persons to whom the Software is furnished to do so, subject to */ | ||
| /* the following conditions: */ | ||
| /* */ | ||
| /* The above copyright notice and this permission notice shall be */ | ||
| /* included in all copies or substantial portions of the Software. */ | ||
| /* */ | ||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
| /**************************************************************************/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "core/os/mutex.h" | ||
| #include "core/string/ustring.h" | ||
| #include "core/templates/hash_map.h" | ||
| #include "core/typedefs.h" | ||
|
|
||
| class MinOsVersion { | ||
| uint32_t version; | ||
|
|
||
| public: | ||
| String to_compiler_os_version() const; | ||
| bool is_null() const { return version == UINT32_MAX; } | ||
| bool is_valid() const { return version != UINT32_MAX; } | ||
|
|
||
| MinOsVersion(const String &p_version); | ||
| constexpr explicit MinOsVersion(uint32_t p_version) : | ||
| version(p_version) {} | ||
| constexpr MinOsVersion(uint32_t p_major, uint32_t p_minor, uint32_t p_patch = 0) : | ||
| version(p_major * 10000 + p_minor * 100 + p_patch) {} | ||
| constexpr MinOsVersion() : | ||
| version(UINT32_MAX) {} | ||
|
|
||
| bool operator>(uint32_t p_other) { | ||
| return version > p_other; | ||
| } | ||
| constexpr operator uint32_t() const { return version; } | ||
| }; | ||
|
|
||
| namespace os_version { | ||
|
|
||
| constexpr MinOsVersion MACOS_26_0(26'00'00); | ||
| constexpr MinOsVersion MACOS_15_0(15'00'00); | ||
| constexpr MinOsVersion MACOS_14_0(14'00'00); | ||
| constexpr MinOsVersion MACOS_13_0(13'00'00); | ||
| constexpr MinOsVersion MACOS_12_0(12'00'00); | ||
| constexpr MinOsVersion MACOS_11_0(11'00'00); | ||
|
|
||
| constexpr MinOsVersion IOS_26_0(26'00'00); | ||
| constexpr MinOsVersion IOS_18_0(18'00'00); | ||
| constexpr MinOsVersion IOS_17_0(17'00'00); | ||
| constexpr MinOsVersion IOS_16_0(16'00'00); | ||
| constexpr MinOsVersion IOS_15_0(15'00'00); | ||
|
|
||
| constexpr MinOsVersion VISIONOS_26_0(26'00'00); | ||
| constexpr MinOsVersion VISIONOS_02_4(02'04'00); | ||
|
|
||
| } //namespace os_version | ||
|
|
||
| /// @brief A minimal structure that defines a device profile for Metal. | ||
| /// | ||
| /// This structure is used by the `RenderingShaderContainerMetal` class to | ||
| /// determine options for compiling SPIR-V to Metal source. It currently only | ||
| /// contains the minimum properties required to transform shaders from SPIR-V to Metal | ||
| /// and potentially compile to a `.metallib`. | ||
| struct MetalDeviceProfile { | ||
| enum class Platform : uint32_t { | ||
| macOS = 0, | ||
| iOS = 1, | ||
| visionOS = 2, | ||
| }; | ||
|
|
||
| /*! @brief The GPU family. | ||
| * | ||
| * NOTE: These values match Apple's MTLGPUFamily | ||
| */ | ||
| enum class GPU : uint32_t { | ||
| Apple1 = 1001, | ||
| Apple2 = 1002, | ||
| Apple3 = 1003, | ||
| Apple4 = 1004, | ||
| Apple5 = 1005, | ||
| Apple6 = 1006, | ||
| Apple7 = 1007, | ||
| Apple8 = 1008, | ||
| Apple9 = 1009, | ||
| }; | ||
|
|
||
| enum class ArgumentBuffersTier : uint32_t { | ||
| Tier1 = 0, | ||
| Tier2 = 1, | ||
| }; | ||
|
|
||
| struct Features { | ||
| uint32_t msl_version = 0; | ||
| bool use_argument_buffers = false; | ||
| bool simdPermute = false; | ||
| }; | ||
|
|
||
| Platform platform = Platform::macOS; | ||
| GPU gpu = GPU::Apple4; | ||
| MinOsVersion min_os_version; | ||
| Features features; | ||
|
|
||
| static const MetalDeviceProfile *get_profile(Platform p_platform, GPU p_gpu, MinOsVersion p_min_os_version); | ||
|
|
||
| MetalDeviceProfile() = default; | ||
|
|
||
| private: | ||
| static Mutex profiles_lock; ///< Mutex to protect access to the profiles map. | ||
|
|
||
| struct ProfileKey { | ||
| friend struct HashMapHasherDefaultImpl<ProfileKey>; | ||
| union { | ||
| struct { | ||
| uint32_t min_os_version; | ||
| uint16_t platform; | ||
| uint16_t gpu; | ||
| }; | ||
| uint64_t value = 0; | ||
| }; | ||
|
|
||
| ProfileKey() = default; | ||
| ProfileKey(MinOsVersion p_min_os_version, Platform p_platform, GPU p_gpu) : | ||
| min_os_version(p_min_os_version), platform((uint16_t)p_platform), gpu((uint16_t)p_gpu) {} | ||
|
|
||
| _FORCE_INLINE_ uint32_t hash() const { | ||
| return hash_one_uint64(value); | ||
| } | ||
|
|
||
| bool operator==(const ProfileKey &p_other) const { | ||
| return value == p_other.value; | ||
| } | ||
| }; | ||
|
|
||
| static HashMap<ProfileKey, MetalDeviceProfile> profiles; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Device Profile is now keyed by platform (macOS, iOS, etc), GPU and minimum OS version. This ensures that when generating or baking the shader, it selects the correct features based on the target OS also.