Skip to content

Commit

Permalink
Add support for commit-queue-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Nov 26, 2023
1 parent a6e32c6 commit 4d7c175
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions protocol/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protocols = [
# Upstream protocols
wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
wl_protocol_dir / 'stable/presentation-time/presentation-time.xml',
wl_protocol_dir / 'staging/commit-queue/commit-queue-v1.xml',

# Gamescope protocols
'gamescope-xwayland.xml',
Expand Down
30 changes: 25 additions & 5 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ struct commit_t : public gamescope::IWaitable
uint64_t commitID = 0;
bool done = false;
bool async = false;
bool fifo = false;
std::optional<wlserver_vk_swapchain_feedback> feedback = std::nullopt;

uint64_t win_seq = 0;
Expand Down Expand Up @@ -794,7 +795,12 @@ struct commit_t : public gamescope::IWaitable
// When we get the new IWaitable stuff in there.
{
std::unique_lock< std::mutex > lock( pDoneCommits->listCommitsDoneLock );
pDoneCommits->listCommitsDone.push_back( CommitDoneEntry_t{ win_seq, commitID, desired_present_time } );
pDoneCommits->listCommitsDone.push_back( CommitDoneEntry_t{
.winSeq = win_seq,
.commitID = commitID,
.desiredPresentTime = desired_present_time,
.fifo = fifo,
} );
}

if ( m_bMangoNudge )
Expand Down Expand Up @@ -1367,7 +1373,7 @@ destroy_buffer( struct wl_listener *listener, void * )
}

static std::shared_ptr<commit_t>
import_commit ( steamcompmgr_win_t *w, struct wlr_surface *surf, struct wlr_buffer *buf, bool async, std::shared_ptr<wlserver_vk_swapchain_feedback> swapchain_feedback, std::vector<struct wl_resource*> presentation_feedbacks, std::optional<uint32_t> present_id, uint64_t desired_present_time )
import_commit ( steamcompmgr_win_t *w, struct wlr_surface *surf, struct wlr_buffer *buf, bool async, std::shared_ptr<wlserver_vk_swapchain_feedback> swapchain_feedback, std::vector<struct wl_resource*> presentation_feedbacks, std::optional<uint32_t> present_id, uint64_t desired_present_time, bool fifo )
{
std::shared_ptr<commit_t> commit = std::make_shared<commit_t>();
std::unique_lock<std::mutex> lock( wlr_buffer_map_lock );
Expand All @@ -1376,6 +1382,7 @@ import_commit ( steamcompmgr_win_t *w, struct wlr_surface *surf, struct wlr_buff
commit->surf = surf;
commit->buf = buf;
commit->async = async;
commit->fifo = fifo;
commit->presentation_feedbacks = std::move(presentation_feedbacks);
if (swapchain_feedback)
commit->feedback = *swapchain_feedback;
Expand Down Expand Up @@ -6366,7 +6373,7 @@ bool handle_done_commit( steamcompmgr_win_t *w, xwayland_ctx_t *ctx, uint64_t co
}

// TODO: Merge these two functions.
void handle_done_commits_xwayland( xwayland_ctx_t *ctx )
void handle_done_commits_xwayland( xwayland_ctx_t *ctx, bool vblank )
{
std::lock_guard<std::mutex> lock( ctx->doneCommits.listCommitsDoneLock );

Expand All @@ -6375,11 +6382,20 @@ void handle_done_commits_xwayland( xwayland_ctx_t *ctx )
// commits that were not ready to be presented based on their display timing.
std::vector< CommitDoneEntry_t > commits_before_their_time;

// windows in FIFO mode we got a new frame to present for this vblank
std::set< uint64_t > fifo_win_seqs;

uint64_t now = get_time_in_nanos();

// very fast loop yes
for ( auto& entry : ctx->doneCommits.listCommitsDone )
{
if (entry.fifo && (!vblank || fifo_win_seqs.count(entry.winSeq) > 0))
{
commits_before_their_time.push_back( entry );
continue;
}

if (!entry.earliestPresentTime)
{
entry.earliestPresentTime = next_refresh_time;
Expand All @@ -6397,7 +6413,11 @@ void handle_done_commits_xwayland( xwayland_ctx_t *ctx )
if (w->seq != entry.winSeq)
continue;
if (handle_done_commit(w, ctx, entry.commitID, entry.earliestPresentTime, entry.earliestLatchTime))
{
if (entry.fifo)
fifo_win_seqs.insert(entry.winSeq);
break;
}
}
}

Expand Down Expand Up @@ -6582,7 +6602,7 @@ void update_wayland_res(CommitDoneList_t *doneCommits, steamcompmgr_win_t *w, Re
return;
}

std::shared_ptr<commit_t> newCommit = import_commit( w, reslistentry.surf, buf, reslistentry.async, std::move(reslistentry.feedback), std::move(reslistentry.presentation_feedbacks), reslistentry.present_id, reslistentry.desired_present_time );
std::shared_ptr<commit_t> newCommit = import_commit( w, reslistentry.surf, buf, reslistentry.async, std::move(reslistentry.feedback), std::move(reslistentry.presentation_feedbacks), reslistentry.present_id, reslistentry.desired_present_time, reslistentry.fifo );

int fence = -1;
if ( newCommit )
Expand Down Expand Up @@ -7925,7 +7945,7 @@ steamcompmgr_main(int argc, char **argv)
gamescope_xwayland_server_t *server = NULL;
for (size_t i = 0; (server = wlserver_get_xwayland_server(i)); i++)
{
handle_done_commits_xwayland(server->ctx.get());
handle_done_commits_xwayland(server->ctx.get(), vblank);

// When we have observed both a complete commit and a VBlank, we should request a new frame.
if (vblank)
Expand Down
6 changes: 6 additions & 0 deletions src/wlserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern "C" {
#include <wlr/util/log.h>
#include <wlr/xwayland/server.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_commit_queue_v1.h>
#undef static
#undef class
}
Expand Down Expand Up @@ -104,10 +105,13 @@ void gamescope_xwayland_server_t::wayland_commit(struct wlr_surface *surf, struc

auto wl_surf = get_wl_surface_info( surf );

auto queue_mode = wlr_commit_queue_v1_get_surface_mode(surf);

ResListEntry_t newEntry = {
.surf = surf,
.buf = buf,
.async = wlserver_surface_is_async(surf),
.fifo = queue_mode == 1,
.feedback = wlserver_surface_swapchain_feedback(surf),
.presentation_feedbacks = std::move(wl_surf->pending_presentation_feedbacks),
.present_id = wl_surf->present_id,
Expand Down Expand Up @@ -1458,6 +1462,8 @@ bool wlserver_init( void ) {

create_presentation_time();

wlr_commit_queue_manager_v1_create(wlserver.display, 1);

wlserver.xdg_shell = wlr_xdg_shell_create(wlserver.display, 3);
if (!wlserver.xdg_shell)
{
Expand Down
1 change: 1 addition & 0 deletions src/wlserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct ResListEntry_t {
struct wlr_surface *surf;
struct wlr_buffer *buf;
bool async;
bool fifo;
std::shared_ptr<wlserver_vk_swapchain_feedback> feedback;
std::vector<struct wl_resource*> presentation_feedbacks;
std::optional<uint32_t> present_id;
Expand Down
1 change: 1 addition & 0 deletions src/xwayland_ctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct CommitDoneEntry_t
uint64_t desiredPresentTime;
uint64_t earliestPresentTime;
uint64_t earliestLatchTime;
bool fifo;
};

struct CommitDoneList_t
Expand Down

0 comments on commit 4d7c175

Please sign in to comment.