Path: blob/master/drivers/metal/metal_device_properties.h
21826 views
/**************************************************************************/1/* metal_device_properties.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/**************************************************************************/33/* */34/* Portions of this code were derived from MoltenVK. */35/* */36/* Copyright (c) 2015-2023 The Brenwill Workshop Ltd. */37/* (http://www.brenwill.com) */38/* */39/* Licensed under the Apache License, Version 2.0 (the "License"); */40/* you may not use this file except in compliance with the License. */41/* You may obtain a copy of the License at */42/* */43/* http://www.apache.org/licenses/LICENSE-2.0 */44/* */45/* Unless required by applicable law or agreed to in writing, software */46/* distributed under the License is distributed on an "AS IS" BASIS, */47/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */48/* implied. See the License for the specific language governing */49/* permissions and limitations under the License. */50/**************************************************************************/5152#include "servers/rendering/rendering_device_driver.h"5354#include <Metal/Metal.hpp>55#include <cstddef>5657/** The buffer index to use for vertex content. */58const static uint32_t VERT_CONTENT_BUFFER_INDEX = 0;59const static uint32_t MAX_COLOR_ATTACHMENT_COUNT = 8;6061enum SampleCount : NS::UInteger {62SampleCount1 = (1UL << 0),63SampleCount2 = (1UL << 1),64SampleCount4 = (1UL << 2),65SampleCount8 = (1UL << 3),66SampleCount16 = (1UL << 4),67SampleCount32 = (1UL << 5),68SampleCount64 = (1UL << 6),69};7071_FORCE_INLINE_ SampleCount operator|(SampleCount a, SampleCount b) {72return static_cast<SampleCount>(static_cast<NS::UInteger>(a) | static_cast<NS::UInteger>(b));73}7475_FORCE_INLINE_ SampleCount &operator|=(SampleCount &a, SampleCount b) {76return a = a | b;77}7879_FORCE_INLINE_ SampleCount operator<<(SampleCount a, int shift) {80return static_cast<SampleCount>(static_cast<NS::UInteger>(a) << shift);81}8283_FORCE_INLINE_ SampleCount &operator<<=(SampleCount &a, int shift) {84return a = a << shift;85}8687struct API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalFeatures {88/// Maximum version of the Metal Shading Language version available.89uint32_t msl_max_version = 0;90/*! @brief Target version of the Metal Shading Language used to translate shaders.91*92* This can be used to override the features used to generate shaders. Primarily93* for engine developers for testing.94*/95uint32_t msl_target_version = 0;96MTL::GPUFamily highestFamily = MTL::GPUFamilyApple4;97bool supportsBCTextureCompression = false;98bool supportsDepth24Stencil8 = false;99bool supports32BitFloatFiltering = false;100bool supports32BitMSAA = false;101bool supportsMac = TARGET_OS_OSX;102SampleCount supportedSampleCounts = SampleCount1;103long hostMemoryPageSize = 0;104bool layeredRendering = false;105bool multisampleLayeredRendering = false;106bool quadPermute = false; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */107bool simdPermute = false; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */108bool simdReduction = false; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */109bool tessellationShader = false; /**< If true, tessellation shaders are supported. */110bool imageCubeArray = false; /**< If true, image cube arrays are supported. */111MTL::ArgumentBuffersTier argument_buffers_tier = MTL::ArgumentBuffersTier1;112bool needs_arg_encoders = true; /**< If true, argument encoders are required to encode arguments into an argument buffer. */113bool use_argument_buffers = true; /**< If true, argument buffers are can be used instead of slot binding, if available. */114bool metal_fx_spatial = false; /**< If true, Metal FX spatial functions are supported. */115bool metal_fx_temporal = false; /**< If true, Metal FX temporal functions are supported. */116bool supports_gpu_address = false; /**< If true, referencing a GPU address in a shader is supported. */117bool supports_image_atomic_32_bit = false; /**< If true, 32-bit atomic operations on images are supported by the GPU. */118bool supports_image_atomic_64_bit = false; /**< If true, 64-bit atomic operations on images are supported by the GPU. */119bool supports_native_image_atomics = false; /**< If true, native image atomic operations are supported by the OS. */120bool supports_residency_sets = false; /**< If true, residency sets (MTLResidencySet) are supported by the OS. */121122/*!123* Check if argument buffers are fully supported, which requires tier 2 support and no need for argument encoders.124*/125_FORCE_INLINE_ bool argument_buffers_supported() const {126return argument_buffers_tier == MTL::ArgumentBuffersTier2 && needs_arg_encoders == false;127}128129/*!130* Check if argument buffers can be used, which requires that they are supported and that the user has enabled their use.131*/132_FORCE_INLINE_ bool argument_buffers_enabled() const {133return use_argument_buffers && argument_buffers_supported();134}135};136137struct MetalLimits {138uint64_t maxImageArrayLayers;139uint64_t maxFramebufferHeight;140uint64_t maxFramebufferWidth;141uint64_t maxImageDimension1D;142uint64_t maxImageDimension2D;143uint64_t maxImageDimension3D;144uint64_t maxImageDimensionCube;145uint64_t maxViewportDimensionX;146uint64_t maxViewportDimensionY;147MTL::Size maxThreadsPerThreadGroup;148MTL::Size maxComputeWorkGroupCount;149uint64_t maxBoundDescriptorSets;150uint64_t maxColorAttachments;151uint64_t maxTexturesPerArgumentBuffer;152uint64_t maxSamplersPerArgumentBuffer;153uint64_t maxBuffersPerArgumentBuffer;154uint64_t maxBufferLength;155uint64_t minUniformBufferOffsetAlignment;156uint64_t maxVertexDescriptorLayoutStride;157uint16_t maxViewports;158uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */159uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */160uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */161uint32_t maxVertexInputAttributes;162uint32_t maxVertexInputBindings;163uint32_t maxVertexInputBindingStride;164uint32_t maxDrawIndexedIndexValue;165uint32_t maxShaderVaryings;166uint32_t maxThreadGroupMemoryAllocation;167168double temporalScalerInputContentMinScale;169double temporalScalerInputContentMaxScale;170171uint32_t minSubgroupSize; /**< The minimum number of threads in a SIMD-group. */172uint32_t maxSubgroupSize; /**< The maximum number of threads in a SIMD-group. */173BitField<RDD::ShaderStage> subgroupSupportedShaderStages;174BitField<RDD::SubgroupOperations> subgroupSupportedOperations; /**< The subgroup operations supported by the device. */175};176177class API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalDeviceProperties {178private:179void init_features(MTL::Device *p_device);180void init_limits(MTL::Device *p_device);181void init_os_props();182183public:184MetalFeatures features;185MetalLimits limits;186187// maj * 10000 + min * 100 + patch188uint32_t os_version;189190SampleCount find_nearest_supported_sample_count(RDD::TextureSamples p_samples) const;191192MetalDeviceProperties(MTL::Device *p_device);193~MetalDeviceProperties();194195private:196static const SampleCount sample_count[RDD::TextureSamples::TEXTURE_SAMPLES_MAX];197};198199200