Skip to content

Commit

Permalink
wayland_backend: Hopefully fix GPUs wehere modifiers are not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
misyltoad committed May 18, 2024
1 parent 12c4729 commit 4ca3986
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/wayland_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace gamescope

gamescope::ConVar<bool> cv_wayland_mouse_warp_without_keyboard_focus( "wayland_mouse_warp_without_keyboard_focus", true, "Should we only forward mouse warps to the app when we have keyboard focus?" );
gamescope::ConVar<bool> cv_wayland_mouse_relmotion_without_keyboard_focus( "wayland_mouse_relmotion_without_keyboard_focus", false, "Should we only forward mouse relative motion to the app when we have keyboard focus?" );
gamescope::ConVar<bool> cv_wayland_use_modifiers( "wayland_use_modifiers", true, "Use DMA-BUF modifiers?" );

class CWaylandConnector;
class CWaylandPlane;
Expand Down Expand Up @@ -532,6 +533,8 @@ namespace gamescope
void SetFullscreen( bool bFullscreen ); // Thread safe, can be called from the input thread.
void UpdateFullscreenState();

bool SupportsFormat( uint32_t uDRMFormat ) const;

void SetHostCompositorIsCurrentlyVRR( bool bActive ) { m_bHostCompositorIsCurrentlyVRR = bActive; }

bool CurrentDisplaySupportsVRR() const { return m_bHostCompositorIsCurrentlyVRR; }
Expand Down Expand Up @@ -598,6 +601,7 @@ namespace gamescope
zwp_relative_pointer_v1 *m_pRelativePointer = nullptr;

std::unordered_map<uint32_t, std::vector<uint64_t>> m_FormatModifiers;
std::unordered_set<uint32_t> m_ModifierlessFormats;
std::unordered_map<uint32_t, wl_buffer *> m_ImportedFbs;

uint32_t m_uPointerEnterSerial = 0;
Expand Down Expand Up @@ -1270,15 +1274,15 @@ namespace gamescope
void CWaylandBackend::GetPreferredOutputFormat( VkFormat *pPrimaryPlaneFormat, VkFormat *pOverlayPlaneFormat ) const
{
VkFormat u8BitFormat = VK_FORMAT_UNDEFINED;
if ( m_FormatModifiers.contains( DRM_FORMAT_ARGB8888 ) )
if ( SupportsFormat( DRM_FORMAT_ARGB8888 ) )
u8BitFormat = VK_FORMAT_B8G8R8A8_UNORM;
else if ( m_FormatModifiers.contains( DRM_FORMAT_ABGR8888 ) )
else if ( SupportsFormat( DRM_FORMAT_ABGR8888 ) )
u8BitFormat = VK_FORMAT_R8G8B8A8_UNORM;

VkFormat u10BitFormat = VK_FORMAT_UNDEFINED;
if ( m_FormatModifiers.contains( DRM_FORMAT_ABGR2101010 ) )
if ( SupportsFormat( DRM_FORMAT_ABGR2101010 ) )
u10BitFormat = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
else if ( m_FormatModifiers.contains( DRM_FORMAT_ARGB2101010 ) )
else if ( SupportsFormat( DRM_FORMAT_ARGB2101010 ) )
u10BitFormat = VK_FORMAT_A2R10G10B10_UNORM_PACK32;

assert( u8BitFormat != VK_FORMAT_UNDEFINED );
Expand Down Expand Up @@ -1478,10 +1482,16 @@ namespace gamescope

bool CWaylandBackend::UsesModifiers() const
{
return true;
if ( !cv_wayland_use_modifiers )
return false;

return !m_FormatModifiers.empty();
}
std::span<const uint64_t> CWaylandBackend::GetSupportedModifiers( uint32_t uDrmFormat ) const
{
if ( !UsesModifiers() )
return std::span<const uint64_t>{};

auto iter = m_FormatModifiers.find( uDrmFormat );
if ( iter == m_FormatModifiers.end() )
return std::span<const uint64_t>{};
Expand Down Expand Up @@ -1744,6 +1754,13 @@ namespace gamescope
}
}

bool CWaylandBackend::SupportsFormat( uint32_t uDRMFormat ) const
{
return UsesModifiers()
? m_FormatModifiers.contains( uDRMFormat )
: m_ModifierlessFormats.contains( uDRMFormat );
}

/////////////////////
// Wayland Callbacks
/////////////////////
Expand Down Expand Up @@ -1831,6 +1848,8 @@ namespace gamescope
//xdg_log.infof( "Modifier: %s (0x%" PRIX32 ") %lx", drmGetFormatName( uFormat ), uFormat, ulModifier );
if ( ulModifier != DRM_FORMAT_MOD_INVALID )
m_FormatModifiers[uFormat].emplace_back( ulModifier );
else
m_ModifierlessFormats.emplace( uFormat );
}

// Output
Expand Down

0 comments on commit 4ca3986

Please sign in to comment.