Smoother animations without a GPU: faster rasteriser, frame pacing, software/hardware mode
CI / test (push) Failing after 3m2s
CI / test (push) Failing after 3m2s
Measured headless at 1920x1080 with CHANDRA_FRAME_TRACE (new: one log line per drawn frame): - Overview open: 46 -> 62 fps, worst frame gap 69 -> 36 ms, raster 14 -> 5 ms a frame. - Live Starfield: 19 -> 30 fps (its target), raster 49 -> 13 ms, CPU 97% -> 46%. Rasteriser (MoonBit host; circles and previews also in the Rust host): - Blending works on two channels at a time in 16-bit lanes with an exact /255: same pixels, about 3x quicker on big translucent fills (the overview's dim, the starfield's nebulae). - Filled circles are drawn as row spans, rings skip their empty middle (a sqrt per pixel of the bounding box before). Same pixels; a Rust test checks it against the old loop. - Window previews gliding in the overview are sampled straight from the preview at each frame's size instead of filtered and cached at a size used once; the MoonBit host also gets the one-large-size cache and 4096 px draw limit the Rust host had (it kept every size and didn't draw previews past 1024 px). - Image scaling sums each output row's columns once, with 32-bit sums and division. Frame pacing: frames are drawn only when the output can take them (no page flip in flight on KMS; the previous frame shown nested and on X11), with a frame every 250 ms for an output that never gets ready. The KMS loop runs at 125 Hz, so animations used to rasterise frames that were never shown. Software or hardware mode (compositor/shell/render_mode.mbt, docs/rendering.md): detected from the DRM render nodes' drivers (and NVIDIA's proprietary driver, LIBGL_ALWAYS_SOFTWARE), overridden by CHANDRA_RENDER=software|hardware or Settings > Session "Lighter animations" (state.edn :render, saved only when it differs from what was detected). Software mode remakes changing previews every 200 ms instead of 100 ms and caps desktop modules at ~30 fps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hkTQp5uN5FtwpzrXUA
This commit is contained in:
16 files changed
+719
-97
No files matched your search
+58
-36
@@ -179,7 +179,11 @@ pub fn run(args : Array[String]) -> Int {
|
||||
let login = drm || login
|
||||
comp.sync_system_theme = login // the login session sets apps' dark/light preference
|
||||
comp.login_session = login // and power actions (suspend, power off) act on the machine
|
||||
// GPU or not (CHANDRA_RENDER overrides): without one the desktop asks less of the CPU.
|
||||
let (rmode, rwhy) = @shell.detect_render_mode()
|
||||
comp.shell.set_render_detected(rmode, rwhy)
|
||||
comp.restore_state() // and the layout mode and recent apps from the last session
|
||||
@sys.log(comp.shell.render_summary())
|
||||
comp.shell.screen_w = width
|
||||
// Screenshots and recordings read the host's framebuffer (it draws the desktop).
|
||||
comp.frame_source = Some(fn() { Some(@raster.read_frame(comp.output_w, comp.output_h)) })
|
||||
@@ -239,6 +243,10 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
let mut frames = 0
|
||||
let idle = IdleClock::new()
|
||||
// CHANDRA_FRAME_TRACE=1: one log line per drawn frame (when, and how long composing and
|
||||
// rasterising took), for measuring how smooth animations are.
|
||||
let trace = @sys.getenv("CHANDRA_FRAME_TRACE").length() > 0
|
||||
let pacer = Pacer::{ last_ms: 0UL }
|
||||
// A changed frame waits here until the display can take it (no page flip in flight).
|
||||
let mut need_present = true
|
||||
// --profile: every 3 s print how long each frame part took on average.
|
||||
@@ -274,15 +282,15 @@ pub fn run(args : Array[String]) -> Int {
|
||||
k.set_cursor_shape(comp.desired_cursor())
|
||||
// The host draws; only a changed desktop is sent, and the frame is shown by the host
|
||||
// straight from its framebuffer.
|
||||
let changed = match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
true
|
||||
}
|
||||
None => false
|
||||
// Draw only when the display can take the frame (no page flip in flight): a frame
|
||||
// drawn meanwhile would never be seen, and drawing it costs a whole frame's CPU.
|
||||
let changed = if k.frame_ready() || comp.screen_off || pacer.overdue() {
|
||||
draw_frame(comp, trace, pacer)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
if changed {
|
||||
need_present = true
|
||||
}
|
||||
if need_present && k.frame_ready() {
|
||||
k.present_frame()
|
||||
@@ -361,15 +369,10 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
n.set_cursor_shape(comp.desired_cursor())
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
// As on a display: draw when the host compositor can take the frame.
|
||||
if (n.frame_ready() || pacer.overdue()) && draw_frame(comp, trace, pacer) {
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
if need_present && n.frame_ready() {
|
||||
n.present_frame(width, height)
|
||||
@@ -407,15 +410,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
x.set_cursor_shape(comp.desired_cursor())
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
if (x.frame_ready() || pacer.overdue()) && draw_frame(comp, trace, pacer) {
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
if need_present && x.frame_ready() {
|
||||
x.present_frame(width, height)
|
||||
@@ -426,15 +423,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
None => {
|
||||
comp.handle_gfx_events(gfx_surface)
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = serve && gfx_out.length() > 0
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
if draw_frame(comp, trace, pacer) {
|
||||
need_present = serve && gfx_out.length() > 0
|
||||
busy = true
|
||||
}
|
||||
// No display: --serve keeps a PNG of the latest frame for looking at a live compositor.
|
||||
if serve && gfx_out.length() > 0 && frames % 30 == 0 && need_present {
|
||||
@@ -479,6 +470,37 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
}
|
||||
|
||||
///| When the last frame was drawn: an output that never says it is ready again (a hidden nested
|
||||
/// window gets no frame callbacks) still gets a frame now and then, so screenshots, recordings
|
||||
/// and clients waiting on frame callbacks carry on.
|
||||
struct Pacer {
|
||||
mut last_ms : UInt64
|
||||
}
|
||||
|
||||
///|
|
||||
fn Pacer::overdue(self : Pacer) -> Bool {
|
||||
@sys.monotonic_ms() - self.last_ms >= 250UL
|
||||
}
|
||||
|
||||
///| Compose the desktop and hand a changed frame to the host to draw. True when it changed.
|
||||
fn draw_frame(comp : @host.ChandraCompositor, trace : Bool, pacer : Pacer) -> Bool {
|
||||
let c0 = @sys.monotonic_ms()
|
||||
pacer.last_ms = c0
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
let r1 = @sys.monotonic_ms()
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (r1 - r0)
|
||||
if trace {
|
||||
@sys.log("frame " + r1.to_string() + " compose " + (r0 - c0).to_string() + " raster " + (r1 - r0).to_string())
|
||||
}
|
||||
true
|
||||
}
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
///| How long an idle main loop may sleep. Nothing on screen changes without a client, the seat or
|
||||
/// the display waking the loop, except what follows the wall clock (clocks, the desktop card,
|
||||
/// system stats, notices), which changes on whole seconds. So an idle loop sleeps until just
|
||||
|
||||
Reference in new issue
Block a user