From 2ece5b731426e22e25bc59dc00e609979210b170 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Sat, 3 Oct 2026 14:28:54 -0400 Subject: [PATCH] Query optional present features after selecting the Vulkan device --- tools/build_local.sh | 10 +- .../patches/0114-optional-present-wait.patch | 96 ++++--------------- 2 files changed, 26 insertions(+), 80 deletions(-) diff --git a/tools/build_local.sh b/tools/build_local.sh index a2efcbe89..67b9dacfd 100755 --- a/tools/build_local.sh +++ b/tools/build_local.sh @@ -209,8 +209,14 @@ cached() { if [[ -f "${repo_root}/tools/gamescope/release.env" ]]; then . "${repo_root}/tools/gamescope/release.env" - gamescope_archive=$(cached "${GAMESCOPE_SHA256}" gamescope.tzst \ - bash -c 'gh release download "$0" -R "$1" -p gamescope.tzst -O "$out"' "${GAMESCOPE_TAG}" "${github_repo}") + if [[ -n "${DROIDDECK_GAMESCOPE_BUNDLE:-}" ]]; then + gamescope_archive=${DROIDDECK_GAMESCOPE_BUNDLE} + test -f "${gamescope_archive}" + echo "Using local Gamescope bundle: ${gamescope_archive}" + else + gamescope_archive=$(cached "${GAMESCOPE_SHA256}" gamescope.tzst \ + bash -c 'gh release download "$0" -R "$1" -p gamescope.tzst -O "$out"' "${GAMESCOPE_TAG}" "${github_repo}") + fi zstd -dc "${gamescope_archive}" | tar -xf - -C "${linuxfs_dir}" test -f "${linuxfs_dir}/usr/local/bin/gamescope" fi diff --git a/tools/gamescope/patches/0114-optional-present-wait.patch b/tools/gamescope/patches/0114-optional-present-wait.patch index c91f19ef0..246986bfb 100644 --- a/tools/gamescope/patches/0114-optional-present-wait.patch +++ b/tools/gamescope/patches/0114-optional-present-wait.patch @@ -1,11 +1,16 @@ diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp -index 54e4efc..43239d8 100644 +index 54e4efc..93038f2 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp -@@ -349,6 +349,25 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) - } - - for (auto cphysDev : physDevs) +@@ -452,0 +453,2 @@ bool CVulkanDevice::createDevice() ++ bool supportsPresentId = false; ++ bool supportsPresentWait = false; +@@ -453,0 +456,4 @@ bool CVulkanDevice::createDevice() ++ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_ID_EXTENSION_NAME) == 0 ) ++ supportsPresentId = true; ++ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0 ) ++ supportsPresentWait = true; +@@ -520,0 +527,19 @@ bool CVulkanDevice::createDevice() + if ( supportsPresentId && supportsPresentWait ) + { + VkPhysicalDevicePresentWaitFeaturesKHR waitFeatures = { @@ -25,27 +30,7 @@ index 54e4efc..43239d8 100644 + if ( GetBackend()->UsesVulkanSwapchain() && !m_bSupportsPresentWait ) + vk_log.infof( "Present ID/wait unavailable; using timer-based pacing." ); + - { - VkPhysicalDeviceProperties deviceProperties; - vk.GetPhysicalDeviceProperties(cphysDev, &deviceProperties); -@@ -450,7 +469,13 @@ bool CVulkanDevice::createDevice() - bool hasDrmProps = vulkan_has_drm_props(); - bool supportsForeignQueue = false; - bool supportsHDRMetadata = false; -+ bool supportsPresentId = false; -+ bool supportsPresentWait = false; - for (const auto& ext : m_supportedExts) { -+ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_ID_EXTENSION_NAME) == 0 ) -+ supportsPresentId = true; -+ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0 ) -+ supportsPresentWait = true; - if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 ) - m_bSupportsModifiers = true; - -@@ -570,8 +595,11 @@ bool CVulkanDevice::createDevice() - enabledExtensions.push_back( VK_KHR_SWAPCHAIN_EXTENSION_NAME ); - enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME ); - +@@ -573,2 +598,5 @@ bool CVulkanDevice::createDevice() - enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME ); - enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME ); + if ( m_bSupportsPresentWait ) @@ -53,31 +38,13 @@ index 54e4efc..43239d8 100644 + enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME ); + enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME ); + } - - if ( supportsHDRMetadata ) - enabledExtensions.push_back( VK_EXT_HDR_METADATA_EXTENSION_NAME ); -@@ -646,7 +674,7 @@ bool CVulkanDevice::createDevice() - - VkPhysicalDeviceFeatures2 features2 = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, +@@ -649 +677 @@ bool CVulkanDevice::createDevice() - .pNext = &presentIdFeatures, + .pNext = m_bSupportsPresentWait ? static_cast( &presentIdFeatures ) : static_cast( &features13 ), - .features = { - .shaderInt16 = m_bSupportsFp16, - }, -@@ -3086,7 +3114,7 @@ void vulkan_present_to_window( void ) - - VkPresentInfoKHR presentInfo = { - .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, +@@ -3089 +3117 @@ void vulkan_present_to_window( void ) - .pNext = &presentIdInfo, + .pNext = g_device.supportsPresentWait() ? &presentIdInfo : nullptr, - .swapchainCount = 1, - .pSwapchains = &g_output.swapChain, - .pImageIndices = &g_output.nOutImage, -@@ -3094,8 +3122,11 @@ void vulkan_present_to_window( void ) - - if ( g_device.vk.QueuePresentKHR( g_device.queue(), &presentInfo ) == VK_SUCCESS ) - { +@@ -3097,2 +3125,5 @@ void vulkan_present_to_window( void ) - g_currentPresentWaitId = presentId; - g_currentPresentWaitId.notify_all(); + if ( g_device.supportsPresentWait() ) @@ -85,45 +52,18 @@ index 54e4efc..43239d8 100644 + g_currentPresentWaitId = presentId; + g_currentPresentWaitId.notify_all(); + } - } - else - vulkan_remake_swapchain(); -@@ -3161,7 +3192,8 @@ gamescope::Rc vulkan_get_hacky_blank_texture() - gamescope::OwningRc vulkan_create_flat_texture( uint32_t width, uint32_t height, uint8_t r, uint8_t g, uint8_t b, uint8_t a ) - { - CVulkanTexture::createFlags flags; +@@ -3164 +3195,2 @@ gamescope::OwningRc vulkan_create_flat_texture( uint32_t width, - flags.bFlippable = true; + // A swapchain backend samples this texture locally; it never scans it out. + flags.bFlippable = !GetBackend()->UsesVulkanSwapchain(); - flags.bSampled = true; - flags.bTransferDst = true; - -@@ -3662,7 +3694,7 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface ) - if (!init_nis_data()) - return false; - +@@ -3665 +3697 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface ) - if ( GetBackend()->UsesVulkanSwapchain() ) + if ( GetBackend()->UsesVulkanSwapchain() && g_device.supportsPresentWait() ) - { - std::thread present_wait_thread( present_wait_thread_func ); - present_wait_thread.detach(); diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index fa519db..91f7793 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp -@@ -862,6 +862,7 @@ public: - inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;} - inline int drmRenderFd() {return m_drmRendererFd;} - inline bool supportsModifiers() {return m_bSupportsModifiers;} +@@ -864,0 +865 @@ public: + inline bool supportsPresentWait() {return m_bSupportsPresentWait;} - inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;} - inline dev_t primaryDevId() {return m_drmPrimaryDevId;} - inline bool supportsFp16() {return m_bSupportsFp16;} -@@ -930,6 +931,7 @@ protected: - uint32_t m_uVendorID = 0; - bool m_bHasDrmPrimaryDevId = false; - bool m_bSupportsModifiers = false; +@@ -932,0 +934 @@ protected: + bool m_bSupportsPresentWait = false; - bool m_bInitialized = false; - -