From 7471a819e1e986a373ab3b9208f43e680362dc9e Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 5 Jan 2022 10:25:46 +0100 Subject: [PATCH] Add Vulkan support for Mac (via MoltenVK) --- Source/Editor/Cooker/Steps/CookAssetsStep.cpp | 8 ++++ Source/Engine/Graphics/GPUAdapter.h | 1 + Source/Engine/Graphics/Graphics.Build.cs | 3 +- .../Shaders/Cache/ShaderCacheManager.cpp | 2 +- .../Vulkan/GraphicsDeviceVulkan.Build.cs | 28 ++++++++++--- .../Vulkan/Mac/MacVulkanPlatform.cpp | 23 +++++++++++ .../Vulkan/Mac/MacVulkanPlatform.h | 21 ++++++++++ .../GraphicsDevice/Vulkan/VulkanPlatform.h | 2 + Source/Engine/Platform/Mac/MacWindow.cpp | 28 +++++++++++++ .../ShadersCompilation.Build.cs | 1 + .../ThirdParty/x64/libGenericCodeGen.a | 3 ++ .../Mac/Binaries/ThirdParty/x64/libHLSL.a | 3 ++ .../ThirdParty/x64/libMachineIndependent.a | 3 ++ .../Binaries/ThirdParty/x64/libOGLCompiler.a | 3 ++ .../Binaries/ThirdParty/x64/libOSDependent.a | 3 ++ .../ThirdParty/x64/libSPIRV-Tools-opt.a | 3 ++ .../Binaries/ThirdParty/x64/libSPIRV-Tools.a | 3 ++ .../Mac/Binaries/ThirdParty/x64/libSPIRV.a | 3 ++ .../Mac/Binaries/ThirdParty/x64/libglslang.a | 3 ++ Source/ThirdParty/glslang/glslang.Build.cs | 1 + .../spirv-tools/spirv_tools.Build.cs | 1 + Source/ThirdParty/volk/volk.Build.cs | 6 +++ .../Flax.Build/Deps/Dependencies/glslang.cs | 41 +++++++++++++++++-- .../Flax.Build/Platforms/Mac/MacToolchain.cs | 1 + 24 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.cpp create mode 100644 Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.h create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libGenericCodeGen.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libHLSL.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libMachineIndependent.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libOGLCompiler.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libOSDependent.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools-opt.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV.a create mode 100644 Source/Platforms/Mac/Binaries/ThirdParty/x64/libglslang.a diff --git a/Source/Editor/Cooker/Steps/CookAssetsStep.cpp b/Source/Editor/Cooker/Steps/CookAssetsStep.cpp index ea234ccd1..e726be706 100644 --- a/Source/Editor/Cooker/Steps/CookAssetsStep.cpp +++ b/Source/Editor/Cooker/Steps/CookAssetsStep.cpp @@ -524,6 +524,14 @@ bool ProcessShaderBase(CookAssetsStep::AssetCookData& data, ShaderAssetBase* ass COMPILE_PROFILE(PS5, SHADER_FILE_CHUNK_INTERNAL_GENERIC_CACHE); break; } +#endif +#if PLATFORM_TOOLS_MAC + case BuildPlatform::MacOSx64: + { + const char* platformDefineName = "PLATFORM_MAC"; + COMPILE_PROFILE(Vulkan_SM5, SHADER_FILE_CHUNK_INTERNAL_VULKAN_SM5_CACHE); + break; + } #endif default: { diff --git a/Source/Engine/Graphics/GPUAdapter.h b/Source/Engine/Graphics/GPUAdapter.h index efacae2ba..0f2ea95eb 100644 --- a/Source/Engine/Graphics/GPUAdapter.h +++ b/Source/Engine/Graphics/GPUAdapter.h @@ -9,6 +9,7 @@ #define GPU_VENDOR_ID_INTEL 0x8086 #define GPU_VENDOR_ID_NVIDIA 0x10DE #define GPU_VENDOR_ID_MICROSOFT 0x1414 +#define GPU_VENDOR_ID_APPLE 0x106B /// /// Interface for GPU device adapter. diff --git a/Source/Engine/Graphics/Graphics.Build.cs b/Source/Engine/Graphics/Graphics.Build.cs index 625128ece..024415ab5 100644 --- a/Source/Engine/Graphics/Graphics.Build.cs +++ b/Source/Engine/Graphics/Graphics.Build.cs @@ -82,7 +82,8 @@ public class Graphics : EngineModule options.PrivateDependencies.Add("GraphicsDeviceVulkan"); break; case TargetPlatform.Mac: - options.PrivateDependencies.Add("GraphicsDeviceNull"); // TODO: Graphics support on Mac + options.PrivateDependencies.Add("GraphicsDeviceNull"); + options.PrivateDependencies.Add("GraphicsDeviceVulkan"); break; default: throw new InvalidPlatformException(options.Platform.Target); } diff --git a/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp b/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp index c5326a448..8c8283922 100644 --- a/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp +++ b/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp @@ -14,7 +14,7 @@ const Char* ShaderProfileCacheDirNames[] = { // @formatter:off - TEXT("EARTH_IS_NOT_FLAT_XD"), // Unknown + TEXT(""), // Unknown TEXT("DX_SM4"), // DirectX_SM4 TEXT("DX_SM5"), // DirectX_SM5 TEXT("GLSL_410"), // GLSL_410 diff --git a/Source/Engine/GraphicsDevice/Vulkan/GraphicsDeviceVulkan.Build.cs b/Source/Engine/GraphicsDevice/Vulkan/GraphicsDeviceVulkan.Build.cs index 4779beb4f..c7711ec80 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GraphicsDeviceVulkan.Build.cs +++ b/Source/Engine/GraphicsDevice/Vulkan/GraphicsDeviceVulkan.Build.cs @@ -25,6 +25,7 @@ public sealed class VulkanSdk : Sdk { TargetPlatform.Windows, TargetPlatform.Linux, + TargetPlatform.Mac, }; } } @@ -34,10 +35,26 @@ public sealed class VulkanSdk : Sdk /// public VulkanSdk() { - if (!Platforms.Contains(Flax.Build.Platform.BuildTargetPlatform)) + var platform = Flax.Build.Platform.BuildTargetPlatform; + if (!Platforms.Contains(platform)) return; var vulkanSdk = Environment.GetEnvironmentVariable("VULKAN_SDK"); + if (vulkanSdk == null && platform == TargetPlatform.Mac) + { + // Try to guess install location for the current user + var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "VulkanSDK"); + if (Directory.Exists(path)) + { + var subDirs = Directory.GetDirectories(path); + if (subDirs.Length != 0) + { + path = Path.Combine(subDirs[0], "macOS"); + if (Directory.Exists(path)) + vulkanSdk = path; + } + } + } if (vulkanSdk != null) { if (Directory.Exists(vulkanSdk)) @@ -110,13 +127,14 @@ public class GraphicsDeviceVulkan : GraphicsDeviceBaseModule options.PrivateDependencies.Add("VulkanMemoryAllocator"); - if (options.Platform.Target == TargetPlatform.Switch) + switch (options.Platform.Target) { + case TargetPlatform.Switch: options.SourcePaths.Add(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Switch", "Engine", "GraphicsDevice", "Vulkan")); - } - else - { + break; + default: options.PrivateDependencies.Add("volk"); + break; } } } diff --git a/Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.cpp b/Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.cpp new file mode 100644 index 000000000..0736666bd --- /dev/null +++ b/Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +#if GRAPHICS_API_VULKAN && PLATFORM_MAC + +#include "MacVulkanPlatform.h" +#include "../RenderToolsVulkan.h" +#include + +void MacVulkanPlatform::GetInstanceExtensions(Array& extensions, Array& layers) +{ + extensions.Add(VK_MVK_MACOS_SURFACE_EXTENSION_NAME); +} + +void MacVulkanPlatform::CreateSurface(void* windowHandle, VkInstance instance, VkSurfaceKHR* surface) +{ + NSWindow* window = (NSWindow*)windowHandle; + VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo; + RenderToolsVulkan::ZeroStruct(surfaceCreateInfo, VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK); + surfaceCreateInfo.pView = (void*)window.contentView; + VALIDATE_VULKAN_RESULT(vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, nullptr, surface)); +} + +#endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.h b/Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.h new file mode 100644 index 000000000..dbdba0ac1 --- /dev/null +++ b/Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.h @@ -0,0 +1,21 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +#pragma once + +#include "../VulkanPlatformBase.h" + +#if GRAPHICS_API_VULKAN && PLATFORM_MAC + +/// +/// The implementation for the Vulkan API support for Mac platform. +/// +class MacVulkanPlatform : public VulkanPlatformBase +{ +public: + static void GetInstanceExtensions(Array& extensions, Array& layers); + static void CreateSurface(void* windowHandle, VkInstance instance, VkSurfaceKHR* outSurface); +}; + +typedef MacVulkanPlatform VulkanPlatform; + +#endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatform.h b/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatform.h index bc216190b..f4f693ac3 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatform.h +++ b/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatform.h @@ -10,4 +10,6 @@ #include "Android/AndroidVulkanPlatform.h" #elif PLATFORM_SWITCH #include "Platforms/Switch/Engine/GraphicsDevice/Vulkan/SwitchVulkanPlatform.h" +#elif PLATFORM_MAC +#include "Mac/MacVulkanPlatform.h" #endif diff --git a/Source/Engine/Platform/Mac/MacWindow.cpp b/Source/Engine/Platform/Mac/MacWindow.cpp index 7f2c70c32..e30529e12 100644 --- a/Source/Engine/Platform/Mac/MacWindow.cpp +++ b/Source/Engine/Platform/Mac/MacWindow.cpp @@ -6,6 +6,7 @@ #include "MacUtils.h" #include "Engine/Graphics/RenderTask.h" #include +#include @interface MacWindowImpl : NSWindow { @@ -31,6 +32,29 @@ @end +@interface MacViewImpl : NSView +{ +} + +- (CALayer*)makeBackingLayer; +- (BOOL)wantsUpdateLayer; + +@end + +@implementation MacViewImpl + +- (CALayer*)makeBackingLayer +{ + return [[CAMetalLayer class] layer]; +} + +- (BOOL)wantsUpdateLayer +{ + return YES; +} + +@end + MacWindow::MacWindow(const CreateWindowSettings& settings) : WindowBase(settings) { @@ -60,12 +84,16 @@ MacWindow::MacWindow(const CreateWindowSettings& settings) styleMask:(styleMask) backing:NSBackingStoreBuffered defer:NO]; + MacViewImpl* view = [[MacViewImpl alloc] init]; + view.wantsLayer = YES; window.title = (__bridge NSString*)MacUtils::ToString(settings.Title); [window setWindow:this]; [window setReleasedWhenClosed:NO]; [window setMinSize:NSMakeSize(settings.MinimumSize.X, settings.MinimumSize.Y)]; [window setMaxSize:NSMakeSize(settings.MaximumSize.X, settings.MaximumSize.Y)]; [window setOpaque:!settings.SupportsTransparency]; + [window setContentView:view]; + [window setAcceptsMouseMovedEvents:YES]; [window setDelegate:window]; _window = window; diff --git a/Source/Engine/ShadersCompilation/ShadersCompilation.Build.cs b/Source/Engine/ShadersCompilation/ShadersCompilation.Build.cs index c6afa0512..0e6f68292 100644 --- a/Source/Engine/ShadersCompilation/ShadersCompilation.Build.cs +++ b/Source/Engine/ShadersCompilation/ShadersCompilation.Build.cs @@ -54,6 +54,7 @@ public class ShadersCompilation : EngineModule options.PrivateDependencies.Add("ShaderCompilerVulkan"); break; case TargetPlatform.Mac: + options.PrivateDependencies.Add("ShaderCompilerVulkan"); break; default: throw new InvalidPlatformException(options.Platform.Target); } diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libGenericCodeGen.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libGenericCodeGen.a new file mode 100644 index 000000000..c7ad63c31 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libGenericCodeGen.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b4f409db277335131763854b3b8f3cb8b3682d825beb43a22ca6d2b992076e1b +size 17544 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libHLSL.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libHLSL.a new file mode 100644 index 000000000..cc6ad7ce8 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libHLSL.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:17f357d78f684fb7ee489b07196b0de3aaf40d2c1832d1ac0e8b25b1d65554ce +size 384 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libMachineIndependent.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libMachineIndependent.a new file mode 100644 index 000000000..3e148d3cc --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libMachineIndependent.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6cb172b89243f4f0f2dbcabecb58a18f4aae52a3fd0e2f8ac202d15fca0e3fe +size 3611744 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libOGLCompiler.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libOGLCompiler.a new file mode 100644 index 000000000..7d7548129 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libOGLCompiler.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b67552378e0d13b34b9bf8929ab54e0afb0bb4b63a3de2a1e1957e81916ba231 +size 2696 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libOSDependent.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libOSDependent.a new file mode 100644 index 000000000..4c614552a --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libOSDependent.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:961c4fd393c0acd9a01aadc9c62b5aa6f786e2a64a871bde124f325d026cac9e +size 4328 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools-opt.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools-opt.a new file mode 100644 index 000000000..bf902ff57 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools-opt.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c221e387458bb0641a604fbc4a52d7b4c9a2f55de2750e87cc16d30d6c9af511 +size 7158936 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools.a new file mode 100644 index 000000000..7270c5575 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV-Tools.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f09c27ed7fe39ca447cce23c253d1fb45fb4294a5ff445990bb24b9a7f21651 +size 2423896 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV.a new file mode 100644 index 000000000..0b2a79040 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libSPIRV.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a24e593416d0a020f8919e7da7349e309d59cda1dabb634e4dda8a8af522b7ea +size 797600 diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libglslang.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libglslang.a new file mode 100644 index 000000000..32632fa33 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libglslang.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:836b56b61050955c16a2d6758a44e647f5b37e318e615868b19e248402de456f +size 32072 diff --git a/Source/ThirdParty/glslang/glslang.Build.cs b/Source/ThirdParty/glslang/glslang.Build.cs index 5fc937ec6..a2b876d8a 100644 --- a/Source/ThirdParty/glslang/glslang.Build.cs +++ b/Source/ThirdParty/glslang/glslang.Build.cs @@ -39,6 +39,7 @@ public class glslang : DepsModule options.OutputFiles.Add(Path.Combine(depsRoot, "SPIRV.lib")); break; case TargetPlatform.Linux: + case TargetPlatform.Mac: options.OutputFiles.Add(Path.Combine(depsRoot, "libGenericCodeGen.a")); options.OutputFiles.Add(Path.Combine(depsRoot, "libglslang.a")); options.OutputFiles.Add(Path.Combine(depsRoot, "libHLSL.a")); diff --git a/Source/ThirdParty/spirv-tools/spirv_tools.Build.cs b/Source/ThirdParty/spirv-tools/spirv_tools.Build.cs index 293ed1510..b5b8af1e6 100644 --- a/Source/ThirdParty/spirv-tools/spirv_tools.Build.cs +++ b/Source/ThirdParty/spirv-tools/spirv_tools.Build.cs @@ -35,6 +35,7 @@ public class spirv_tools : DepsModule options.OutputFiles.Add(Path.Combine(depsRoot, "SPIRV-Tools-opt.lib")); break; case TargetPlatform.Linux: + case TargetPlatform.Mac: options.OutputFiles.Add(Path.Combine(depsRoot, "libSPIRV-Tools.a")); options.OutputFiles.Add(Path.Combine(depsRoot, "libSPIRV-Tools-opt.a")); break; diff --git a/Source/ThirdParty/volk/volk.Build.cs b/Source/ThirdParty/volk/volk.Build.cs index 82bb2572b..d4f6bb6f5 100644 --- a/Source/ThirdParty/volk/volk.Build.cs +++ b/Source/ThirdParty/volk/volk.Build.cs @@ -1,5 +1,6 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. +using System.IO; using Flax.Build; using Flax.Build.NativeCpp; @@ -36,6 +37,11 @@ public class volk : ThirdPartyModule case TargetPlatform.Android: options.PublicDefinitions.Add("VK_USE_PLATFORM_ANDROID_KHR"); break; + case TargetPlatform.Mac: + options.PublicDefinitions.Add("VK_USE_PLATFORM_MACOS_MVK"); + options.DependencyFiles.Add(Path.Combine(VulkanSdk.Instance.RootPath, "../MoltenVK/dylib/macOS/libMoltenVK.dylib")); + options.DependencyFiles.Add(Path.Combine(VulkanSdk.Instance.RootPath, "../MoltenVK/dylib/macOS/MoltenVK_icd.json")); + break; default: throw new InvalidPlatformException(options.Platform.Target); } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/glslang.cs b/Source/Tools/Flax.Build/Deps/Dependencies/glslang.cs index bb7ef862e..bf56982f5 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/glslang.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/glslang.cs @@ -28,6 +28,11 @@ namespace Flax.Deps.Dependencies { TargetPlatform.Linux, }; + case TargetPlatform.Mac: + return new[] + { + TargetPlatform.Mac, + }; default: return new TargetPlatform[0]; } } @@ -71,10 +76,10 @@ namespace Flax.Deps.Dependencies // Build for Win64 File.Delete(Path.Combine(buildDir, "CMakeCache.txt")); - RunCmake(buildDir, TargetPlatform.Windows, TargetArchitecture.x64, cmakeArgs); + RunCmake(buildDir, platform, TargetArchitecture.x64, cmakeArgs); Utilities.Run("cmake", string.Format("--build . --config {0} --target install", configuration), null, buildDir, Utilities.RunOptions.None); Deploy.VCEnvironment.BuildSolution(solutionPath, configuration, "x64"); - var depsFolder = GetThirdPartyFolder(options, TargetPlatform.Windows, TargetArchitecture.x64); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); foreach (var file in outputFiles) { Utilities.FileCopy(file, Path.Combine(depsFolder, Path.GetFileName(file))); @@ -97,10 +102,10 @@ namespace Flax.Deps.Dependencies }; // Build for Linux - RunCmake(root, TargetPlatform.Linux, TargetArchitecture.x64, cmakeArgs); + RunCmake(root, platform, TargetArchitecture.x64, cmakeArgs); Utilities.Run("cmake", string.Format("--build . --config {0} --target install", configuration), null, buildDir, Utilities.RunOptions.None); Utilities.Run("make", null, null, root, Utilities.RunOptions.None); - var depsFolder = GetThirdPartyFolder(options, TargetPlatform.Linux, TargetArchitecture.x64); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); foreach (var file in outputFiles) { var dst = Path.Combine(depsFolder, Path.GetFileName(file)); @@ -109,6 +114,34 @@ namespace Flax.Deps.Dependencies } break; } + case TargetPlatform.Mac: + { + var outputFiles = new[] + { + Path.Combine(libsRoot, "libGenericCodeGen.a"), + Path.Combine(libsRoot, "libMachineIndependent.a"), + Path.Combine(libsRoot, "libHLSL.a"), + Path.Combine(libsRoot, "libOSDependent.a"), + Path.Combine(libsRoot, "libOGLCompiler.a"), + Path.Combine(libsRoot, "libSPIRV-Tools-opt.a"), + Path.Combine(libsRoot, "libSPIRV-Tools.a"), + Path.Combine(libsRoot, "libSPIRV.a"), + Path.Combine(libsRoot, "libglslang.a"), + }; + + // Build for Mac + RunCmake(root, platform, TargetArchitecture.x64, cmakeArgs); + Utilities.Run("cmake", string.Format("--build . --config {0} --target install", configuration), null, buildDir, Utilities.RunOptions.None); + Utilities.Run("make", null, null, root, Utilities.RunOptions.None); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); + foreach (var file in outputFiles) + { + var dst = Path.Combine(depsFolder, Path.GetFileName(file)); + Utilities.FileCopy(file, dst); + Utilities.Run("strip", string.Format("\"{0}\"", dst), null, null, Utilities.RunOptions.None); + } + break; + } } } diff --git a/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs b/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs index da87519ed..79781a9ae 100644 --- a/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs @@ -114,6 +114,7 @@ namespace Flax.Build.Platforms options.LinkEnv.InputLibraries.Add("SystemConfiguration.framework"); options.LinkEnv.InputLibraries.Add("IOKit.framework"); options.LinkEnv.InputLibraries.Add("Cocoa.framework"); + options.LinkEnv.InputLibraries.Add("QuartzCore.framework"); } ///