Add Vulkan support for Mac (via MoltenVK)
This commit is contained in:
@@ -25,6 +25,7 @@ public sealed class VulkanSdk : Sdk
|
||||
{
|
||||
TargetPlatform.Windows,
|
||||
TargetPlatform.Linux,
|
||||
TargetPlatform.Mac,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -34,10 +35,26 @@ public sealed class VulkanSdk : Sdk
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <Cocoa/Cocoa.h>
|
||||
|
||||
void MacVulkanPlatform::GetInstanceExtensions(Array<const char*>& extensions, Array<const char*>& 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
|
||||
21
Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.h
Normal file
21
Source/Engine/GraphicsDevice/Vulkan/Mac/MacVulkanPlatform.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../VulkanPlatformBase.h"
|
||||
|
||||
#if GRAPHICS_API_VULKAN && PLATFORM_MAC
|
||||
|
||||
/// <summary>
|
||||
/// The implementation for the Vulkan API support for Mac platform.
|
||||
/// </summary>
|
||||
class MacVulkanPlatform : public VulkanPlatformBase
|
||||
{
|
||||
public:
|
||||
static void GetInstanceExtensions(Array<const char*>& extensions, Array<const char*>& layers);
|
||||
static void CreateSurface(void* windowHandle, VkInstance instance, VkSurfaceKHR* outSurface);
|
||||
};
|
||||
|
||||
typedef MacVulkanPlatform VulkanPlatform;
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user