From e3540ccd17193e131d42290a9dd4d6bca6e5f634 Mon Sep 17 00:00:00 2001 From: Conrad Kreyling Date: Mon, 30 Nov 2020 20:31:14 -0500 Subject: [PATCH] First pass on using Display KHR, needs proper init flags --- CMakeLists.txt | 7 +++++++ Common/GPU/Vulkan/VulkanContext.cpp | 14 ++++++++++++++ Common/GPU/Vulkan/VulkanContext.h | 3 +++ Common/GPU/Vulkan/VulkanLoader.cpp | 6 ++++++ Common/GPU/Vulkan/VulkanLoader.h | 3 +++ libretro/LibretroVulkanContext.cpp | 2 ++ libretro/libretro_vulkan.cpp | 3 +++ 7 files changed, 38 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58502f15c6..40a4498bed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,7 @@ option(USING_FBDEV "Set to ON if target environment uses fbdev (eg. Pandora)" ${ option(USING_GLES2 "Set to ON if target device uses OpenGL ES 2.0" ${USING_GLES2}) option(USING_X11_VULKAN "Set to OFF if target environment doesn't use X11 for Vulkan" ON) option(USE_WAYLAND_WSI "Enable or disable Wayland WSI support for Vulkan" ${USE_WAYLAND_WSI}) +option(USE_VULKAN_DISPLAY_KHR "Enable or disable full screen display of Vulkan" ${USE_VULKAN_DISPLAY_KHR}) # :: Frontends option(USING_QT_UI "Set to ON if you wish to use the Qt frontend wrapper" ${USING_QT_UI}) option(MOBILE_DEVICE "Set to ON when targeting a mobile device" ${MOBILE_DEVICE}) @@ -143,6 +144,7 @@ if(UNIX AND NOT (APPLE OR ANDROID) AND VULKAN) else() message("NOT using X11 for Vulkan") endif() + # add_definitions(-DVK_USE_PLATFORM_XCB_KHR) if(USE_WAYLAND_WSI) find_package(Wayland) @@ -153,6 +155,11 @@ if(UNIX AND NOT (APPLE OR ANDROID) AND VULKAN) add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR) endif() endif() + + if(USE_VULKAN_DISPLAY_KHR) + message(STATUS "Using experimental full-screen display for Vulkan.") + add_definitions(-DVK_USE_PLATFORM_DISPLAY_KHR) + endif() endif() if(LIBRETRO) diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index bf77c2720f..1ab627512c 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -123,6 +123,11 @@ VkResult VulkanContext::CreateInstance(const CreateInfo &info) { instance_extensions_enabled_.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); } #endif +#if defined(VK_USE_PLATFORM_DISPLAY_KHR) + if (IsInstanceExtensionAvailable(VK_KHR_DISPLAY_EXTENSION_NAME)) { + instance_extensions_enabled_.push_back(VK_KHR_DISPLAY_EXTENSION_NAME); + } +#endif #if defined(VK_USE_PLATFORM_METAL_EXT) if (IsInstanceExtensionAvailable(VK_EXT_METAL_SURFACE_EXTENSION_NAME)) { instance_extensions_enabled_.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME); @@ -795,6 +800,15 @@ VkResult VulkanContext::ReinitSurface() { break; } #endif +#if defined(VK_USE_PLATFORM_DISPLAY_KHR) + case WINDOWSYSTEM_DISPLAY: + { + VkDisplaySurfaceCreateInfoKHR display{ VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR }; + display.flags = 0; + retval = vkCreateDisplayPlaneSurfaceKHR(instance_, &display, nullptr, &surface_); + break; + } +#endif default: _assert_msg_(false, "Vulkan support for chosen window system not implemented"); diff --git a/Common/GPU/Vulkan/VulkanContext.h b/Common/GPU/Vulkan/VulkanContext.h index 3798066c65..a277561800 100644 --- a/Common/GPU/Vulkan/VulkanContext.h +++ b/Common/GPU/Vulkan/VulkanContext.h @@ -48,6 +48,9 @@ enum WindowSystem { #ifdef VK_USE_PLATFORM_WAYLAND_KHR WINDOWSYSTEM_WAYLAND, #endif +#ifdef VK_USE_PLATFORM_DISPLAY_KHR + WINDOWSYSTEM_DISPLAY, +#endif }; struct VulkanPhysicalDeviceInfo { diff --git a/Common/GPU/Vulkan/VulkanLoader.cpp b/Common/GPU/Vulkan/VulkanLoader.cpp index ad44606272..7471d07266 100644 --- a/Common/GPU/Vulkan/VulkanLoader.cpp +++ b/Common/GPU/Vulkan/VulkanLoader.cpp @@ -185,6 +185,9 @@ PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR; #if defined(VK_USE_PLATFORM_WAYLAND_KHR) PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR; #endif +#if defined(VK_USE_PLATFORM_DISPLAY_KHR) +PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR; +#endif PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR; @@ -532,6 +535,9 @@ void VulkanLoadInstanceFunctions(VkInstance instance, const VulkanExtensions &en #if defined(VK_USE_PLATFORM_WAYLAND_KHR) LOAD_INSTANCE_FUNC(instance, vkCreateWaylandSurfaceKHR); #endif +#if defined(VK_USE_PLATFORM_DISPLAY_KHR) + LOAD_INSTANCE_FUNC(instance, vkCreateDisplayPlaneSurfaceKHR); +#endif LOAD_INSTANCE_FUNC(instance, vkDestroySurfaceKHR); diff --git a/Common/GPU/Vulkan/VulkanLoader.h b/Common/GPU/Vulkan/VulkanLoader.h index c91ad6296c..02a2b947f0 100644 --- a/Common/GPU/Vulkan/VulkanLoader.h +++ b/Common/GPU/Vulkan/VulkanLoader.h @@ -184,6 +184,9 @@ extern PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR; #if defined(VK_USE_PLATFORM_WAYLAND_KHR) extern PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR; #endif +#if defined(VK_USE_PLATFORM_DISPLAY_KHR) +extern PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR; +#endif extern PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR; diff --git a/libretro/LibretroVulkanContext.cpp b/libretro/LibretroVulkanContext.cpp index 2b9e944360..98a2db727e 100644 --- a/libretro/LibretroVulkanContext.cpp +++ b/libretro/LibretroVulkanContext.cpp @@ -66,6 +66,8 @@ static bool create_device(retro_vulkan_context *context, VkInstance instance, Vk vk->InitSurface(WINDOWSYSTEM_XCB, nullptr, nullptr); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) vk->InitSurface(WINDOWSYSTEM_WAYLAND, nullptr, nullptr); +#elif defined(VK_USE_PLATFORM_DISPLAY_KHR) + vk->InitSurface(WINDOWSYSTEM_DISPLAY, nullptr, nullptr); #endif context->gpu = vk->GetPhysicalDevice(physical_device); diff --git a/libretro/libretro_vulkan.cpp b/libretro/libretro_vulkan.cpp index 1081f95e0b..8007d31d3f 100644 --- a/libretro/libretro_vulkan.cpp +++ b/libretro/libretro_vulkan.cpp @@ -372,6 +372,9 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr_libretro(VkInstan #endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR || !strcmp(pName, "vkCreateWaylandSurfaceKHR") +#endif +#ifdef VK_USE_PLATFORM_DISPLAY_KHR + || !strcmp(pName, "vkCreateDisplayPlaneSurfaceKHR") #endif ) { return (PFN_vkVoidFunction)vkCreateLibretroSurfaceKHR;