Skip to content

Commit

Permalink
wip wayland backend
Browse files Browse the repository at this point in the history
  • Loading branch information
misyltoad committed Mar 2, 2024
1 parent 14a1db3 commit 81ef1ac
Show file tree
Hide file tree
Showing 9 changed files with 1,245 additions and 11 deletions.
3 changes: 3 additions & 0 deletions protocol/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ wl_protocol_dir = wayland_protos.get_variable('pkgdatadir')

protocols = [
# Upstream protocols
wl_protocol_dir / 'stable/linux-dmabuf/linux-dmabuf-v1.xml',
wl_protocol_dir / 'stable/viewporter/viewporter.xml',
wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
wl_protocol_dir / 'stable/presentation-time/presentation-time.xml',
wl_protocol_dir / 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml',

# Gamescope protocols
'gamescope-xwayland.xml',
Expand Down
2 changes: 2 additions & 0 deletions src/backends.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ namespace gamescope
SDL,
OpenVR,
Headless,
Wayland,
};

// Backend forward declarations.
class CSDLBackend;
class CDRMBackend;
class COpenVRBackend;
class CHeadlessBackend;
class CWaylandBackend;
}
7 changes: 6 additions & 1 deletion src/drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,11 @@ namespace gamescope
if ( !SupportsColorManagement() )
bNeedsFullComposite |= ( pFrameInfo->layerCount > 1 || pFrameInfo->layers[0].colorspace != GAMESCOPE_APP_TEXTURE_COLORSPACE_HDR10_PQ );
}
else
{
if ( !SupportsColorManagement() )
bNeedsFullComposite |= ColorspaceIsHDR( pFrameInfo->layers[0].colorspace );
}

bNeedsFullComposite |= !!(g_uCompositeDebug & CompositeDebugFlag::Heatmap);

Expand Down Expand Up @@ -3238,7 +3243,7 @@ namespace gamescope

baseLayer->filter = GamescopeUpscaleFilter::NEAREST;
baseLayer->ctm = nullptr;
baseLayer->colorspace = g_bOutputHDREnabled ? GAMESCOPE_APP_TEXTURE_COLORSPACE_HDR10_PQ : GAMESCOPE_APP_TEXTURE_COLORSPACE_SRGB;
baseLayer->colorspace = pFrameInfo->outputEncodingEOTF == EOTF_PQ ? GAMESCOPE_APP_TEXTURE_COLORSPACE_HDR10_PQ : GAMESCOPE_APP_TEXTURE_COLORSPACE_SRGB;

m_bWasPartialCompsiting = false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ int main(int argc, char **argv)
}
}

#if 0
switch ( eCurrentBackend )
{
#if HAVE_DRM
Expand All @@ -799,6 +800,8 @@ int main(int argc, char **argv)
default:
abort();
}
#endif
gamescope::IBackend::Set<gamescope::CWaylandBackend>();

if ( !GetBackend() )
{
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ src = [
'mangoapp.cpp',
'reshade_effect_manager.cpp',
'backend.cpp',
'wayland_backend.cpp',
]

gamescope_cpp_args = []
Expand Down
25 changes: 18 additions & 7 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2853,23 +2853,25 @@ std::shared_ptr<CVulkanTexture> vulkan_get_hacky_blank_texture()
return g_output.temporaryHackyBlankImage;
}

std::shared_ptr<CVulkanTexture> vulkan_create_debug_blank_texture()
std::shared_ptr<CVulkanTexture> 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;
flags.bFlippable = true;
flags.bSampled = true;
flags.bTransferDst = true;

// To match Steam's scaling, which is capped at 1080p
int width = std::min<int>( g_nOutputWidth, 1920 );
int height = std::min<int>( g_nOutputHeight, 1080 );

auto texture = std::make_shared<CVulkanTexture>();
bool bRes = texture->BInit( width, height, 1u, VulkanFormatToDRM( VK_FORMAT_B8G8R8A8_UNORM ), flags );
assert( bRes );

void* dst = g_device.uploadBufferData( width * height * 4 );
memset( dst, 0x0, width * height * 4 );
uint8_t* dst = (uint8_t *)g_device.uploadBufferData( width * height * 4 );
for ( uint32_t i = 0; i < width * height; i += 4 )
{
dst[i + 0] = b;
dst[i + 1] = g;
dst[i + 2] = r;
dst[i + 3] = a;
}

auto cmdBuffer = g_device.commandBuffer();
cmdBuffer->copyBufferToImage(g_device.uploadBuffer(), 0, 0, texture);
Expand All @@ -2879,6 +2881,15 @@ std::shared_ptr<CVulkanTexture> vulkan_create_debug_blank_texture()
return texture;
}

std::shared_ptr<CVulkanTexture> vulkan_create_debug_blank_texture()
{
// To match Steam's scaling, which is capped at 1080p
int width = std::min<int>( g_nOutputWidth, 1920 );
int height = std::min<int>( g_nOutputHeight, 1080 );

return vulkan_create_flat_texture( width, height, 0, 0, 0, 0 );
}

bool vulkan_supports_hdr10()
{
for ( auto& format : g_output.surfaceFormats )
Expand Down
12 changes: 12 additions & 0 deletions src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ inline bool close_enough(float a, float b, float epsilon = 0.001f)
return fabsf(a - b) <= epsilon;
}

bool DRMFormatHasAlpha( uint32_t nDRMFormat );

struct FrameInfo_t
{
bool useFSRLayer0;
Expand Down Expand Up @@ -301,6 +303,14 @@ struct FrameInfo_t
return tex->isYcbcr();
}

bool hasAlpha() const
{
if ( !tex )
return false;

return DRMFormatHasAlpha( tex->drmFormat() );
}

bool isScreenSize() const {
return close_enough(scale.x, 1.0f) &&
close_enough(scale.y, 1.0f) &&
Expand Down Expand Up @@ -910,6 +920,8 @@ VkFormat DRMFormatToVulkan( uint32_t nDRMFormat, bool bSrgb );
bool DRMFormatHasAlpha( uint32_t nDRMFormat );
uint32_t DRMFormatGetBPP( uint32_t nDRMFormat );

std::shared_ptr<CVulkanTexture> vulkan_create_flat_texture( uint32_t width, uint32_t height, uint8_t r, uint8_t g, uint8_t b, uint8_t a );

bool vulkan_supports_hdr10();

void vulkan_wait_idle();
Expand Down
7 changes: 4 additions & 3 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,10 @@ paint_all(bool async)
if ( overlay == global_focus.inputFocusWindow )
update_touch_scaling( &frameInfo );
}
else
else if ( !GetBackend()->UsesVulkanSwapchain() && GetBackend()->IsSessionBased() )
{
auto tex = vulkan_get_hacky_blank_texture();
if ( !GetBackend()->UsesVulkanSwapchain() && tex != nullptr )
if ( tex != nullptr )
{
// HACK! HACK HACK HACK
// To avoid stutter when toggling the overlay on
Expand Down Expand Up @@ -7573,7 +7573,8 @@ steamcompmgr_main(int argc, char **argv)
update_mode_atoms(root_ctx);
XFlush(root_ctx->dpy);

GetBackend()->PostInit();
if ( !GetBackend()->PostInit() )
return;

update_edid_prop();

Expand Down
Loading

0 comments on commit 81ef1ac

Please sign in to comment.