Path: blob/master/drivers/metal/metal_device_properties.h
9973 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#import "servers/rendering/rendering_device.h"5354#import <Foundation/Foundation.h>55#import <Metal/Metal.h>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;6061typedef NS_OPTIONS(NSUInteger, SampleCount) {62SampleCount1 = (1UL << 0),63SampleCount2 = (1UL << 1),64SampleCount4 = (1UL << 2),65SampleCount8 = (1UL << 3),66SampleCount16 = (1UL << 4),67SampleCount32 = (1UL << 5),68SampleCount64 = (1UL << 6),69};7071struct API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalFeatures {72uint32_t mslVersionMajor = 0;73uint32_t mslVersionMinor = 0;74MTLGPUFamily highestFamily = MTLGPUFamilyApple4;75bool supportsBCTextureCompression = false;76bool supportsDepth24Stencil8 = false;77bool supports32BitFloatFiltering = false;78bool supports32BitMSAA = false;79bool supportsMac = TARGET_OS_OSX;80MTLLanguageVersion mslVersionEnum = MTLLanguageVersion1_2;81SampleCount supportedSampleCounts = SampleCount1;82long hostMemoryPageSize = 0;83bool layeredRendering = false;84bool multisampleLayeredRendering = false;85bool quadPermute = false; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */86bool simdPermute = false; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */87bool simdReduction = false; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */88bool tessellationShader = false; /**< If true, tessellation shaders are supported. */89bool imageCubeArray = false; /**< If true, image cube arrays are supported. */90MTLArgumentBuffersTier argument_buffers_tier = MTLArgumentBuffersTier1;91/// If true, argument encoders are required to encode arguments into an argument buffer.92bool needs_arg_encoders = true;93bool metal_fx_spatial = false; /**< If true, Metal FX spatial functions are supported. */94bool metal_fx_temporal = false; /**< If true, Metal FX temporal functions are supported. */95bool supports_gpu_address = false; /**< If true, referencing a GPU address in a shader is supported. */96bool supports_image_atomic_32_bit = false; /**< If true, 32-bit atomic operations on images are supported by the GPU. */97bool supports_image_atomic_64_bit = false; /**< If true, 64-bit atomic operations on images are supported by the GPU. */98bool supports_native_image_atomics = false; /**< If true, native image atomic operations are supported by the OS. */99};100101struct MetalLimits {102uint64_t maxImageArrayLayers;103uint64_t maxFramebufferHeight;104uint64_t maxFramebufferWidth;105uint64_t maxImageDimension1D;106uint64_t maxImageDimension2D;107uint64_t maxImageDimension3D;108uint64_t maxImageDimensionCube;109uint64_t maxViewportDimensionX;110uint64_t maxViewportDimensionY;111MTLSize maxThreadsPerThreadGroup;112MTLSize maxComputeWorkGroupCount;113uint64_t maxBoundDescriptorSets;114uint64_t maxColorAttachments;115uint64_t maxTexturesPerArgumentBuffer;116uint64_t maxSamplersPerArgumentBuffer;117uint64_t maxBuffersPerArgumentBuffer;118uint64_t maxBufferLength;119uint64_t minUniformBufferOffsetAlignment;120uint64_t maxVertexDescriptorLayoutStride;121uint16_t maxViewports;122uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */123uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */124uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */125uint32_t maxVertexInputAttributes;126uint32_t maxVertexInputBindings;127uint32_t maxVertexInputBindingStride;128uint32_t maxDrawIndexedIndexValue;129uint32_t maxShaderVaryings;130uint32_t maxThreadGroupMemoryAllocation;131132double temporalScalerInputContentMinScale;133double temporalScalerInputContentMaxScale;134135uint32_t minSubgroupSize; /**< The minimum number of threads in a SIMD-group. */136uint32_t maxSubgroupSize; /**< The maximum number of threads in a SIMD-group. */137BitField<RDD::ShaderStage> subgroupSupportedShaderStages;138BitField<RD::SubgroupOperations> subgroupSupportedOperations; /**< The subgroup operations supported by the device. */139};140141class API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalDeviceProperties {142private:143void init_features(id<MTLDevice> p_device);144void init_limits(id<MTLDevice> p_device);145146public:147MetalFeatures features;148MetalLimits limits;149150SampleCount find_nearest_supported_sample_count(RenderingDevice::TextureSamples p_samples) const;151152MetalDeviceProperties(id<MTLDevice> p_device);153~MetalDeviceProperties();154155private:156static const SampleCount sample_count[RenderingDevice::TextureSamples::TEXTURE_SAMPLES_MAX];157};158159160