@@ -41,6 +41,25 @@ const uint32_t VIEW_MASK_BUFFER_INDEX = 24;
41
41
42
42
class RenderingShaderContainerFormatMetal;
43
43
44
+ class MinOsVersion {
45
+ uint32_t version;
46
+
47
+ public:
48
+ String to_compiler_os_version () const ;
49
+ bool is_null () const { return version == UINT32_MAX; }
50
+ bool is_valid () const { return version != UINT32_MAX; }
51
+
52
+ MinOsVersion (const String &p_version);
53
+ explicit MinOsVersion (uint32_t p_version) :
54
+ version (p_version) {}
55
+ MinOsVersion () :
56
+ version (UINT32_MAX) {}
57
+
58
+ bool operator>(uint32_t p_other) {
59
+ return version > p_other;
60
+ }
61
+ };
62
+
44
63
// / @brief A minimal structure that defines a device profile for Metal.
45
64
// /
46
65
// / This structure is used by the `RenderingShaderContainerMetal` class to
@@ -53,17 +72,20 @@ struct MetalDeviceProfile {
53
72
iOS = 1 ,
54
73
};
55
74
56
- // / @brief The GPU family.
75
+ /* ! @brief The GPU family.
76
+ *
77
+ * NOTE: These values match Apple's MTLGPUFamily
78
+ */
57
79
enum class GPU : uint32_t {
58
- Apple1,
59
- Apple2,
60
- Apple3,
61
- Apple4,
62
- Apple5,
63
- Apple6,
64
- Apple7,
65
- Apple8,
66
- Apple9,
80
+ Apple1 = 1001 ,
81
+ Apple2 = 1002 ,
82
+ Apple3 = 1003 ,
83
+ Apple4 = 1004 ,
84
+ Apple5 = 1005 ,
85
+ Apple6 = 1006 ,
86
+ Apple7 = 1007 ,
87
+ Apple8 = 1008 ,
88
+ Apple9 = 1009 ,
67
89
};
68
90
69
91
enum class ArgumentBuffersTier : uint32_t {
@@ -108,6 +130,13 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
108
130
// / The Metal language version specified when compiling SPIR-V to MSL.
109
131
// / Format is major * 10000 + minor * 100 + patch.
110
132
uint32_t msl_version = UINT32_MAX;
133
+ /* ! @brief The minimum supported OS version for shaders baked to a `.metallib`.
134
+ *
135
+ * NOTE: This property is only valid when shaders are baked to a .metalllib
136
+ *
137
+ * Format is major * 10000 + minor * 100 + patch.
138
+ */
139
+ MinOsVersion os_min_version;
111
140
uint32_t flags = NONE;
112
141
113
142
// / @brief Returns `true` if the shader is compiled with multi-view support.
@@ -210,9 +239,23 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
210
239
HeaderData mtl_reflection_data; // compliment to reflection_data
211
240
Vector<StageData> mtl_shaders; // compliment to shaders
212
241
242
+ private:
243
+ struct ToolchainProperties {
244
+ MinOsVersion os_version_min_required;
245
+ uint32_t metal_version = UINT32_MAX;
246
+
247
+ _FORCE_INLINE_ bool is_null () const { return os_version_min_required.is_null () || metal_version == UINT32_MAX; }
248
+ _FORCE_INLINE_ bool is_valid () const { return !is_null (); }
249
+ };
250
+
251
+ ToolchainProperties compiler_props;
252
+
253
+ void _initialize_toolchain_properties ();
254
+
213
255
private:
214
256
const MetalDeviceProfile *device_profile = nullptr ;
215
257
bool export_mode = false ;
258
+ MinOsVersion min_os_version;
216
259
217
260
Vector<UniformData> mtl_reflection_binding_set_uniforms_data; // compliment to reflection_binding_set_uniforms_data
218
261
Vector<SpecializationData> mtl_reflection_specialization_data; // compliment to reflection_specialization_data
@@ -224,6 +267,7 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
224
267
225
268
void set_export_mode (bool p_export_mode) { export_mode = p_export_mode; }
226
269
void set_device_profile (const MetalDeviceProfile *p_device_profile) { device_profile = p_device_profile; }
270
+ void set_min_os_version (const MinOsVersion p_min_os_version) { min_os_version = p_min_os_version; }
227
271
228
272
struct MetalShaderReflection {
229
273
Vector<Vector<UniformData>> uniform_sets;
@@ -253,13 +297,14 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
253
297
254
298
class RenderingShaderContainerFormatMetal : public RenderingShaderContainerFormat {
255
299
bool export_mode = false ;
300
+ MinOsVersion min_os_version;
256
301
257
302
const MetalDeviceProfile *device_profile = nullptr ;
258
303
259
304
public:
260
305
virtual Ref<RenderingShaderContainer> create_container () const override;
261
306
virtual ShaderLanguageVersion get_shader_language_version () const override;
262
307
virtual ShaderSpirvVersion get_shader_spirv_version () const override;
263
- RenderingShaderContainerFormatMetal (const MetalDeviceProfile *p_device_profile, bool p_export = false );
308
+ RenderingShaderContainerFormatMetal (const MetalDeviceProfile *p_device_profile, bool p_export = false , const MinOsVersion p_min_os_version = MinOsVersion () );
264
309
virtual ~RenderingShaderContainerFormatMetal () = default ;
265
310
};
0 commit comments