Path: blob/master/drivers/metal/metal_device_profile.h
12197 views
/**************************************************************************/1/* metal_device_profile.h */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#pragma once3132#include "core/os/mutex.h"33#include "core/string/ustring.h"34#include "core/templates/hash_map.h"35#include "core/typedefs.h"3637class MinOsVersion {38uint32_t version;3940public:41String to_compiler_os_version() const;42bool is_null() const { return version == UINT32_MAX; }43bool is_valid() const { return version != UINT32_MAX; }4445MinOsVersion(const String &p_version);46constexpr explicit MinOsVersion(uint32_t p_version) :47version(p_version) {}48constexpr MinOsVersion(uint32_t p_major, uint32_t p_minor, uint32_t p_patch = 0) :49version(p_major * 10000 + p_minor * 100 + p_patch) {}50constexpr MinOsVersion() :51version(UINT32_MAX) {}5253bool operator>(uint32_t p_other) {54return version > p_other;55}56constexpr operator uint32_t() const { return version; }57};5859namespace os_version {6061constexpr MinOsVersion MACOS_26_0(26'00'00);62constexpr MinOsVersion MACOS_15_0(15'00'00);63constexpr MinOsVersion MACOS_14_0(14'00'00);64constexpr MinOsVersion MACOS_13_0(13'00'00);65constexpr MinOsVersion MACOS_12_0(12'00'00);66constexpr MinOsVersion MACOS_11_0(11'00'00);6768constexpr MinOsVersion IOS_26_0(26'00'00);69constexpr MinOsVersion IOS_18_0(18'00'00);70constexpr MinOsVersion IOS_17_0(17'00'00);71constexpr MinOsVersion IOS_16_0(16'00'00);72constexpr MinOsVersion IOS_15_0(15'00'00);7374constexpr MinOsVersion VISIONOS_26_0(26'00'00);75constexpr MinOsVersion VISIONOS_02_4(02'04'00);7677} //namespace os_version7879/// @brief A minimal structure that defines a device profile for Metal.80///81/// This structure is used by the `RenderingShaderContainerMetal` class to82/// determine options for compiling SPIR-V to Metal source. It currently only83/// contains the minimum properties required to transform shaders from SPIR-V to Metal84/// and potentially compile to a `.metallib`.85struct MetalDeviceProfile {86enum class Platform : uint32_t {87macOS = 0,88iOS = 1,89visionOS = 2,90};9192/*! @brief The GPU family.93*94* NOTE: These values match Apple's MTLGPUFamily95*/96enum class GPU : uint32_t {97Apple1 = 1001,98Apple2 = 1002,99Apple3 = 1003,100Apple4 = 1004,101Apple5 = 1005,102Apple6 = 1006,103Apple7 = 1007,104Apple8 = 1008,105Apple9 = 1009,106};107108enum class ArgumentBuffersTier : uint32_t {109Tier1 = 0,110Tier2 = 1,111};112113struct Features {114uint32_t msl_version = 0;115bool use_argument_buffers = false;116bool simdPermute = false;117};118119Platform platform = Platform::macOS;120GPU gpu = GPU::Apple4;121MinOsVersion min_os_version;122Features features;123124static const MetalDeviceProfile *get_profile(Platform p_platform, GPU p_gpu, MinOsVersion p_min_os_version);125126MetalDeviceProfile() = default;127128private:129static Mutex profiles_lock; ///< Mutex to protect access to the profiles map.130131struct ProfileKey {132friend struct HashMapHasherDefaultImpl<ProfileKey>;133union {134struct {135uint32_t min_os_version;136uint16_t platform;137uint16_t gpu;138};139uint64_t value = 0;140};141142ProfileKey() = default;143ProfileKey(MinOsVersion p_min_os_version, Platform p_platform, GPU p_gpu) :144min_os_version(p_min_os_version), platform((uint16_t)p_platform), gpu((uint16_t)p_gpu) {}145146_FORCE_INLINE_ uint32_t hash() const {147return hash_one_uint64(value);148}149150bool operator==(const ProfileKey &p_other) const {151return value == p_other.value;152}153};154155static HashMap<ProfileKey, MetalDeviceProfile> profiles;156};157158159