@@ -41,6 +41,25 @@ const uint32_t VIEW_MASK_BUFFER_INDEX = 24;
4141
4242class RenderingShaderContainerFormatMetal;
4343
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+
4463// / @brief A minimal structure that defines a device profile for Metal.
4564// /
4665// / This structure is used by the `RenderingShaderContainerMetal` class to
@@ -53,17 +72,20 @@ struct MetalDeviceProfile {
5372 iOS = 1 ,
5473 };
5574
56- // / @brief The GPU family.
75+ /* ! @brief The GPU family.
76+ *
77+ * NOTE: These values match Apple's MTLGPUFamily
78+ */
5779 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 ,
6789 };
6890
6991 enum class ArgumentBuffersTier : uint32_t {
@@ -108,6 +130,13 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
108130 // / The Metal language version specified when compiling SPIR-V to MSL.
109131 // / Format is major * 10000 + minor * 100 + patch.
110132 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;
111140 uint32_t flags = NONE;
112141
113142 // / @brief Returns `true` if the shader is compiled with multi-view support.
@@ -210,9 +239,23 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
210239 HeaderData mtl_reflection_data; // compliment to reflection_data
211240 Vector<StageData> mtl_shaders; // compliment to shaders
212241
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+
213255private:
214256 const MetalDeviceProfile *device_profile = nullptr ;
215257 bool export_mode = false ;
258+ MinOsVersion min_os_version;
216259
217260 Vector<UniformData> mtl_reflection_binding_set_uniforms_data; // compliment to reflection_binding_set_uniforms_data
218261 Vector<SpecializationData> mtl_reflection_specialization_data; // compliment to reflection_specialization_data
@@ -224,6 +267,7 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
224267
225268 void set_export_mode (bool p_export_mode) { export_mode = p_export_mode; }
226269 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; }
227271
228272 struct MetalShaderReflection {
229273 Vector<Vector<UniformData>> uniform_sets;
@@ -253,13 +297,14 @@ class RenderingShaderContainerMetal : public RenderingShaderContainer {
253297
254298class RenderingShaderContainerFormatMetal : public RenderingShaderContainerFormat {
255299 bool export_mode = false ;
300+ MinOsVersion min_os_version;
256301
257302 const MetalDeviceProfile *device_profile = nullptr ;
258303
259304public:
260305 virtual Ref<RenderingShaderContainer> create_container () const override;
261306 virtual ShaderLanguageVersion get_shader_language_version () const override;
262307 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 () );
264309 virtual ~RenderingShaderContainerFormatMetal () = default ;
265310};
0 commit comments