Keep swapchain textures local instead of exporting scan-out buffers

This commit is contained in:
xXJsonDeruloXx committed 2026-10-03 14:39:51 -04:00
1 parent 2ece5b7314
commit dcd2641a90
2 files changed
+80 -15

No files matched your search

@@ -1,16 +1,25 @@
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
index 54e4efc..93038f2 100644
index 54e4efc..88a6353 100644
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -452,0 +453,2 @@ bool CVulkanDevice::createDevice()
@@ -450,7 +450,13 @@ bool CVulkanDevice::createDevice()
bool hasDrmProps = vulkan_has_drm_props();
bool supportsForeignQueue = false;
bool supportsHDRMetadata = false;
+ bool supportsPresentId = false;
+ bool supportsPresentWait = false;
@@ -453,0 +456,4 @@ bool CVulkanDevice::createDevice()
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;
@@ -520,0 +527,19 @@ bool CVulkanDevice::createDevice()
if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 )
m_bSupportsModifiers = true;
@@ -518,6 +524,25 @@ bool CVulkanDevice::createDevice()
m_bSupportsModifiers = false;
}
+ if ( supportsPresentId && supportsPresentWait )
+ {
+ VkPhysicalDevicePresentWaitFeaturesKHR waitFeatures = {
@@ -30,7 +39,13 @@ index 54e4efc..93038f2 100644
+ if ( GetBackend()->UsesVulkanSwapchain() && !m_bSupportsPresentWait )
+ vk_log.infof( "Present ID/wait unavailable; using timer-based pacing." );
+
@@ -573,2 +598,5 @@ bool CVulkanDevice::createDevice()
{
VkPhysicalDeviceVulkan12Features vulkan12Features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
@@ -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 );
- enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME );
- enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME );
+ if ( m_bSupportsPresentWait )
@@ -38,13 +53,44 @@ index 54e4efc..93038f2 100644
+ enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME );
+ enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME );
+ }
@@ -649 +677 @@ bool CVulkanDevice::createDevice()
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,
- .pNext = &presentIdFeatures,
+ .pNext = m_bSupportsPresentWait ? static_cast<void *>( &presentIdFeatures ) : static_cast<void *>( &features13 ),
@@ -3089 +3117 @@ void vulkan_present_to_window( void )
.features = {
.shaderInt16 = m_bSupportsFp16,
},
@@ -2082,6 +2110,12 @@ static VkImageViewType VulkanImageTypeToViewType(VkImageType type)
bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA /* = nullptr */, uint32_t contentWidth /* = 0 */, uint32_t contentHeight /* = 0 */, CVulkanTexture *pExistingImageToReuseMemory, gamescope::OwningRc<gamescope::IBackendFb> pBackendFb )
{
+ // Swapchain backends composite into their own images; textures are never scanned out.
+ // Keep explicit exports and dma-buf imports, but do not require a DRM export for local
+ // cursor, blank, or wl_shm textures (Lavapipe has no DRM allocator).
+ if ( GetBackend()->UsesVulkanSwapchain() )
+ flags.bFlippable = false;
+
m_pBackendFb = std::move( pBackendFb );
m_drmFormat = drmFormat;
VkResult res = VK_ERROR_INITIALIZATION_FAILED;
@@ -3086,7 +3120,7 @@ void vulkan_present_to_window( void )
VkPresentInfoKHR presentInfo = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
- .pNext = &presentIdInfo,
+ .pNext = g_device.supportsPresentWait() ? &presentIdInfo : nullptr,
@@ -3097,2 +3125,5 @@ void vulkan_present_to_window( void )
.swapchainCount = 1,
.pSwapchains = &g_output.swapChain,
.pImageIndices = &g_output.nOutImage,
@@ -3094,8 +3128,11 @@ void vulkan_present_to_window( void )
if ( g_device.vk.QueuePresentKHR( g_device.queue(), &presentInfo ) == VK_SUCCESS )
{
- g_currentPresentWaitId = presentId;
- g_currentPresentWaitId.notify_all();
+ if ( g_device.supportsPresentWait() )
@@ -52,18 +98,35 @@ index 54e4efc..93038f2 100644
+ g_currentPresentWaitId = presentId;
+ g_currentPresentWaitId.notify_all();
+ }
@@ -3164 +3195,2 @@ gamescope::OwningRc<CVulkanTexture> 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();
@@ -3665 +3697 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface )
}
else
vulkan_remake_swapchain();
@@ -3662,7 +3699,7 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface )
if (!init_nis_data())
return false;
- 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
@@ -864,0 +865 @@ public:
@@ -862,6 +862,7 @@ public:
inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;}
inline int drmRenderFd() {return m_drmRendererFd;}
inline bool supportsModifiers() {return m_bSupportsModifiers;}
+ inline bool supportsPresentWait() {return m_bSupportsPresentWait;}
@@ -932,0 +934 @@ protected:
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;
+ bool m_bSupportsPresentWait = false;
bool m_bInitialized = false;