Path: blob/master/drivers/metal/metal_device_profile.cpp
12197 views
/**************************************************************************/1/* metal_device_profile.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "metal_device_profile.h"3132#include "metal_utils.h"3334Mutex MetalDeviceProfile::profiles_lock;35HashMap<MetalDeviceProfile::ProfileKey, MetalDeviceProfile> MetalDeviceProfile::profiles;3637const MetalDeviceProfile *MetalDeviceProfile::get_profile(Platform p_platform, GPU p_gpu, MinOsVersion p_min_os_version) {38DEV_ASSERT(p_platform == Platform::macOS || p_platform == Platform::iOS || p_platform == Platform::visionOS);3940MutexLock lock(profiles_lock);4142ProfileKey key(p_min_os_version, p_platform, p_gpu);43if (MetalDeviceProfile *profile = profiles.getptr(key)) {44return profile;45}4647MetalDeviceProfile res;48res.platform = p_platform;49res.gpu = p_gpu;50res.min_os_version = p_min_os_version;5152switch (p_platform) {53case Platform::macOS: {54if (p_min_os_version >= os_version::MACOS_26_0) {55res.features.msl_version = MSL_VERSION_40;56} else if (p_min_os_version >= os_version::MACOS_15_0) {57res.features.msl_version = MSL_VERSION_32;58} else if (p_min_os_version >= os_version::MACOS_14_0) {59res.features.msl_version = MSL_VERSION_31;60} else if (p_min_os_version >= os_version::MACOS_13_0) {61res.features.msl_version = MSL_VERSION_30;62} else if (p_min_os_version >= os_version::MACOS_12_0) {63res.features.msl_version = MSL_VERSION_24;64} else {65res.features.msl_version = MSL_VERSION_23;66}67res.features.use_argument_buffers = p_min_os_version >= os_version::MACOS_13_0;68res.features.simdPermute = true;69} break;7071case Platform::iOS: {72if (p_min_os_version >= os_version::IOS_26_0) {73res.features.msl_version = MSL_VERSION_40;74} else if (p_min_os_version >= os_version::IOS_18_0) {75res.features.msl_version = MSL_VERSION_32;76} else if (p_min_os_version >= os_version::IOS_17_0) {77res.features.msl_version = MSL_VERSION_31;78} else if (p_min_os_version >= os_version::IOS_16_0) {79res.features.msl_version = MSL_VERSION_30;80} else if (p_min_os_version >= os_version::IOS_15_0) {81res.features.msl_version = MSL_VERSION_24;82} else {83res.features.msl_version = MSL_VERSION_23;84}8586switch (p_gpu) {87case GPU::Apple1:88case GPU::Apple2:89case GPU::Apple3:90case GPU::Apple4:91case GPU::Apple5: {92res.features.simdPermute = false;93res.features.use_argument_buffers = false;94} break;95case GPU::Apple6:96case GPU::Apple7:97case GPU::Apple8:98case GPU::Apple9: {99res.features.use_argument_buffers = p_min_os_version >= os_version::IOS_16_0;100res.features.simdPermute = true;101} break;102}103} break;104105case Platform::visionOS: {106if (p_min_os_version >= os_version::VISIONOS_26_0) {107res.features.msl_version = MSL_VERSION_40;108} else if (p_min_os_version >= os_version::VISIONOS_02_4) {109res.features.msl_version = MSL_VERSION_32;110} else {111ERR_FAIL_V_MSG(nullptr, "visionOS 2.4 is the minimum supported version for visionOS.");112}113114switch (p_gpu) {115case GPU::Apple8:116case GPU::Apple9: {117res.features.use_argument_buffers = true;118res.features.simdPermute = true;119} break;120default: {121CRASH_NOW_MSG("visionOS hardware has a minimum Apple8 GPU.");122}123}124} break;125}126127return &profiles.insert(key, res)->value;128}129130131