Metal: Ensure baking to binary sets minimum target OS

Co-authored-by: Travis Lange <travislange12@gmail.com>
This commit is contained in:
Stuart Carnie
2025-09-05 10:05:29 +10:00
parent 6c9aa4c7d3
commit b7aac81366
14 changed files with 250 additions and 44 deletions

View File

@@ -54,7 +54,7 @@ bool ShaderBakerExportPlugin::_is_active(const Vector<String> &p_features) const
return RendererSceneRenderRD::get_singleton() != nullptr && RendererRD::MaterialStorage::get_singleton() != nullptr && p_features.has("shader_baker");
}
bool ShaderBakerExportPlugin::_initialize_container_format(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
bool ShaderBakerExportPlugin::_initialize_container_format(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features, const Ref<EditorExportPreset> &p_preset) {
Variant driver_variant = GLOBAL_GET("rendering/rendering_device/driver." + p_platform->get_os_name().to_lower());
if (!driver_variant.is_string()) {
driver_variant = GLOBAL_GET("rendering/rendering_device/driver");
@@ -67,7 +67,7 @@ bool ShaderBakerExportPlugin::_initialize_container_format(const Ref<EditorExpor
for (Ref<ShaderBakerExportPluginPlatform> platform : platforms) {
if (platform->matches_driver(shader_container_driver)) {
shader_container_format = platform->create_shader_container_format(p_platform);
shader_container_format = platform->create_shader_container_format(p_platform, get_export_preset());
ERR_FAIL_NULL_V_MSG(shader_container_format, false, "Unable to create shader container format for the export platform.");
return true;
}
@@ -99,7 +99,7 @@ bool ShaderBakerExportPlugin::_begin_customize_resources(const Ref<EditorExportP
return false;
}
if (!_initialize_container_format(p_platform, p_features)) {
if (!_initialize_container_format(p_platform, p_features, get_export_preset())) {
return false;
}

View File

@@ -38,7 +38,7 @@ class ShaderBakerExportPluginPlatform : public RefCounted {
GDCLASS(ShaderBakerExportPluginPlatform, RefCounted);
public:
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) = 0;
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) = 0;
virtual bool matches_driver(const String &p_driver) = 0;
virtual ~ShaderBakerExportPluginPlatform() {}
};
@@ -82,7 +82,7 @@ protected:
virtual String get_name() const override;
virtual bool _is_active(const Vector<String> &p_features) const;
virtual bool _initialize_container_format(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features);
virtual bool _initialize_container_format(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features, const Ref<EditorExportPreset> &p_preset);
virtual void _cleanup_container_format();
virtual bool _initialize_cache_directory();
virtual bool _begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) override;

View File

@@ -34,7 +34,7 @@
#include <windows.h>
RenderingShaderContainerFormat *ShaderBakerExportPluginPlatformD3D12::create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) {
RenderingShaderContainerFormat *ShaderBakerExportPluginPlatformD3D12::create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) {
if (lib_d3d12 == nullptr) {
lib_d3d12 = LoadLibraryW(L"D3D12.dll");
ERR_FAIL_NULL_V_MSG(lib_d3d12, nullptr, "Unable to load D3D12.dll.");

View File

@@ -39,7 +39,7 @@ private:
void *lib_d3d12 = nullptr;
public:
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) override;
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) override;
virtual bool matches_driver(const String &p_driver) override;
virtual ~ShaderBakerExportPluginPlatformD3D12() override;
};

View File

@@ -32,18 +32,22 @@
#include "drivers/metal/rendering_shader_container_metal.h"
RenderingShaderContainerFormat *ShaderBakerExportPluginPlatformMetal::create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) {
RenderingShaderContainerFormat *ShaderBakerExportPluginPlatformMetal::create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) {
const String &os_name = p_platform->get_os_name();
const MetalDeviceProfile *profile;
String min_os_version;
if (os_name == U"macOS") {
profile = MetalDeviceProfile::get_profile(MetalDeviceProfile::Platform::macOS, MetalDeviceProfile::GPU::Apple7);
// Godot metal doesn't support x86_64 mac so no need to worry about that version
min_os_version = p_preset->get("application/min_macos_version_arm64");
} else if (os_name == U"iOS") {
profile = MetalDeviceProfile::get_profile(MetalDeviceProfile::Platform::iOS, MetalDeviceProfile::GPU::Apple7);
min_os_version = p_preset->get("application/min_ios_version");
} else {
ERR_FAIL_V_MSG(nullptr, vformat("Unsupported platform: %s", os_name));
}
return memnew(RenderingShaderContainerFormatMetal(profile, true));
return memnew(RenderingShaderContainerFormatMetal(profile, true, min_os_version));
}
bool ShaderBakerExportPluginPlatformMetal::matches_driver(const String &p_driver) {

View File

@@ -34,6 +34,6 @@
class ShaderBakerExportPluginPlatformMetal : public ShaderBakerExportPluginPlatform {
public:
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) override;
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) override;
virtual bool matches_driver(const String &p_driver) override;
};

View File

@@ -32,7 +32,7 @@
#include "drivers/vulkan/rendering_shader_container_vulkan.h"
RenderingShaderContainerFormat *ShaderBakerExportPluginPlatformVulkan::create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) {
RenderingShaderContainerFormat *ShaderBakerExportPluginPlatformVulkan::create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) {
return memnew(RenderingShaderContainerFormatVulkan);
}

View File

@@ -36,6 +36,6 @@ class ShaderBakerExportPluginPlatformVulkan : public ShaderBakerExportPluginPlat
GDCLASS(ShaderBakerExportPluginPlatformVulkan, ShaderBakerExportPluginPlatform);
public:
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) override;
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) override;
virtual bool matches_driver(const String &p_driver) override;
};