renderer_vulkan: Integrate MacOS wsi

This commit is contained in:
GPUCode
2022-11-02 23:19:50 +02:00
parent 474cccda33
commit 01af8e3f2c
3 changed files with 19 additions and 1 deletions

View File

@ -322,6 +322,8 @@ static Frontend::WindowSystemType GetWindowSystemType() {
return Frontend::WindowSystemType::X11; return Frontend::WindowSystemType::X11;
else if (platform_name == QStringLiteral("wayland")) else if (platform_name == QStringLiteral("wayland"))
return Frontend::WindowSystemType::Wayland; return Frontend::WindowSystemType::Wayland;
else if (platform_name == QStringLiteral("cocoa"))
return Frontend::WindowSystemType::MacOS;
LOG_CRITICAL(Frontend, "Unknown Qt platform!"); LOG_CRITICAL(Frontend, "Unknown Qt platform!");
return Frontend::WindowSystemType::Windows; return Frontend::WindowSystemType::Windows;

View File

@ -18,7 +18,9 @@ namespace Frontend {
/// WindowInformation /// WindowInformation
enum class WindowSystemType : u8 { enum class WindowSystemType : u8 {
Headless, Headless,
Android,
Windows, Windows,
MacOS,
X11, X11,
Wayland, Wayland,
}; };

View File

@ -8,7 +8,6 @@
#elif defined(_WIN32) #elif defined(_WIN32)
#define VK_USE_PLATFORM_WIN32_KHR #define VK_USE_PLATFORM_WIN32_KHR
#elif defined(__APPLE__) #elif defined(__APPLE__)
#define VK_USE_PLATFORM_MACOS_MVK
#define VK_USE_PLATFORM_METAL_EXT #define VK_USE_PLATFORM_METAL_EXT
#else #else
#define VK_USE_PLATFORM_WAYLAND_KHR #define VK_USE_PLATFORM_WAYLAND_KHR
@ -63,6 +62,17 @@ vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::EmuWindow& e
UNREACHABLE(); UNREACHABLE();
} }
} }
#elif defined(VK_USE_PLATFORM_METAL_EXT)
if (window_info.type == Frontend::WindowSystemType::MacOS) {
const vk::MetalSurfaceCreateInfoEXT macos_ci = {
.pLayer = static_cast<const CAMetalLayer*>(window_info.render_surface)
};
if (instance.createMetalSurfaceEXT(&macos_ci, nullptr, &surface) != vk::Result::eSuccess) {
LOG_CRITICAL(Render_Vulkan, "Failed to initialize MacOS surface");
UNREACHABLE();
}
}
#endif #endif
if (!surface) { if (!surface) {
@ -98,6 +108,10 @@ std::vector<const char*> GetInstanceExtensions(Frontend::WindowSystemType window
case Frontend::WindowSystemType::Wayland: case Frontend::WindowSystemType::Wayland:
extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
break; break;
#elif defined(VK_USE_PLATFORM_METAL_EXT)
case Frontend::WindowSystemType::MacOS:
extensions.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME);
break;
#endif #endif
default: default:
LOG_ERROR(Render_Vulkan, "Presentation not supported on this platform"); LOG_ERROR(Render_Vulkan, "Presentation not supported on this platform");