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