|
| 1 | +/**************************************************************************/ |
| 2 | +/* metal_device_properties.h */ |
| 3 | +/**************************************************************************/ |
| 4 | +/* This file is part of: */ |
| 5 | +/* GODOT ENGINE */ |
| 6 | +/* https://godotengine.org */ |
| 7 | +/**************************************************************************/ |
| 8 | +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | +/* */ |
| 11 | +/* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | +/* a copy of this software and associated documentation files (the */ |
| 13 | +/* "Software"), to deal in the Software without restriction, including */ |
| 14 | +/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | +/* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | +/* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | +/* the following conditions: */ |
| 18 | +/* */ |
| 19 | +/* The above copyright notice and this permission notice shall be */ |
| 20 | +/* included in all copies or substantial portions of the Software. */ |
| 21 | +/* */ |
| 22 | +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | +/**************************************************************************/ |
| 30 | + |
| 31 | +/**************************************************************************/ |
| 32 | +/* */ |
| 33 | +/* Portions of this code were derived from MoltenVK. */ |
| 34 | +/* */ |
| 35 | +/* Copyright (c) 2015-2023 The Brenwill Workshop Ltd. */ |
| 36 | +/* (http://www.brenwill.com) */ |
| 37 | +/* */ |
| 38 | +/* Licensed under the Apache License, Version 2.0 (the "License"); */ |
| 39 | +/* you may not use this file except in compliance with the License. */ |
| 40 | +/* You may obtain a copy of the License at */ |
| 41 | +/* */ |
| 42 | +/* http://www.apache.org/licenses/LICENSE-2.0 */ |
| 43 | +/* */ |
| 44 | +/* Unless required by applicable law or agreed to in writing, software */ |
| 45 | +/* distributed under the License is distributed on an "AS IS" BASIS, */ |
| 46 | +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ |
| 47 | +/* implied. See the License for the specific language governing */ |
| 48 | +/* permissions and limitations under the License. */ |
| 49 | +/**************************************************************************/ |
| 50 | + |
| 51 | +#ifndef METAL_DEVICE_PROPERTIES_H |
| 52 | +#define METAL_DEVICE_PROPERTIES_H |
| 53 | + |
| 54 | +#import "servers/rendering/rendering_device.h" |
| 55 | + |
| 56 | +#import <Foundation/Foundation.h> |
| 57 | +#import <Metal/Metal.h> |
| 58 | + |
| 59 | +/** The buffer index to use for vertex content. */ |
| 60 | +const static uint32_t VERT_CONTENT_BUFFER_INDEX = 0; |
| 61 | +const static uint32_t MAX_COLOR_ATTACHMENT_COUNT = 8; |
| 62 | + |
| 63 | +typedef NS_OPTIONS(NSUInteger, SampleCount) { |
| 64 | + SampleCount1 = (1UL << 0), |
| 65 | + SampleCount2 = (1UL << 1), |
| 66 | + SampleCount4 = (1UL << 2), |
| 67 | + SampleCount8 = (1UL << 3), |
| 68 | + SampleCount16 = (1UL << 4), |
| 69 | + SampleCount32 = (1UL << 5), |
| 70 | + SampleCount64 = (1UL << 6), |
| 71 | +}; |
| 72 | + |
| 73 | +struct API_AVAILABLE(macos(11.0), ios(14.0)) MetalFeatures { |
| 74 | + uint32_t mslVersion; |
| 75 | + MTLGPUFamily highestFamily; |
| 76 | + MTLLanguageVersion mslVersionEnum; |
| 77 | + SampleCount supportedSampleCounts; |
| 78 | + long hostMemoryPageSize; |
| 79 | + bool layeredRendering; |
| 80 | + bool multisampleLayeredRendering; |
| 81 | + bool quadPermute; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */ |
| 82 | + bool simdPermute; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */ |
| 83 | + bool simdReduction; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */ |
| 84 | + bool tessellationShader; /**< If true, tessellation shaders are supported. */ |
| 85 | + bool imageCubeArray; /**< If true, image cube arrays are supported. */ |
| 86 | +}; |
| 87 | + |
| 88 | +struct MetalLimits { |
| 89 | + uint64_t maxImageArrayLayers; |
| 90 | + uint64_t maxFramebufferHeight; |
| 91 | + uint64_t maxFramebufferWidth; |
| 92 | + uint64_t maxImageDimension1D; |
| 93 | + uint64_t maxImageDimension2D; |
| 94 | + uint64_t maxImageDimension3D; |
| 95 | + uint64_t maxImageDimensionCube; |
| 96 | + uint64_t maxViewportDimensionX; |
| 97 | + uint64_t maxViewportDimensionY; |
| 98 | + MTLSize maxThreadsPerThreadGroup; |
| 99 | + MTLSize maxComputeWorkGroupCount; |
| 100 | + uint64_t maxBoundDescriptorSets; |
| 101 | + uint64_t maxColorAttachments; |
| 102 | + uint64_t maxTexturesPerArgumentBuffer; |
| 103 | + uint64_t maxSamplersPerArgumentBuffer; |
| 104 | + uint64_t maxBuffersPerArgumentBuffer; |
| 105 | + uint64_t maxBufferLength; |
| 106 | + uint64_t minUniformBufferOffsetAlignment; |
| 107 | + uint64_t maxVertexDescriptorLayoutStride; |
| 108 | + uint16_t maxViewports; |
| 109 | + uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */ |
| 110 | + uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */ |
| 111 | + uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */ |
| 112 | + uint32_t maxVertexInputAttributes; |
| 113 | + uint32_t maxVertexInputBindings; |
| 114 | + uint32_t maxVertexInputBindingStride; |
| 115 | + uint32_t maxDrawIndexedIndexValue; |
| 116 | + |
| 117 | + uint32_t minSubgroupSize; /**< The minimum number of threads in a SIMD-group. */ |
| 118 | + uint32_t maxSubgroupSize; /**< The maximum number of threads in a SIMD-group. */ |
| 119 | + BitField<RDD::ShaderStage> subgroupSupportedShaderStages; |
| 120 | + BitField<RD::SubgroupOperations> subgroupSupportedOperations; /**< The subgroup operations supported by the device. */ |
| 121 | +}; |
| 122 | + |
| 123 | +class API_AVAILABLE(macos(11.0), ios(14.0)) MetalDeviceProperties { |
| 124 | +private: |
| 125 | + void init_features(id<MTLDevice> p_device); |
| 126 | + void init_limits(id<MTLDevice> p_device); |
| 127 | + |
| 128 | +public: |
| 129 | + MetalFeatures features; |
| 130 | + MetalLimits limits; |
| 131 | + |
| 132 | + SampleCount find_nearest_supported_sample_count(RenderingDevice::TextureSamples p_samples) const; |
| 133 | + |
| 134 | + MetalDeviceProperties(id<MTLDevice> p_device); |
| 135 | + ~MetalDeviceProperties(); |
| 136 | + |
| 137 | +private: |
| 138 | + static const SampleCount sample_count[RenderingDevice::TextureSamples::TEXTURE_SAMPLES_MAX]; |
| 139 | +}; |
| 140 | + |
| 141 | +#endif // METAL_DEVICE_PROPERTIES_H |
0 commit comments