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