From 2855869530cee66a57e8d959a041f9ca95a85da7 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 27 Feb 2018 10:56:06 +0300 Subject: [PATCH] vulkan: Support APPLE - Adds support for compilation on MAC with moltenVK. Note that vulkan does not work on MacOS yet. There are two main blockers:- 1) Texture component swizzles are not supported except for RGBA8_UNORM->BGRA8_UNORM. 2) There is a bug in their SPIR-V -> MSL generator. GLSL.std.450.xxxx functions are not implemented which breaks rpcs3 functionality. Trying to compile a vertex shader will throw because unpackHalf2x16 is missing. --- rpcs3/Emu/RSX/VK/VKHelpers.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 36ef6b69fa..bb50cd478f 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -1679,6 +1679,7 @@ public: std::vector extensions; std::vector layers; +#ifndef __APPLE__ extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); #ifdef _WIN32 @@ -1704,10 +1705,9 @@ public: return 0; } #endif - if (!fast && g_cfg.video.debug_output) layers.push_back("VK_LAYER_LUNARG_standard_validation"); - +#endif VkInstanceCreateInfo instance_info = {}; instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instance_info.pApplicationInfo = &app; @@ -1791,6 +1791,10 @@ public: VkSurfaceKHR surface; CHECK_RESULT(vkCreateWin32SurfaceKHR(m_instance, &createInfo, NULL, &surface)); +#elif defined(__APPLE__) + using swapchain_NATIVE = swapchain_X11; + VkSurfaceKHR surface; + #else using swapchain_NATIVE = swapchain_X11; VkSurfaceKHR surface; @@ -1818,14 +1822,15 @@ public: #endif uint32_t device_queues = dev.get_queue_count(); - std::vector supportsPresent(device_queues); + std::vector supportsPresent(device_queues, VK_FALSE); + bool present_possible = false; +#ifndef __APPLE__ for (u32 index = 0; index < device_queues; index++) { vkGetPhysicalDeviceSurfaceSupportKHR(dev, index, surface, &supportsPresent[index]); } - bool present_possible = false; for (const auto &value : supportsPresent) { if (value) @@ -1839,6 +1844,7 @@ public: { LOG_ERROR(RSX, "It is not possible for the currently selected GPU to present to the window (Likely caused by NVIDIA driver running the current display)"); } +#endif // Search for a graphics and a present queue in the array of queue // families, try to find one that supports both @@ -1897,6 +1903,10 @@ public: return swapchain; } +#ifdef __APPLE__ + fmt::throw_exception("Unreachable" HERE); +#endif + // Get the list of VkFormat's that are supported: uint32_t formatCount; CHECK_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, nullptr));