Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3049,23 +3049,36 @@ bool acquire_next_image( void )

static std::atomic<uint64_t> g_currentPresentWaitId = {0u};
static std::mutex present_wait_lock;
static std::jthread g_presentWaitThread;
static constexpr uint64_t k_uPresentWaitShutdownId = ~0ull;

extern void mangoapp_output_update( uint64_t vblanktime );
static void present_wait_thread_func( void )
static void present_wait_thread_func( std::stop_token stopToken )
{
pthread_setname_np( pthread_self(), "gamescope-prsnt" );
uint64_t present_wait_id = 0;

while (true)
std::stop_callback stopCallback( stopToken, []
{
g_currentPresentWaitId.wait(present_wait_id);
std::unique_lock lock( present_wait_lock );
g_currentPresentWaitId = k_uPresentWaitShutdownId;
g_currentPresentWaitId.notify_all();
} );

while ( !stopToken.stop_requested() )
{
g_currentPresentWaitId.wait( present_wait_id );

// Lock to make sure swapchain destruction is waited on and that
// it's for this swapchain.
{
std::unique_lock lock(present_wait_lock);
std::unique_lock lock( present_wait_lock );
present_wait_id = g_currentPresentWaitId.load();

if (present_wait_id != 0)
if ( stopToken.stop_requested() )
break;

if ( present_wait_id != 0 )
{
g_device.vk.WaitForPresentKHR( g_device.device(), g_output.swapChain, present_wait_id, 1'000'000'000lu );
uint64_t vblanktime = get_time_in_nanos();
Expand All @@ -3076,6 +3089,15 @@ static void present_wait_thread_func( void )
}
}

void vulkan_present_wait_shutdown( void )
{
if ( !g_presentWaitThread.joinable() )
return;

g_presentWaitThread.request_stop();
g_presentWaitThread.join();
}

void vulkan_update_swapchain_hdr_metadata( VulkanOutput_t *pOutput )
{
if (!g_output.swapchainHDRMetadata)
Expand Down Expand Up @@ -3734,8 +3756,7 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface )

if ( GetBackend()->UsesVulkanSwapchain() )
{
std::thread present_wait_thread( present_wait_thread_func );
present_wait_thread.detach();
g_presentWaitThread = std::jthread( present_wait_thread_func );
}

s_bInitted = true;
Expand Down
1 change: 1 addition & 0 deletions src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ gamescope::Rc<CVulkanTexture> vulkan_acquire_capture_texture(uint32_t width, uin
uint32_t vulkan_get_rgb10_capture_format( void );

void vulkan_present_to_window( void );
void vulkan_present_wait_shutdown( void );

void vulkan_garbage_collect( void );
bool vulkan_remake_swapchain( void );
Expand Down
2 changes: 2 additions & 0 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7821,6 +7821,8 @@ steamcompmgr_exit(void)

g_VirtualConnectorFocuses.clear();

vulkan_present_wait_shutdown();

gamescope::IBackend::Set( nullptr );

wlserver_lock();
Expand Down
Loading