diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp index 7e68a44fb..65e35f525 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -2002,24 +2002,32 @@ namespace gamescope // Prefer opaque for composition on the Wayland backend. uint32_t u8BitFormat = DRM_FORMAT_INVALID; - if ( SupportsFormat( DRM_FORMAT_XRGB8888 ) ) - u8BitFormat = DRM_FORMAT_XRGB8888; - else if ( SupportsFormat( DRM_FORMAT_XBGR8888 ) ) - u8BitFormat = DRM_FORMAT_XBGR8888; - else if ( SupportsFormat( DRM_FORMAT_ARGB8888 ) ) - u8BitFormat = DRM_FORMAT_ARGB8888; - else if ( SupportsFormat( DRM_FORMAT_ABGR8888 ) ) - u8BitFormat = DRM_FORMAT_ABGR8888; + for (int i = 0; i < 2 && u8BitFormat == DRM_FORMAT_INVALID; i++) + { + bool invalidOnly = i == 0; + if ( SupportsFormat( DRM_FORMAT_XRGB8888, invalidOnly ) ) + u8BitFormat = DRM_FORMAT_XRGB8888; + else if ( SupportsFormat( DRM_FORMAT_XBGR8888, invalidOnly ) ) + u8BitFormat = DRM_FORMAT_XBGR8888; + else if ( SupportsFormat( DRM_FORMAT_ARGB8888, invalidOnly ) ) + u8BitFormat = DRM_FORMAT_ARGB8888; + else if ( SupportsFormat( DRM_FORMAT_ABGR8888, invalidOnly ) ) + u8BitFormat = DRM_FORMAT_ABGR8888; + } uint32_t u10BitFormat = DRM_FORMAT_INVALID; - if ( SupportsFormat( DRM_FORMAT_XBGR2101010 ) ) - u10BitFormat = DRM_FORMAT_XBGR2101010; - else if ( SupportsFormat( DRM_FORMAT_XRGB2101010 ) ) - u10BitFormat = DRM_FORMAT_XRGB2101010; - else if ( SupportsFormat( DRM_FORMAT_ABGR2101010 ) ) - u10BitFormat = DRM_FORMAT_ABGR2101010; - else if ( SupportsFormat( DRM_FORMAT_ARGB2101010 ) ) - u10BitFormat = DRM_FORMAT_ARGB2101010; + for (int i = 0; i < 2 && u10BitFormat == DRM_FORMAT_INVALID; i++) + { + bool invalidOnly = i == 0; + if ( SupportsFormat( DRM_FORMAT_XBGR2101010, invalidOnly ) ) + u10BitFormat = DRM_FORMAT_XBGR2101010; + else if ( SupportsFormat( DRM_FORMAT_XRGB2101010, invalidOnly ) ) + u10BitFormat = DRM_FORMAT_XRGB2101010; + else if ( SupportsFormat( DRM_FORMAT_ABGR2101010, invalidOnly ) ) + u10BitFormat = DRM_FORMAT_ABGR2101010; + else if ( SupportsFormat( DRM_FORMAT_ARGB2101010, invalidOnly ) ) + u10BitFormat = DRM_FORMAT_ARGB2101010; + } assert( u8BitFormat != DRM_FORMAT_INVALID ); diff --git a/src/backend.h b/src/backend.h index 29219dbc8..2767546cd 100644 --- a/src/backend.h +++ b/src/backend.h @@ -309,9 +309,11 @@ namespace gamescope virtual bool UsesModifiers() const = 0; virtual std::span GetSupportedModifiers( uint32_t uDrmFormat ) const = 0; - inline bool SupportsFormat( uint32_t uDrmFormat ) const + inline bool SupportsFormat( uint32_t uDrmFormat, bool invalidOnly ) const { - return Algorithm::Contains( this->GetSupportedModifiers( uDrmFormat ), DRM_FORMAT_MOD_INVALID ); + if ( invalidOnly ) + return Algorithm::Contains( this->GetSupportedModifiers( uDrmFormat ), DRM_FORMAT_MOD_INVALID ); + return !this->GetSupportedModifiers( uDrmFormat ).empty(); } virtual IBackendConnector *GetCurrentConnector() = 0; diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index b8412b8fd..f41ef4c9b 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -2814,7 +2814,7 @@ bool vulkan_init_format(VkFormat format, uint32_t drmFormat) } else { - if ( GetBackend()->UsesModifiers() && !GetBackend()->SupportsFormat( drmFormat ) ) + if ( GetBackend()->UsesModifiers() && !GetBackend()->SupportsFormat( drmFormat, true ) ) return false; wlr_drm_format_set_add( &sampledDRMFormats, drmFormat, DRM_FORMAT_MOD_INVALID );