Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Tearing: async-capable buffers, give up where the driver never flips

oxydizera986eed78fa1
diff --git a/build/support.zig b/build/support.zig
index bfb4972..54fcd8d 100644
--- a/build/support.zig
+++ b/build/support.zig
@@ -79,12 +79,13 @@ pub fn addBassDsp(b: *std.Build, target: std.Build.ResolvedTarget) void {
pub const projection_sources = [_][]const u8{ "src/projection.c", "src/projection_props.c", "src/projection_resolve.c", "src/projection_present.c", "src/projection_pass.c", "src/projection_pick.c" };
/// scene_output.c and its parts (scene_output_internal.h).
-pub const scene_output_sources = [_][]const u8{ "src/scene_output.c", "src/scene_output_collect.c", "src/scene_output_effects.c", "src/scene_output_draw.c", "src/scene_output_ribbon.c", "src/scene_output_snapshot.c" };
+pub const scene_output_sources = [_][]const u8{ "src/scene_output.c", "src/scene_output_collect.c", "src/scene_output_effects.c", "src/scene_output_draw.c", "src/scene_output_ribbon.c", "src/scene_output_snapshot.c", "src/scene_output_async.c" };
pub fn addGlass(b: *std.Build, module: *std.Build.Module, damage_audit: bool) void {
module.linkSystemLibrary("wlroots-0.20", .{});
module.linkSystemLibrary("egl", .{});
module.linkSystemLibrary("glesv2", .{});
+ module.linkSystemLibrary("libdrm", .{}); // scene_output_async.c reads plane properties
module.addCSourceFiles(.{ .files = &projection_sources, .flags = if (damage_audit) &.{ "-std=c11", "-Wall", "-Wextra", "-DREDIWM_DAMAGE_AUDIT" } else &.{ "-std=c11", "-Wall", "-Wextra" } });
module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
module.addCSourceFiles(.{ .files = &.{ "src/node_surface.c", "src/node_subsurface_tree.c", "src/node_xdg_shell.c" }, .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
diff --git a/docs/plans/vrr-tearing.md b/docs/plans/vrr-tearing.md
index 6ae76ab..62dd081 100644
--- a/docs/plans/vrr-tearing.md
+++ b/docs/plans/vrr-tearing.md
@@ -283,3 +283,36 @@ with a HEAD worktree.
focused fullscreen window.
* Not verified on DRM yet: that needs P0's run on the VT (does i915 take the
composited buffer asynchronously, how often the cursor check fires).
+
+## P0 findings (2026-11-21, eDP-1 on i915, kernel 7.2)
+
+* A fullscreen `vkcube --present_mode 0 --gpu_number 0` (Mesa) is recognised
+ and sends the async hint, but every asynchronous flip was refused (90
+ refused, 0 taken). Cause: the primary plane's `IN_FORMATS_ASYNC` allows
+ XR24/AR24 only as LINEAR, X_TILED, Y_TILED and Y_TILED_GEN12_RC_CCS, while
+ GBM picked Y_TILED_GEN12_RC_CCS_CC from `IN_FORMATS` for our swapchain.
+ wlroots 0.20 does not read `IN_FORMATS_ASYNC`.
+* Fix (`scene_output_async.c`): while `tearing.wanted`, the output swapchain
+ is rebuilt from its own modifiers intersected with the plane's
+ `IN_FORMATS_ASYNC` (read with libdrm on wlroots' non-master fd), and
+ rebuilt with the defaults when no game wants to tear. The session log says
+ "tearing buffers use N of M modifiers (asynchronous flip test passed)".
+* Windowed vkcube on NVIDIA (PRIME) was never a game window: fullscreen it to
+ test. Whether NVIDIA's Vulkan WSI sends the async hint is still unknown.
+* Retest with the async swapchain (buffers now Y_TILED_GEN12_RC_CCS): still
+ every flip refused. Kernel debug (`drm.debug=0x14`) names the remaining
+ cause: `intel_atomic_check: [PLANE:cursor A] async flip not supported`.
+ i915 refuses an atomic async commit that contains any non-primary plane,
+ and wlroots 0.20.2 (`backend/drm/atomic.c`, `atomic_connector_add`) writes
+ the cursor plane's properties into every commit, visible or disabled
+ (`plane_disable` still sets FB_ID/CRTC_ID). A software cursor (KWin's
+ workaround) therefore does not help here. The `No prop can be changed
+ during async flip` lines for FB_ID, FB_DAMAGE_CLIPS and IN_FENCE_FD are
+ informational: the core allows those three on the primary plane.
+ Upstream: i915 issue 13834; a 2025 i915 patch would allow no-op planes.
+* Decision (2026-11-21): keep the async swapchain, and stop tearing on an
+ output whose driver refuses the first whole run of 30 flips without ever
+ taking one (`Backoff.gaveUp`): attempts stop for the session, the tearing
+ buffers are released and IPC reports `tearing_paused`. No driver list, so a
+ fixed kernel needs no change here. Revisit with a DRM run once the i915 fix
+ lands (or wlroots stops writing an unchanged cursor plane in async commits).
diff --git a/src/ipc/handlers_data.zig b/src/ipc/handlers_data.zig
index 3b765d2..12c3388 100644
--- a/src/ipc/handlers_data.zig
+++ b/src/ipc/handlers_data.zig
@@ -198,7 +198,7 @@ pub fn makeOutputData(server: *Server, output: *Output) protocol.OutputData {
.is_focused = is_focused,
.tearing_allowed = output_tearing.wanted(output),
.tearing_active = output.tearing.active,
- .tearing_paused = output.tearing.backoff.paused_until_ns != 0 and output.tearing.backoff.paused(stats.nowNs()),
+ .tearing_paused = output_tearing.paused(output),
.direct_scanout = if (server.scene_outputs.get(output.wlr_output)) |scene_output| scene_output.directScanout() else false,
};
}
diff --git a/src/output/frame.zig b/src/output/frame.zig
index 82bf516..b247ec4 100644
--- a/src/output/frame.zig
+++ b/src/output/frame.zig
@@ -311,6 +311,7 @@ pub fn runFrame(output: *Output) void {
var committed = true;
if (should_commit) {
if (output.server.capture_mgr) |cm| cm.guardScreencopy(output.wlr_output);
+ scene_output.setTearingBuffers(tearing.buffersWanted(output));
const built_ok = output.server.buildOutputState(scene_output, &state);
timing.markBuilt();
if (built_ok) {
diff --git a/src/output/tearing.zig b/src/output/tearing.zig
index 555c384..fd76da2 100644
--- a/src/output/tearing.zig
+++ b/src/output/tearing.zig
@@ -34,11 +34,24 @@ pub fn wanted(output: *Output) bool {
/// Whether this output tries asynchronous flips now: wanted, and not paused
/// after a run of refusals.
pub fn allowed(output: *Output) bool {
- if (!wanted(output)) return false;
const backoff = &output.tearing.backoff;
+ if (backoff.gaveUp() or !wanted(output)) return false;
return backoff.paused_until_ns == 0 or !backoff.paused(stats.nowNs());
}
+/// Whether the output should draw into buffers it can flip asynchronously
+/// (`scene_output_async.c`): a game wants to tear and the driver has not
+/// shown that it cannot.
+pub fn buffersWanted(output: *Output) bool {
+ return !output.tearing.backoff.gaveUp() and wanted(output);
+}
+
+/// Whether tearing is paused now, or given up for the session.
+pub fn paused(output: *Output) bool {
+ const backoff = &output.tearing.backoff;
+ return backoff.gaveUp() or (backoff.paused_until_ns != 0 and backoff.paused(stats.nowNs()));
+}
+
/// Whether this frame may flip asynchronously at all. Atomic async flips may
/// change only the primary plane's buffer, so a frame that also changes the
/// mode, colour, image description or hardware cursor would be refused:
@@ -54,6 +67,12 @@ pub fn frameCanTear(output: *Output, state: *const wlr.Output.State) bool {
pub fn refused(output: *Output) void {
stats.global_stats.tearing_refused_flips +%= 1;
const pause = output.tearing.backoff.failed(stats.nowNs()) orelse return;
+ if (output.tearing.backoff.gaveUp()) {
+ log.info("output '{s}': {d} asynchronous page flips refused and none ever taken; tearing disabled on this output until restart", .{
+ output.wlr_output.name, tearing_policy.tuning.failures_before_pause,
+ });
+ return;
+ }
// Once per run: later pauses of the same run are only debug noise.
if (pause == tearing_policy.tuning.first_pause_ns) {
log.info("output '{s}': {d} asynchronous page flips refused in a row; tearing paused, retrying with backoff", .{
diff --git a/src/output/tearing_policy.zig b/src/output/tearing_policy.zig
index 852ea6a..d068654 100644
--- a/src/output/tearing_policy.zig
+++ b/src/output/tearing_policy.zig
@@ -10,6 +10,11 @@
//! stop for a while, since each one costs an extra test commit, and resume
//! by themselves with a growing pause. No timer: the next client commit after
//! the pause tries again.
+//!
+//! A driver that refuses the first whole run without ever taking one flip
+//! cannot tear here at all (i915 refuses any atomic async commit that carries
+//! the cursor plane, which wlroots 0.20 always writes): attempts stop for the
+//! session (`gaveUp`). A fixed kernel takes the first run and never gives up.
const std = @import("std");
@@ -27,6 +32,10 @@ pub const Backoff = struct {
/// Zero when not paused.
paused_until_ns: u64 = 0,
next_pause_ns: u64 = tuning.first_pause_ns,
+ /// An asynchronous flip went through at least once this session.
+ ever_succeeded: bool = false,
+ /// A run of refusals paused attempts at least once.
+ ever_paused: bool = false,
/// Whether attempts are paused at `now`. Ending a pause clears it, so
/// callers can skip the clock read while `paused_until_ns` is zero.
@@ -39,6 +48,7 @@ pub const Backoff = struct {
/// An asynchronous flip went through: start over.
pub fn succeeded(self: *Backoff) void {
+ self.ever_succeeded = true;
self.failures = 0;
self.next_pause_ns = tuning.first_pause_ns;
}
@@ -49,11 +59,17 @@ pub const Backoff = struct {
self.failures += 1;
if (self.failures < tuning.failures_before_pause) return null;
self.failures = 0;
+ self.ever_paused = true;
const pause = self.next_pause_ns;
self.paused_until_ns = now_ns + pause;
self.next_pause_ns = @min(pause * 2, tuning.max_pause_ns);
return pause;
}
+
+ /// The driver refused a whole run before taking any flip: it cannot tear.
+ pub fn gaveUp(self: *const Backoff) bool {
+ return self.ever_paused and !self.ever_succeeded;
+ }
};
test "isolated refusals never pause" {
@@ -65,8 +81,23 @@ test "isolated refusals never pause" {
}
}
+test "a driver that never takes a flip gives up after the first run" {
+ var b: Backoff = .{};
+ for (0..tuning.failures_before_pause - 1) |_| _ = b.failed(0);
+ try std.testing.expect(!b.gaveUp());
+ _ = b.failed(0);
+ try std.testing.expect(b.gaveUp());
+
+ // One success before the first pause: later runs only back off.
+ var ok: Backoff = .{};
+ ok.succeeded();
+ for (0..tuning.failures_before_pause * 3) |_| _ = ok.failed(0);
+ try std.testing.expect(!ok.gaveUp());
+}
+
test "a run of refusals pauses, resumes and backs off" {
var b: Backoff = .{};
+ b.succeeded();
var now: u64 = 1000;
for (0..tuning.failures_before_pause - 1) |_| try std.testing.expectEqual(null, b.failed(now));
try std.testing.expectEqual(@as(?u64, tuning.first_pause_ns), b.failed(now));
diff --git a/src/scene_output.c b/src/scene_output.c
index 3f7568a..09cf31c 100644
--- a/src/scene_output.c
+++ b/src/scene_output.c
@@ -310,7 +310,7 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
bool ok = scanout;
struct wlr_buffer *buffer = NULL;
if (scanout) goto done;
- if (!wlr_output_configure_primary_swapchain(output, state, &output->swapchain)) goto done;
+ if (!scene_output_configure_swapchain(out, state)) goto done;
buffer = wlr_swapchain_acquire(output->swapchain);
if (!buffer) goto done;
struct wlr_render_pass *pass = rediwm_scene_pass_begin(r->pass, buffer,
diff --git a/src/scene_output_async.c b/src/scene_output_async.c
new file mode 100644
index 0000000..f69a6a1
--- /dev/null
+++ b/src/scene_output_async.c
@@ -0,0 +1,194 @@
+// The output swapchain while a game tears. An atomic asynchronous flip is
+// refused unless the buffer's modifier is in the primary plane's
+// IN_FORMATS_ASYNC, which can be narrower than IN_FORMATS (Intel Gen12 takes
+// RC_CCS but not RC_CCS_CC or MC_CCS asynchronously). wlroots picks the
+// swapchain modifiers from IN_FORMATS alone, and the allocator then takes the
+// best one, so every flip of a tearing game was refused. While
+// `tearing_buffers` is set the swapchain is rebuilt from the modifiers it
+// already allows that the plane also flips asynchronously, and rebuilt with
+// the defaults once it is cleared.
+#include "scene_output_internal.h"
+#include <unistd.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <wlr/backend/drm.h>
+#include <wlr/render/drm_format_set.h>
+
+static uint64_t plane_property(int fd, uint32_t plane_id, const char *name, bool *found) {
+ *found = false;
+ uint64_t value = 0;
+ drmModeObjectProperties *props = drmModeObjectGetProperties(fd, plane_id, DRM_MODE_OBJECT_PLANE);
+ if (!props) return 0;
+ for (uint32_t i = 0; i < props->count_props && !*found; i++) {
+ drmModePropertyRes *prop = drmModeGetProperty(fd, props->props[i]);
+ if (!prop) continue;
+ if (strcmp(prop->name, name) == 0) {
+ value = props->prop_values[i];
+ *found = true;
+ }
+ drmModeFreeProperty(prop);
+ }
+ drmModeFreeObjectProperties(props);
+ return value;
+}
+
+static bool add_blob_formats(int fd, uint32_t blob_id, struct wlr_drm_format_set *set) {
+ drmModePropertyBlobRes *blob = drmModeGetPropertyBlob(fd, blob_id);
+ if (!blob) return false;
+ bool ok = false;
+ const struct drm_format_modifier_blob *head = blob->data;
+ const size_t length = blob->length;
+ if (length < sizeof(*head) || head->version != FORMAT_BLOB_CURRENT) goto out;
+ if (head->formats_offset > length || head->count_formats > (length - head->formats_offset) / sizeof(uint32_t)) goto out;
+ if (head->modifiers_offset > length ||
+ head->count_modifiers > (length - head->modifiers_offset) / sizeof(struct drm_format_modifier)) goto out;
+ const uint32_t *formats = (const uint32_t *)((const char *)head + head->formats_offset);
+ const struct drm_format_modifier *mods =
+ (const struct drm_format_modifier *)((const char *)head + head->modifiers_offset);
+ for (uint32_t i = 0; i < head->count_modifiers; i++) {
+ for (uint32_t bit = 0; bit < 64; bit++) {
+ if (!(mods[i].formats & (UINT64_C(1) << bit))) continue;
+ const uint64_t index = (uint64_t)mods[i].offset + bit;
+ if (index >= head->count_formats) break;
+ if (wlr_drm_format_set_add(set, formats[index], mods[i].modifier)) ok = true;
+ }
+ }
+out:
+ drmModeFreePropertyBlob(blob);
+ return ok;
+}
+
+// IN_FORMATS_ASYNC of the primary plane that can drive the output's CRTC.
+// False on a backend other than DRM, a kernel without the property, or
+// anything the queries refuse.
+static bool read_async_formats(struct wlr_output *output, struct wlr_drm_format_set *set) {
+ if (!wlr_output_is_drm(output)) return false;
+ const int fd = wlr_drm_backend_get_non_master_fd(output->backend);
+ if (fd < 0) return false;
+ bool ok = false;
+ drmModeRes *res = NULL;
+ drmModeConnector *conn = NULL;
+ drmModeEncoder *enc = NULL;
+ drmModePlaneRes *planes = NULL;
+ if (drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1) != 0) goto out;
+ res = drmModeGetResources(fd);
+ conn = drmModeGetConnectorCurrent(fd, wlr_drm_connector_get_id(output));
+ if (!res || !conn || conn->encoder_id == 0) goto out;
+ enc = drmModeGetEncoder(fd, conn->encoder_id);
+ if (!enc || enc->crtc_id == 0) goto out;
+ int crtc_index = -1;
+ for (int i = 0; i < res->count_crtcs && i < 32; i++)
+ if (res->crtcs[i] == enc->crtc_id) crtc_index = i;
+ if (crtc_index < 0) goto out;
+ planes = drmModeGetPlaneResources(fd);
+ if (!planes) goto out;
+ for (uint32_t i = 0; i < planes->count_planes; i++) {
+ drmModePlane *plane = drmModeGetPlane(fd, planes->planes[i]);
+ if (!plane) continue;
+ const bool drives = (plane->possible_crtcs & (1u << crtc_index)) != 0;
+ const uint32_t id = plane->plane_id;
+ drmModeFreePlane(plane);
+ if (!drives) continue;
+ bool found;
+ if (plane_property(fd, id, "type", &found) != DRM_PLANE_TYPE_PRIMARY || !found) continue;
+ const uint64_t blob = plane_property(fd, id, "IN_FORMATS_ASYNC", &found);
+ ok = found && blob != 0 && add_blob_formats(fd, (uint32_t)blob, set);
+ break;
+ }
+out:
+ if (planes) drmModeFreePlaneResources(planes);
+ if (enc) drmModeFreeEncoder(enc);
+ if (conn) drmModeFreeConnector(conn);
+ if (res) drmModeFreeResources(res);
+ close(fd);
+ return ok;
+}
+
+static bool format_has(const struct wlr_drm_format *format, uint64_t modifier) {
+ for (size_t i = 0; i < format->len; i++)
+ if (format->modifiers[i] == modifier) return true;
+ return false;
+}
+
+static bool test_swapchain(struct wlr_output *output, struct wlr_swapchain *swapchain,
+ const struct wlr_output_state *state, bool tearing) {
+ struct wlr_buffer *buffer = wlr_swapchain_acquire(swapchain);
+ if (!buffer) return false;
+ struct wlr_output_state copy = *state;
+ copy.committed |= WLR_OUTPUT_STATE_BUFFER;
+ copy.buffer = buffer;
+ copy.tearing_page_flip = tearing;
+ const bool ok = wlr_output_test_state(output, &copy);
+ wlr_buffer_unlock(buffer);
+ return ok;
+}
+
+enum async_result { ASYNC_FAILED, ASYNC_ALREADY, ASYNC_REPLACED };
+
+// Replaces output->swapchain (which wlroots just configured) with one limited
+// to the modifiers the plane flips asynchronously.
+static enum async_result use_async_swapchain(struct wlr_output *output, const struct wlr_output_state *state) {
+ struct wlr_swapchain *current = output->swapchain;
+ const uint32_t fourcc = current->format.format;
+ struct wlr_drm_format_set async = {0};
+ if (!read_async_formats(output, &async)) {
+ wlr_drm_format_set_finish(&async);
+ wlr_log(WLR_INFO, "Output '%s': no asynchronous flip formats to read; tearing buffers unchanged", output->name);
+ return ASYNC_FAILED;
+ }
+ const struct wlr_drm_format *allowed = wlr_drm_format_set_get(&async, fourcc);
+ struct wlr_drm_format_set picked = {0};
+ size_t kept = 0;
+ for (size_t i = 0; allowed && i < current->format.len; i++) {
+ if (!format_has(allowed, current->format.modifiers[i])) continue;
+ if (wlr_drm_format_set_add(&picked, fourcc, current->format.modifiers[i])) kept++;
+ }
+ wlr_drm_format_set_finish(&async);
+ enum async_result result = ASYNC_FAILED;
+ const struct wlr_drm_format *format = wlr_drm_format_set_get(&picked, fourcc);
+ if (!format) {
+ wlr_log(WLR_INFO, "Output '%s': none of the swapchain's %zu modifiers flips asynchronously",
+ output->name, current->format.len);
+ } else if (kept == current->format.len) {
+ result = ASYNC_ALREADY;
+ } else {
+ struct wlr_swapchain *swapchain = wlr_swapchain_create(output->allocator, current->width, current->height, format);
+ if (swapchain && test_swapchain(output, swapchain, state, false)) {
+ wlr_log(WLR_INFO, "Output '%s': tearing buffers use %zu of %zu modifiers (asynchronous flip test %s)",
+ output->name, kept, current->format.len,
+ test_swapchain(output, swapchain, state, true) ? "passed" : "refused");
+ wlr_swapchain_destroy(current);
+ output->swapchain = swapchain;
+ result = ASYNC_REPLACED;
+ } else {
+ wlr_log(WLR_INFO, "Output '%s': could not use a swapchain for asynchronous flips", output->name);
+ if (swapchain) wlr_swapchain_destroy(swapchain);
+ }
+ }
+ wlr_drm_format_set_finish(&picked);
+ return result;
+}
+
+bool scene_output_configure_swapchain(struct rediwm_scene_output *out, const struct wlr_output_state *state) {
+ struct wlr_output *output = out->output;
+ const bool want = out->tearing_buffers && !out->async_unavailable;
+ if (out->async_swapchain && !want) {
+ // wlroots keeps any swapchain of the right size and format: drop it so
+ // the default modifiers (and their compression) come back.
+ wlr_swapchain_destroy(output->swapchain);
+ output->swapchain = NULL;
+ out->async_swapchain = false;
+ wlr_log(WLR_DEBUG, "Output '%s': tearing buffers released", output->name);
+ }
+ struct wlr_swapchain *before = output->swapchain;
+ if (!wlr_output_configure_primary_swapchain(output, state, &output->swapchain)) return false;
+ if (output->swapchain != before) out->async_swapchain = false;
+ if (want && !out->async_swapchain) {
+ switch (use_async_swapchain(output, state)) {
+ case ASYNC_REPLACED:
+ case ASYNC_ALREADY: out->async_swapchain = true; break;
+ case ASYNC_FAILED: out->async_unavailable = true; break;
+ }
+ }
+ return true;
+}
diff --git a/src/scene_output_internal.h b/src/scene_output_internal.h
index e77d883..59bd49d 100644
--- a/src/scene_output_internal.h
+++ b/src/scene_output_internal.h
@@ -131,6 +131,9 @@ bool scene_output_collect(const struct rediwm_item *item, struct rediwm_node *tr
void scene_output_clear_entries(struct rediwm_output_renderer *r);
bool scene_output_decide_effects(struct rediwm_output_renderer *r, struct output_state *os,
struct rediwm_scene_output *out, const struct output_view *v, pixman_region32_t *changed);
+// The primary swapchain, limited to asynchronous-flip modifiers while a game
+// tears (scene_output_async.c).
+bool scene_output_configure_swapchain(struct rediwm_scene_output *out, const struct wlr_output_state *state);
bool scene_output_render_entry(struct rediwm_output_renderer *r, struct entry *e, struct rediwm_scene_output *out,
struct wlr_render_pass *pass, const struct output_view *v, pixman_region32_t *damage, bool backdrop);
diff --git a/src/scene_outputs.c b/src/scene_outputs.c
index b65d5b8..d6709c8 100644
--- a/src/scene_outputs.c
+++ b/src/scene_outputs.c
@@ -87,6 +87,16 @@ bool rediwm_scene_output_direct_scanout(const struct rediwm_scene_output *out) {
return out->prev_scanout;
}
+void rediwm_scene_output_set_tearing_buffers(struct rediwm_scene_output *out, bool wanted) {
+ if (out->tearing_buffers == wanted) return;
+ out->tearing_buffers = wanted;
+ if (!wanted) out->async_unavailable = false;
+}
+
+bool rediwm_scene_output_async_swapchain(const struct rediwm_scene_output *out) {
+ return out->async_swapchain;
+}
+
static void output_commit(struct wl_listener *listener, void *data) {
struct rediwm_scene_output *out = wl_container_of(listener, out, output_commit);
struct wlr_output_event_commit *event = data;
diff --git a/src/scene_outputs.h b/src/scene_outputs.h
index 693a42a..5bdbb3c 100644
--- a/src/scene_outputs.h
+++ b/src/scene_outputs.h
@@ -37,6 +37,11 @@ struct rediwm_scene_output {
// What was damaged and not yet committed with a buffer.
pixman_region32_t pending_commit_damage;
bool prev_scanout;
+ // Tearing (scene_output_async.c): a game wants asynchronous flips, so the
+ // swapchain should use only modifiers the primary plane flips asynchronously.
+ bool tearing_buffers;
+ bool async_swapchain; // output->swapchain is that restricted swapchain
+ bool async_unavailable; // tried while wanted and failed; retried once unwanted
// Explicit sync: the pass signals `in` when it has drawn, the scanout signals `out`.
struct wlr_drm_syncobj_timeline *in_timeline, *out_timeline;
uint64_t in_point, out_point;
@@ -90,6 +95,11 @@ bool rediwm_scene_output_needs_frame(const struct rediwm_scene_output *);
bool rediwm_scene_output_has_pending_damage(const struct rediwm_scene_output *);
// Whether the last built frame scanned a client buffer out directly.
bool rediwm_scene_output_direct_scanout(const struct rediwm_scene_output *);
+// Whether the next frames should be drawn into buffers the display can flip
+// asynchronously (a game on this output asks to tear).
+void rediwm_scene_output_set_tearing_buffers(struct rediwm_scene_output *, bool);
+// Whether the current swapchain was made for asynchronous flips.
+bool rediwm_scene_output_async_swapchain(const struct rediwm_scene_output *);
// Frame timing trace (-Dframe-trace, src/output/frame_trace.zig): when content last asked
// this output for a frame. A no-op in every other build.
diff --git a/src/scene_outputs.zig b/src/scene_outputs.zig
index 519aee2..e4e7aaa 100644
--- a/src/scene_outputs.zig
+++ b/src/scene_outputs.zig
@@ -12,6 +12,12 @@ pub const SceneOutput = opaque {
extern fn rediwm_scene_output_direct_scanout(output: *const SceneOutput) bool;
/// Whether the last built frame scanned a client buffer out directly.
pub const directScanout = rediwm_scene_output_direct_scanout;
+ extern fn rediwm_scene_output_set_tearing_buffers(output: *SceneOutput, wanted: bool) void;
+ /// Draw the next frames into buffers the display can flip asynchronously.
+ pub const setTearingBuffers = rediwm_scene_output_set_tearing_buffers;
+ extern fn rediwm_scene_output_async_swapchain(output: *const SceneOutput) bool;
+ /// Whether the current swapchain was made for asynchronous flips.
+ pub const asyncSwapchain = rediwm_scene_output_async_swapchain;
extern fn rediwm_scene_output_damage_whole(output: *SceneOutput) void;
/// Repaints all of the output and asks for a frame.
pub const damageWhole = rediwm_scene_output_damage_whole;