Keep the Qualcomm-only gamescope patches out of the regular gamescope

0120 (nested swapchain capability fallback) and 0124 (SDL explicit refresh)
only matter for gamescope's SDL backend, which only Qualcomm sessions use.
In tools/gamescope/patches they would go into the next regular gamescope
release for every user. They now live in tools/qualcomm/gamescope-patches;
build_gamescope.py reads both folders in name order, so the Qualcomm build
applies the same series as before.

0121 and 0123 only change anything on PowerVR (vendor 0x1010) and are dropped.
0122 is renamed 0122-dmabuf-import-memory-type: it keeps the part every
vendor uses (the imported DMA-BUF's memory type must also be allowed by
vkGetMemoryFdPropertiesKHR) and drops the PowerVR-only query retry.

The full series still applies to gamescope 8f212644 (3.16.29).
This commit is contained in:
The412Banner committed 2026-10-25 23:13:44 +00:00
1 parent 614f2d4ec1
commit 18735361d7
6 files changed
+35 -146

No files matched your search

+1 -1
View File
@@ -54,7 +54,7 @@ The same lock pins a vendor-neutral X11 WSI layer and upstream Gamescope shader
Qualcomm 0.842.44 traps in its LLVM shader compiler when Gamescope dynamically indexes YUV sampler arrays. The constant-index switch preserves the eight-layer selection. The inner X11 WSI layer uses shared-memory copies; this is a compatibility path with additional CPU and memory-bandwidth cost. Steam additionally needs a larger `glibc.rtld.optional_static_tls` reserve because it loads the Bionic TLS bridge late.
The private Gamescope is built from Valve revision `8f212644c46460549035971ab914421180f61a7c` with the regular DroidDeck patches, the additional SHM/cursor patches in `gamescope-patches`, the constant YUV sampler patch, and `gamescope-no-dmabuf.patch`. The additional integration patches were taken from `wallentx/DroidDeck` revision `c931c4de26339c50f92354b9b06f6fdf7043ca8f`. The corresponding source is packaged in the APK. Upstream integration references:
The private Gamescope is built from Valve revision `8f212644c46460549035971ab914421180f61a7c` with the regular DroidDeck patches, the additional patches in `gamescope-patches` (nested SDL swapchain and refresh handling, DMA-BUF import memory types, SHM/cursor presentation), the constant YUV sampler patch, and `gamescope-no-dmabuf.patch`. The additional integration patches were taken from `wallentx/DroidDeck` revision `c931c4de26339c50f92354b9b06f6fdf7043ca8f`. The corresponding source is packaged in the APK. Upstream integration references:
- [DroidDeck fork at the producer revision](https://github.com/wallentx/DroidDeck/tree/af320dd86c7de5738ff16cfeeefbcf42581c199e/tools/gamescope)
- [libhybris runtime builder and patches](https://github.com/wallentx/DroidDeck/tree/4ed93fb9ee6e2a0b24ff087196f2e93d247fd985/tools/hybris)
@@ -0,0 +1,358 @@
diff --git a/src/nested_swapchain.hpp b/src/nested_swapchain.hpp
new file mode 100644
index 0000000..06fc987
--- /dev/null
+++ b/src/nested_swapchain.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <algorithm>
+#include <vulkan/vulkan_core.h>
+
+namespace gamescope
+{
+struct NestedSwapchainConfig
+{
+ bool copy = false;
+ uint32_t imageCount = 0;
+ VkImageUsageFlags usage = 0;
+ VkCompositeAlphaFlagBitsKHR alpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
+ VkExtent2D extent = {};
+};
+
+inline bool ChooseNestedSwapchainConfig( const VkSurfaceCapabilitiesKHR &caps,
+ bool mutableFormat, uint32_t width, uint32_t height, NestedSwapchainConfig &config )
+{
+ constexpr VkImageUsageFlags direct = VK_IMAGE_USAGE_SAMPLED_BIT |
+ VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+ config.copy = !mutableFormat || ( caps.supportedUsageFlags & direct ) != direct;
+ config.usage = config.copy ? VkImageUsageFlags{VK_IMAGE_USAGE_TRANSFER_DST_BIT} : direct;
+ if ( ( caps.supportedUsageFlags & config.usage ) != config.usage )
+ return false;
+
+ bool foundAlpha = false;
+ for ( auto alpha : { VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR,
+ VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR, VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR } )
+ {
+ if ( caps.supportedCompositeAlpha & alpha )
+ {
+ config.alpha = alpha;
+ foundAlpha = true;
+ break;
+ }
+ }
+ if ( !foundAlpha || caps.maxImageExtent.width < caps.minImageExtent.width ||
+ caps.maxImageExtent.height < caps.minImageExtent.height )
+ return false;
+
+ config.imageCount = caps.minImageCount + ( caps.minImageCount != UINT32_MAX );
+ if ( caps.maxImageCount )
+ config.imageCount = std::min( config.imageCount, caps.maxImageCount );
+ if ( config.imageCount < caps.minImageCount )
+ return false;
+ config.extent = caps.currentExtent.width == UINT32_MAX
+ ? VkExtent2D{ std::clamp( width, caps.minImageExtent.width, caps.maxImageExtent.width ),
+ std::clamp( height, caps.minImageExtent.height, caps.maxImageExtent.height ) }
+ : caps.currentExtent;
+ return config.extent.width && config.extent.height;
+}
+}
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
index ffad695..ffc8e28 100644
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -12,6 +12,7 @@
#include <deque>
#include <dlfcn.h>
#include "vulkan_include.h"
+#include "nested_swapchain.hpp"
#include "Utils/Algorithm.h"
#if defined(__linux__)
@@ -450,6 +451,8 @@ bool CVulkanDevice::createDevice()
bool hasDrmProps = vulkan_has_drm_props();
bool supportsForeignQueue = false;
bool supportsHDRMetadata = false;
+ bool presentIdExtension = false;
+ bool presentWaitExtension = false;
for (const auto& ext : m_supportedExts) {
if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 )
m_bSupportsModifiers = true;
@@ -457,6 +460,13 @@ bool CVulkanDevice::createDevice()
if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 )
supportsForeignQueue = true;
+ if ( strcmp(ext.extensionName, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME) == 0 )
+ m_bSupportsMutableSwapchain = true;
+ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_ID_EXTENSION_NAME) == 0 )
+ presentIdExtension = true;
+ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0 )
+ presentWaitExtension = true;
+
if ( strcmp(ext.extensionName, VK_EXT_HDR_METADATA_EXTENSION_NAME) == 0 )
supportsHDRMetadata = true;
}
@@ -576,10 +586,24 @@ bool CVulkanDevice::createDevice()
if ( GetBackend()->UsesVulkanSwapchain() )
{
enabledExtensions.push_back( VK_KHR_SWAPCHAIN_EXTENSION_NAME );
- enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME );
+ if ( m_bSupportsMutableSwapchain )
+ 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 ( presentIdExtension && presentWaitExtension )
+ {
+ VkPhysicalDevicePresentWaitFeaturesKHR wait = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR };
+ VkPhysicalDevicePresentIdFeaturesKHR id = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, .pNext = &wait };
+ VkPhysicalDeviceFeatures2 features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &id };
+ vk.GetPhysicalDeviceFeatures2( physDev(), &features );
+ m_bSupportsPresentWait = id.presentId && wait.presentWait;
+ }
+ if ( m_bSupportsPresentWait )
+ {
+ enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME );
+ enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME );
+ }
+ else
+ vk_log.infof( "Using FIFO acquire pacing; presentation timestamps unavailable" );
if ( supportsHDRMetadata )
enabledExtensions.push_back( VK_EXT_HDR_METADATA_EXTENSION_NAME );
@@ -654,7 +678,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 ),
.features = {
.shaderInt16 = m_bSupportsFp16,
},
@@ -2660,7 +2684,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
return true;
}
-bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format )
+bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format, bool transferOnly )
{
m_drmFormat = VulkanFormatToDRM( format );
m_vkImage = image;
@@ -2672,6 +2696,12 @@ bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t
m_contentWidth = width;
m_contentHeight = height;
m_bOutputImage = true;
+ if ( transferOnly )
+ {
+ // A copy destination needs no views (and the swapchain need not be mutable).
+ m_bInitialized = true;
+ return true;
+ }
VkImageViewCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -3094,7 +3124,7 @@ void vulkan_present_to_window( void )
VkPresentInfoKHR presentInfo = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
- .pNext = &presentIdInfo,
+ .pNext = g_device.supportsPresentWait() ? &presentIdInfo : nullptr,
.swapchainCount = 1,
.pSwapchains = &g_output.swapChain,
.pImageIndices = &g_output.nOutImage,
@@ -3102,14 +3132,22 @@ 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() )
+ {
+ g_currentPresentWaitId = presentId;
+ g_currentPresentWaitId.notify_all();
+ }
}
else
vulkan_remake_swapchain();
while ( !acquire_next_image() )
vulkan_remake_swapchain();
+ if ( !g_device.supportsPresentWait() )
+ {
+ // Estimated scheduling anchor after FIFO buffer acquisition, not presentation feedback.
+ GetVBlankTimer().MarkVBlank( get_time_in_nanos(), true );
+ }
}
gamescope::Rc<CVulkanTexture> vulkan_create_1d_lut(uint32_t size)
@@ -3219,7 +3257,19 @@ extern bool g_bOutputHDREnabled;
bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
{
- uint32_t imageCount = pOutput->surfaceCaps.minImageCount + 1;
+ // Re-query on resize as well as initial creation.
+ if ( g_device.vk.GetPhysicalDeviceSurfaceCapabilitiesKHR( g_device.physDev(), pOutput->surface, &pOutput->surfaceCaps ) != VK_SUCCESS )
+ return false;
+ gamescope::NestedSwapchainConfig config;
+ if ( !gamescope::ChooseNestedSwapchainConfig( pOutput->surfaceCaps, g_device.supportsMutableSwapchain(), g_nOutputWidth, g_nOutputHeight, config ) )
+ {
+ vk_log.errorf( "Surface supports neither direct composition nor transfer presentation" );
+ return false;
+ }
+ pOutput->copyToSwapchain = config.copy;
+ g_nOutputWidth = config.extent.width;
+ g_nOutputHeight = config.extent.height;
+ uint32_t imageCount = config.imageCount;
uint32_t formatCount = pOutput->surfaceFormats.size();
uint32_t surfaceFormat = formatCount;
VkColorSpaceKHR preferredColorSpace = g_bOutputHDREnabled ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
@@ -3254,6 +3304,13 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
}
}
+ if ( surfaceFormat == formatCount )
+ {
+ for ( surfaceFormat = 0; surfaceFormat < formatCount; ++surfaceFormat )
+ if ( pOutput->surfaceFormats[surfaceFormat].format == VK_FORMAT_R8G8B8A8_UNORM &&
+ pOutput->surfaceFormats[surfaceFormat].colorSpace == preferredColorSpace )
+ break;
+ }
if ( surfaceFormat == formatCount )
return false;
@@ -3276,8 +3333,8 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
VkSwapchainCreateInfoKHR createInfo = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
- .pNext = formats[0] != formats[1] ? &usageListInfo : nullptr,
- .flags = formats[0] != formats[1] ? VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR : (VkSwapchainCreateFlagBitsKHR )0,
+ .pNext = !config.copy && formats[0] != formats[1] ? &usageListInfo : nullptr,
+ .flags = !config.copy && formats[0] != formats[1] ? VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR : (VkSwapchainCreateFlagBitsKHR )0,
.surface = pOutput->surface,
.minImageCount = imageCount,
.imageFormat = eVkFormat,
@@ -3287,10 +3344,10 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
.height = g_nOutputHeight,
},
.imageArrayLayers = 1,
- .imageUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
+ .imageUsage = config.usage,
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
.preTransform = pOutput->surfaceCaps.currentTransform,
- .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
+ .compositeAlpha = config.alpha,
.presentMode = VK_PRESENT_MODE_FIFO_KHR,
.clipped = VK_TRUE,
};
@@ -3304,12 +3361,30 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
g_device.vk.GetSwapchainImagesKHR( g_device.device(), pOutput->swapChain, &imageCount, swapchainImages.data() );
pOutput->outputImages.resize(imageCount);
+ pOutput->presentationImages.clear();
+ if ( config.copy )
+ {
+ vk_log.infof( "Nested swapchain: composing offscreen and copying to FIFO presentation images" );
+ pOutput->presentationImages.resize(imageCount);
+ }
for ( uint32_t i = 0; i < pOutput->outputImages.size(); i++ )
{
pOutput->outputImages[i] = new CVulkanTexture();
- if ( !pOutput->outputImages[i]->BInitFromSwapchain(swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat))
+ if ( config.copy )
+ {
+ CVulkanTexture::createFlags flags;
+ flags.bStorage = true;
+ flags.bSampled = true;
+ flags.bTransferSrc = true;
+ if ( !pOutput->outputImages[i]->BInit( g_nOutputWidth, g_nOutputHeight, 1, pOutput->uOutputFormat, flags ) )
+ return false;
+ pOutput->presentationImages[i] = new CVulkanTexture();
+ if ( !pOutput->presentationImages[i]->BInitFromSwapchain( swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat, true ) )
+ return false;
+ }
+ else if ( !pOutput->outputImages[i]->BInitFromSwapchain(swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat))
return false;
}
@@ -3335,6 +3410,10 @@ bool vulkan_remake_swapchain( void )
g_device.vk.QueueWaitIdle( g_device.queue() );
pOutput->outputImages.clear();
+ pOutput->presentationImages.clear();
+ if ( pOutput->acquireFence )
+ g_device.vk.DestroyFence( g_device.device(), pOutput->acquireFence, nullptr );
+ pOutput->acquireFence = VK_NULL_HANDLE;
g_device.vk.DestroySwapchainKHR( g_device.device(), pOutput->swapChain, nullptr );
@@ -3670,7 +3749,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();
@@ -4579,6 +4658,9 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco
CompositeTimingEnd( cmdBuffer.get(), *oTimingSlot, pszKey, pszKeyPre, pszKeyPost );
}
+ if ( !pOutputOverride && g_output.copyToSwapchain )
+ cmdBuffer->copyImage( compositeImage, g_output.presentationImages[g_output.nOutImage] );
+
uint64_t sequence = g_device.submit(std::move(cmdBuffer));
if ( oTimingSlot )
g_CompositeTiming.pending.back().ulSeqNo = sequence;
diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
index fa519db..674a3b4 100644
--- a/src/rendervulkan.hpp
+++ b/src/rendervulkan.hpp
@@ -162,7 +162,7 @@ public:
};
bool 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 = nullptr, gamescope::OwningRc<gamescope::IBackendFb> pBackendFb = nullptr );
- bool BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format );
+ bool BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format, bool transferOnly = false );
uint32_t IncRef();
uint32_t DecRef();
@@ -586,7 +586,9 @@ struct VulkanOutput_t
std::shared_ptr<gamescope::BackendBlob> swapchainHDRMetadata;
VkSwapchainKHR swapChain;
- VkFence acquireFence;
+ VkFence acquireFence = VK_NULL_HANDLE;
+ bool copyToSwapchain = false;
+ std::vector<gamescope::OwningRc<CVulkanTexture>> presentationImages;
uint32_t nOutImage; // swapchain index in nested mode, or ping/pong between two RTs
std::vector<gamescope::OwningRc<CVulkanTexture>> outputImages;
@@ -756,6 +758,7 @@ static inline uint32_t div_roundup(uint32_t x, uint32_t y)
VK_FUNC(CreateDescriptorPool) \
VK_FUNC(CreateDescriptorSetLayout) \
VK_FUNC(CreateFence) \
+ VK_FUNC(DestroyFence) \
VK_FUNC(CreateGraphicsPipelines) \
VK_FUNC(CreateImage) \
VK_FUNC(CreateImageView) \
@@ -862,6 +865,8 @@ public:
inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;}
inline int drmRenderFd() {return m_drmRendererFd;}
inline bool supportsModifiers() {return m_bSupportsModifiers;}
+ inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;}
+ 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 +935,8 @@ protected:
uint32_t m_uVendorID = 0;
bool m_bHasDrmPrimaryDevId = false;
bool m_bSupportsModifiers = false;
+ bool m_bSupportsMutableSwapchain = false;
+ bool m_bSupportsPresentWait = false;
bool m_bInitialized = false;
@@ -1,15 +0,0 @@
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -996,8 +996,9 @@
SHADER(BLUR, cs_composite_blur);
SHADER(BLUR_COND, cs_composite_blur_cond);
SHADER(BLUR_FIRST_PASS, cs_gaussian_blur_horizontal);
- // The one pixel layout is only measured on Adreno, every other vendor keeps the quad swizzle.
- if (m_uVendorID == 0x5143) /* Qualcomm */
+ // PowerVR rejects the quad-swizzled RCAS for 3+ layers with YCbCr mask 2.
+ // The existing one-pixel shader compiles those variants and covers the same 16x16 tile.
+ if (m_uVendorID == 0x5143 || m_uVendorID == 0x1010) /* Qualcomm or Imagination */
{
SHADER(RCAS, cs_composite_rcas_1px);
}
@@ -1,4 +1,32 @@
diff --git a/src/dmabuf_import.hpp b/src/dmabuf_import.hpp
new file mode 100644
index 0000000..ffa002b
--- /dev/null
+++ b/src/dmabuf_import.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include <vulkan/vulkan_core.h>
+
+namespace gamescope
+{
+inline uint32_t DmabufMemoryType( const VkPhysicalDeviceMemoryProperties &memory,
+ uint32_t imageBits, uint32_t fdBits, VkMemoryPropertyFlags preferred )
+{
+ uint32_t fallback = UINT32_MAX;
+ const uint32_t compatible = imageBits & fdBits;
+ for ( uint32_t i = 0; i < memory.memoryTypeCount; ++i )
+ {
+ if ( !( compatible & ( 1u << i ) ) ) continue;
+ if ( fallback == UINT32_MAX ) fallback = i;
+ if ( ( memory.memoryTypes[i].propertyFlags & preferred ) == preferred ) return i;
+ }
+ // Device-local is a preference for an existing imported buffer. CPU mapping
+ // properties are requirements and must never be silently relaxed.
+ return preferred == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? fallback : UINT32_MAX;
+}
+}
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
index a5d9bbb..8d9f8f9 100644
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -13,6 +13,7 @@
@@ -9,37 +37,7 @@ diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
#include "Utils/Algorithm.h"
#if defined(__linux__)
@@ -2229,8 +2230,27 @@
return false;
}
- if ( res == VK_SUCCESS &&
- ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT ) )
+ bool importable = res == VK_SUCCESS &&
+ ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT );
+ if ( gamescope::RetryPowerVRLinearQuery( g_device.vendorID(), imageInfo.format,
+ pDMA->modifier, pDMA->n_planes, imageInfo.flags, res ) )
+ {
+ // PowerVR's mutable-format query rejects this linear import even though
+ // explicit-layout imports and UNORM/sRGB GPU sampling work. Query the base
+ // format without changing the image we actually create or its supplied stride.
+ VkImageCreateInfo baseFormat = imageInfo;
+ baseFormat.flags &= ~VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
+ baseFormat.pNext = nullptr;
+ res = getModifierProps( &baseFormat, pDMA->modifier, &externalImageProperties );
+ importable = res == VK_SUCCESS &&
+ ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT );
+ }
+ if ( !importable && g_device.vendorID() == 0x1010 )
+ {
+ vk_log.errorf( "PowerVR DMA-BUF modifier is not importable; refusing a different tiling" );
+ return false;
+ }
+ if ( importable )
{
modifierInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT,
@@ -2348,6 +2368,22 @@
@@ -2347,6 +2348,22 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
m_format = imageInfo.format;
@@ -62,7 +60,7 @@ diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
res = g_device.vk.CreateImage(g_device.device(), &imageInfo, nullptr, &m_vkImage);
if (res != VK_SUCCESS) {
vk_errorf( res, "vkCreateImage failed" );
@@ -2357,10 +2393,22 @@
@@ -2356,10 +2373,22 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
VkMemoryRequirements memRequirements;
g_device.vk.GetImageMemoryRequirements(g_device.device(), m_vkImage, &memRequirements);
@@ -86,7 +84,7 @@ diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
};
m_size = allocInfo.allocationSize;
@@ -2453,6 +2501,13 @@
@@ -2452,6 +2481,13 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
if ( res != VK_SUCCESS )
{
vk_errorf( res, "vkBindImageMemory failed" );
@@ -101,9 +99,10 @@ diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
}
diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
index 674a3b4..5ffec4a 100644
--- a/src/rendervulkan.hpp
+++ b/src/rendervulkan.hpp
@@ -791,6 +791,7 @@
@@ -791,6 +791,7 @@ static inline uint32_t div_roundup(uint32_t x, uint32_t y)
VK_FUNC(GetImageMemoryRequirements) \
VK_FUNC(GetImageSubresourceLayout) \
VK_FUNC(GetMemoryFdKHR) \
@@ -111,7 +110,7 @@ diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
VK_FUNC(GetQueryPoolResults) \
VK_FUNC(GetSemaphoreCounterValue) \
VK_FUNC(GetSwapchainImagesKHR) \
@@ -865,6 +866,8 @@
@@ -865,6 +866,8 @@ public:
inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;}
inline int drmRenderFd() {return m_drmRendererFd;}
inline bool supportsModifiers() {return m_bSupportsModifiers;}
@@ -120,37 +119,3 @@ diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;}
inline bool supportsPresentWait() {return m_bSupportsPresentWait;}
inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;}
diff --git a/src/dmabuf_import.hpp b/src/dmabuf_import.hpp
new file mode 100644
--- /dev/null
+++ b/src/dmabuf_import.hpp
@@ -0,0 +1,29 @@
+#pragma once
+#include <vulkan/vulkan_core.h>
+
+namespace gamescope
+{
+inline bool RetryPowerVRLinearQuery( uint32_t vendor, VkFormat format, uint64_t modifier,
+ uint32_t planes, VkImageCreateFlags flags, VkResult result )
+{
+ return vendor == 0x1010 && modifier == 0 && planes == 1 &&
+ flags == VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT && result == VK_ERROR_FORMAT_NOT_SUPPORTED &&
+ ( format == VK_FORMAT_R8G8B8A8_UNORM || format == VK_FORMAT_B8G8R8A8_UNORM );
+}
+
+inline uint32_t DmabufMemoryType( const VkPhysicalDeviceMemoryProperties &memory,
+ uint32_t imageBits, uint32_t fdBits, VkMemoryPropertyFlags preferred )
+{
+ uint32_t fallback = UINT32_MAX;
+ const uint32_t compatible = imageBits & fdBits;
+ for ( uint32_t i = 0; i < memory.memoryTypeCount; ++i )
+ {
+ if ( !( compatible & ( 1u << i ) ) ) continue;
+ if ( fallback == UINT32_MAX ) fallback = i;
+ if ( ( memory.memoryTypes[i].propertyFlags & preferred ) == preferred ) return i;
+ }
+ // Device-local is a preference for an existing imported buffer. CPU mapping
+ // properties are requirements and must never be silently relaxed.
+ return preferred == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? fallback : UINT32_MAX;
+}
+}
@@ -1,61 +0,0 @@
diff --git a/src/nested_surface_format.hpp b/src/nested_surface_format.hpp
new file mode 100644
--- /dev/null
+++ b/src/nested_surface_format.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <vulkan/vulkan_core.h>
+
+namespace gamescope
+{
+// The SDR composition shader declares rgba8, which requires an R8G8B8A8_UNORM
+// storage view. Binding a BGRA view is a format mismatch; a same-format copy
+// cannot correct it. Keep the workaround scoped to the PowerVR SDR copy path
+// where the channel reversal was reproduced, not game-facing texture formats.
+// On success, formatCount means the existing selector should choose the format.
+// On failure, no matching RGBA SDR surface was advertised for this scoped path.
+inline bool ChooseNestedSDRCopySurfaceFormat( uint32_t vendorId, bool copy, bool hdr,
+ const VkSurfaceFormatKHR *formats, uint32_t formatCount, uint32_t &surfaceFormat )
+{
+ surfaceFormat = formatCount;
+ if ( vendorId != 0x1010 || !copy || hdr )
+ return true;
+
+ for ( uint32_t i = 0; i < formatCount; ++i )
+ {
+ if ( formats[i].format == VK_FORMAT_R8G8B8A8_UNORM &&
+ formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR )
+ {
+ surfaceFormat = i;
+ return true;
+ }
+ }
+ return false;
+}
+}
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -14,6 +14,7 @@
#include "vulkan_include.h"
#include "nested_swapchain.hpp"
#include "dmabuf_import.hpp"
+#include "nested_surface_format.hpp"
#include "Utils/Algorithm.h"
#if defined(__linux__)
@@ -3330,6 +3331,13 @@
uint32_t surfaceFormat = formatCount;
VkColorSpaceKHR preferredColorSpace = g_bOutputHDREnabled ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
+ if ( !gamescope::ChooseNestedSDRCopySurfaceFormat( g_device.vendorID(), config.copy,
+ g_bOutputHDREnabled, pOutput->surfaceFormats.data(), formatCount, surfaceFormat ) )
+ {
+ vk_log.errorf( "PowerVR copy composition requires an RGBA SDR surface" );
+ return false;
+ }
+
if ( surfaceFormat == formatCount )
{
for ( surfaceFormat = 0; surfaceFormat < formatCount; surfaceFormat++ )
@@ -0,0 +1,78 @@
diff --git a/src/sdl_refresh.hpp b/src/sdl_refresh.hpp
new file mode 100644
--- /dev/null
+++ b/src/sdl_refresh.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <cstdint>
+
+namespace gamescope
+{
+struct SDLRefreshChoice
+{
+ int32_t refresh = 0;
+ bool configured = false;
+};
+
+// SDL reports the desktop mode again when its window is shown, moved or resized. Keep an
+// explicit -r as the rate exposed by nested Gamescope; discover the desktop rate only when the
+// caller did not configure one.
+inline constexpr SDLRefreshChoice ChooseSDLRefresh( int32_t configuredRefresh, int32_t desktopRefresh )
+{
+ return configuredRefresh > 0
+ ? SDLRefreshChoice{ configuredRefresh, true }
+ : SDLRefreshChoice{ desktopRefresh, false };
+}
+}
diff --git a/src/Backends/SDLBackend.cpp b/src/Backends/SDLBackend.cpp
--- a/src/Backends/SDLBackend.cpp
+++ b/src/Backends/SDLBackend.cpp
@@ -18,14 +18,20 @@
#include "steamcompmgr.hpp"
#include "Utils/Defer.h"
#include "refresh_rate.h"
+#include "log.hpp"
+#include "sdl_refresh.hpp"
#include "sdlscancodetable.hpp"
static int g_nOldNestedRefresh = 0;
static bool g_bWindowFocused = true;
+static int g_nLastLoggedConfiguredRefresh = -1;
+static int g_nLastLoggedDesktopRefresh = -1;
+static int g_nLastLoggedEffectiveRefresh = -1;
static int g_nOutputWidthPts = 0;
static int g_nOutputHeightPts = 0;
+static LogScope sdl_log( "sdl_backend" );
extern bool g_bForceHDR10OutputDebug;
extern bool steamMode;
@@ -846,9 +851,25 @@ namespace gamescope
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
display_index = SDL_GetWindowDisplayIndex( m_Connector.GetSDLWindow() );
if ( SDL_GetDesktopDisplayMode( display_index, &mode ) == 0 )
{
- g_nOutputRefresh = ConvertHztomHz( mode.refresh_rate );
+ const int nDesktopRefresh = ConvertHztomHz( mode.refresh_rate );
+ const SDLRefreshChoice refresh = ChooseSDLRefresh( g_nOldNestedRefresh, nDesktopRefresh );
+ g_nOutputRefresh = refresh.refresh;
+
+ if ( g_nLastLoggedConfiguredRefresh != g_nOldNestedRefresh ||
+ g_nLastLoggedDesktopRefresh != nDesktopRefresh ||
+ g_nLastLoggedEffectiveRefresh != refresh.refresh )
+ {
+ sdl_log.infof( "Refresh mode: configured=%.3fHz desktop=%.3fHz effective=%.3fHz source=%s",
+ ConvertmHzToHz( float( g_nOldNestedRefresh ) ),
+ ConvertmHzToHz( float( nDesktopRefresh ) ),
+ ConvertmHzToHz( float( refresh.refresh ) ),
+ refresh.configured ? "configured -r" : "SDL desktop" );
+ g_nLastLoggedConfiguredRefresh = g_nOldNestedRefresh;
+ g_nLastLoggedDesktopRefresh = nDesktopRefresh;
+ g_nLastLoggedEffectiveRefresh = refresh.refresh;
+ }
}
}
break;