Gamescope swapchain

gamescope-specific swapchain protocol

This is a private Gamescope protocol. Regular Wayland clients must not use it.


create_swapchain(surface: object<wl_surface>, callback: new_id<gamescope_swapchain>)
Argument
Type
Description
surfaceobject<wl_surface>
target surface
callbacknew_id<gamescope_swapchain>
new swapchain object
create Gamescope swapchain interface

This constructor only enables the original past_present_timing, refresh_cycle and retired events, regardless of the bound version. Clients must use create_swapchain_with_timing to opt into newer events.

create_swapchain_with_timing(surface: object<wl_surface>, callback: new_id<gamescope_swapchain>)
Argument
Type
Description
surfaceobject<wl_surface>
target surface
callbacknew_id<gamescope_swapchain>
new swapchain object
create a swapchain with presentation timing events

Creates a swapchain that also receives present_timing and timing_properties. Binding version 2 alone does not enable these events, since older clients may bind the advertised version without understanding them. The initial properties arrive once the compositor knows the surface's timing.



destroy()
override_window_content(gamescope_xwayland_server_id: uint, x11_window: uint)
Argument
Type
Description
gamescope_xwayland_server_iduint
gamescope xwayland server ID
x11_windowuint
X11 window ID
override an X11's window wl_surface

Xwayland creates a wl_surface for each X11 window. It sends a WL_SURFACE_ID client message to indicate the mapping between the X11 windows and the wl_surface objects.

This request overrides this mapping for a given X11 window, allowing an X11 client to submit buffers via the Wayland protocol. The override only affects buffer submission. Everything else (e.g. input events) still uses Xwayland's WL_SURFACE_ID.

x11_server is gotten by the GAMESCOPE_XWAYLAND_SERVER_ID property on the root window of the associated server.

swapchain_feedback(image_count: uint, vk_format: uint, vk_colorspace: uint, vk_composite_alpha: uint, vk_pre_transform: uint, vk_clipped: uint, vk_engine_name: string)
Argument
Type
Description
image_countuint
image count of swapchain
vk_formatuint
VkFormat of swapchain
vk_colorspaceuint
VkColorSpaceKHR of swapchain
vk_composite_alphauint
VkCompositeAlphaFlagBitsKHR of swapchain
vk_pre_transformuint
VkSurfaceTransformFlagBitsKHR of swapchain
vk_clippeduint
clipped (VkBool32) of swapchain
vk_engine_namestring
Engine name
provide swapchain feedback

Provide swapchain feedback to the compositor.

This is what the useless tearing protocol should have been. Absolutely not enough information in the final protocol to do what we want for SteamOS -- which is have the Allow Tearing toggle apply to *both* Mailbox + Immediate and NOT fifo, essentially acting as an override for tearing on/off for games. The upstream protocol is very useless for our usecase here.

Provides image count ahead of time instead of needing to try and calculate it from an initial stall if we are doing low latency.

Provides colorspace info for us to do HDR for both HDR10 PQ and scRGB. The upstream HDR efforts seem to have no interest in supporting scRGB but we *need* that so /shrug We can do it here now! Yipee!

Swapchain feedback solves so many problems! :D

set_present_mode(vk_present_mode: uint)
Argument
Type
Description
vk_present_modeuint
VkPresentModeKHR
Add a fifo queue constraint
Argument
Type
Description
display_primary_red_xuint
red primary x coordinate
display_primary_red_yuint
red primary y coordinate
display_primary_green_xuint
green primary x coordinate
display_primary_green_yuint
green primary y coordinate
display_primary_blue_xuint
blue primary x coordinate
display_primary_blue_yuint
blue primary y coordinate
white_point_xuint
white point x coordinate
white_point_yuint
white point y coordinate
max_display_mastering_luminanceuint
max display mastering luminance
min_display_mastering_luminanceuint
min display mastering luminance
max_clluint
max content light level
max_falluint
max frame average light level
set HDR metadata for a surface

Forward HDR metadata from Vulkan to the compositor.

HDR Metadata Infoframe as per CTA 861.G spec. This is expected to match exactly with the spec.

display_primary_*: Color Primaries of the Data. Specifies X and Y coordinates. These are coded as unsigned 16-bit values in units of 0.00002, where 0x0000 represents zero and 0xC350 represents 1.0000.

white_point_*: White Point of Colorspace Data. Specifies X and Y coordinates. These are coded as unsigned 16-bit values in units of 0.00002, where 0x0000 represents zero and 0xC350 represents 1.0000.

max_display_mastering_luminance: Max Mastering Display Luminance. This value is coded as an unsigned 16-bit value in units of 1 cd/m2, where 0x0001 represents 1 cd/m2 and 0xFFFF represents 65535 cd/m2.

max_display_mastering_luminance: Min Mastering Display Luminance. This value is coded as an unsigned 16-bit value in units of 0.0001 cd/m2, where 0x0001 represents 0.0001 cd/m2 and 0xFFFF represents 6.5535 cd/m2.

max_cll: Max Content Light Level. This value is coded as an unsigned 16-bit value in units of 1 cd/m2, where 0x0001 represents 1 cd/m2 and 0xFFFF represents 65535 cd/m2.

max_fall: Max Frame Average Light Level. This value is coded as an unsigned 16-bit value in units of 1 cd/m2, where 0x0001 represents 1 cd/m2 and 0xFFFF represents 65535 cd/m2.

set_present_time(present_id: uint, desired_present_time_hi: uint, desired_present_time_lo: uint)
Argument
Type
Description
present_iduint
application provided presentation id
desired_present_time_hiuint
high part of the desired presentation time for this commit. Uses CLOCK_MONOTONIC. 0 = present as soon as possible.
desired_present_time_louint
low part of the desired presentation time for this commit. Uses CLOCK_MONOTONIC. 0 = present as soon as possible.
display timing of next commit

Sets the display timing of the next commit.

This gets reset to 0s in the compositor's state after a commit.

set_present_timing(serial_hi: uint, serial_lo: uint, target_hi: uint, target_lo: uint, flags: uint<gamescope_swapchain.present_timing_flags>)
Argument
Type
Description
serial_hiuint
high part of the client timing serial
serial_louint
low part of the client timing serial
target_hiuint
high part of target time or relative duration in nanoseconds
target_louint
low part of target time or relative duration in nanoseconds
flagsuint<gamescope_swapchain.present_timing_flags>
presentation timing flags
timing request for the next commit

Only swapchains created with create_swapchain_with_timing accept this request. Other swapchains ignore it, including zero-serial requests. Registers a client-local serial for one timing report. Target uses CLOCK_MONOTONIC nanoseconds, or a duration with the relative flag. Zero requests presentation as soon as possible, as does a relative target before this swapchain has latched a frame. Unknown flag bits are ignored. The request applies to the next commit that carries buffer content, including one that recommits the current buffer. Replacing an armed serial reports the old serial as dropped. A zero serial clears any armed request and is never reported.

Argument
Type
Description
present_iduint
application provided presentation id
desired_present_time_hiuint
high part of the desired presentation time for the commit. (from the app)
desired_present_time_louint
low part of the desired presentation time for the commit. (from the app)
actual_present_time_hiuint
high part of the actual present time for this commit.
actual_present_time_louint
low part of the actual present time for this commit.
earliest_present_time_hiuint
high part of the refresh time that Gamescope thought this commit was done by.
earliest_present_time_louint
low part of the refresh time that Gamescope thought this commit was done by.
present_margin_hiuint
high part of the difference between earliest present time and the earliest latch time
present_margin_louint
low part of the difference between earliest present time and the earliest latch time
information about past presentation

Gives information on the past presentation timing

refresh_cycle(refresh_cycle_hi: uint, refresh_cycle_lo: uint)
Argument
Type
Description
refresh_cycle_hiuint
high part of the refresh cycle in nanos
refresh_cycle_louint
low part of the refresh cycle in nanos
information about refresh cycle for this swapchain

Gives information on the refresh cycle for this swapchain

retired()
Swapchain was remotely retired
present_timing(serial_hi: uint, serial_lo: uint, queue_end_hi: uint, queue_end_lo: uint, dequeued_hi: uint, dequeued_lo: uint, pixel_out_hi: uint, pixel_out_lo: uint)
Argument
Type
Description
serial_hiuint
high part of the client timing serial
serial_louint
low part of the client timing serial
queue_end_hiuint
high part of queue completion time in nanoseconds
queue_end_louint
low part of queue completion time in nanoseconds
dequeued_hiuint
high part of latch time in nanoseconds
dequeued_louint
low part of latch time in nanoseconds
pixel_out_hiuint
high part of predicted scanout time in nanoseconds
pixel_out_louint
low part of predicted scanout time in nanoseconds
timing result for the registering swapchain

Only sent to swapchains created with create_swapchain_with_timing. Sent once per serial when presented or dropped, unless this object is destroyed first. All timestamps use CLOCK_MONOTONIC nanoseconds. Zero means unavailable, and a dropped commit has all timestamps zero. Pixel out is the compositor's predicted scanout.

Argument
Type
Description
refresh_duration_hiuint
high part of effective refresh duration in nanoseconds
refresh_duration_louint
low part of effective refresh duration in nanoseconds
refresh_interval_hiuint
high part of base refresh interval in nanoseconds
refresh_interval_louint
low part of base refresh interval in nanoseconds
effective and base refresh cycles

Only sent to swapchains created with create_swapchain_with_timing. Duration is the effective cycle including the frame limiter, the same value refresh_cycle carries. Interval is the panel cycle on fixed refresh, or UINT64_MAX for variable refresh. Sent once the compositor knows the window's timing and whenever the values change. Until then both values are unknown to the client.

present_timing_flags { relative, nearest_refresh_cycle } 
Argument
Value
Description
relative1
target is a duration after this swapchain's previous expected scanout
nearest_refresh_cycle2
allow presentation less than half an effective refresh cycle early

Compositor Support

gamescope_swapchain_factory_v2↓
Compositors
CageCage0.3.0
x
COSMICCOSMIC1.11.0
x
flakewm3.0.5
x
GameScopeGameScope3.17.0
2
HyprlandHyprland0.57.2
x
Jay1.14.0
x
KWinKWin6.7
x
LabwcLabwc0.20.2
x
LouvreLouvre2.14.1
x
MangoMango0.16.3
x
MirMir2.26
x
MuffinMuffin6.7.4
x
MutterMutter51
x
niriniri26.04
x
phocphoc0.55
x
Pila0.5.1
x
QtileQtile0.37.1
x
riverriver0.5.0
x
SwaySway1.11
x
TreelandTreeland0.8.0
x
WayfireWayfire0.9.0
x
WestonWeston15.0.1
x

Copyright © 2023 Joshua Ashton for Valve Software

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.