Draw in the host: the wasm compositor sends draw ops, the host rasterises natively
CI / test (push) Failing after 29s
CI / test (push) Failing after 29s
The wasm software renderer cost ~10-20 ns/pixel, so any changed frame took ~100+ ms at 1080p and the desktop swung between idle and very slow. The compositor still builds the scene (windows, decorations, panel, wallpaper) but a new moonplasma:host/raster interface turns it into pixels in the host: - host-wasm/src/raster.rs: a port of compositor/renderer (same blend arithmetic: fills, strokes, lines, circles, text, clips, shadows, surface blits), a wallpaper+desktop-card cache, and captured client surfaces (copied out of the shared memory once at commit, converted to RGBA, solid ones blit as row copies). 9 unit tests; a full frame matches the native software renderer except for text antialiasing (0.3% of pixels). - compositor/raster sends a SceneGraph as ops; compositor.compose_scene() returns it only when something changed. The login session shows the host framebuffer directly (display.present-frame), the nested window gets it as a memfd (raster.export-memfd), --gfx-out reads it (read-frame). - Client buffers never enter wasm: snapshot_shm_buffer captures in the host and keeps an id. - Loop pacing sleeps the rest of the frame budget instead of a fixed 16/8 ms. Full-screen terminal flooding output at 1080p: ~2 fps / 94% CPU -> ~57 fps; idle ~9%. The native build keeps the software renderer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66bf293085
commit
c6e31b4a8f
38 files changed
+2141
-220
No files matched your search
+46
-14
@@ -122,7 +122,6 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
|
||||
let gfx_surface = @gfx.Surface::new({ width: Some(width), height: Some(height) })
|
||||
let gfx_ctx = @gfx.SurfaceFrameBufferContext::new(gfx_surface)
|
||||
|
||||
match @host.MoonPlasmaCompositor::new(socket_path, theme, width, height) {
|
||||
None => {
|
||||
@@ -138,8 +137,11 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.restore_state() // and the layout mode and recent apps from the last session
|
||||
comp.shell.screen_w = width
|
||||
if gfx_out.length() > 0 && !serve {
|
||||
let pixmap = comp.present_to_gfx(gfx_ctx)
|
||||
ignore(@sys.write_file_bytes(gfx_out, @renderer.encode_png(pixmap)))
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => @raster.submit(sg)
|
||||
None => ()
|
||||
}
|
||||
ignore(@sys.write_file_bytes(gfx_out, @renderer.encode_png(@raster.read_frame(width, height))))
|
||||
comp.close()
|
||||
@sys.log("frame written to " + gfx_out)
|
||||
return 0
|
||||
@@ -192,10 +194,19 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.step()
|
||||
let f1 = @sys.monotonic_ms()
|
||||
k.set_cursor_shape(comp.desired_cursor())
|
||||
let px = comp.compose_frame()
|
||||
need_present = need_present || comp.frame_changed
|
||||
// The host draws; only a changed desktop is sent, and the frame is shown by the host
|
||||
// straight from its framebuffer.
|
||||
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
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if need_present && k.frame_ready() {
|
||||
k.present(px)
|
||||
k.present_frame()
|
||||
need_present = false
|
||||
}
|
||||
if profile {
|
||||
@@ -213,7 +224,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.prof_raster_ms = 0UL
|
||||
}
|
||||
}
|
||||
@sys.sleep_ms(8)
|
||||
// Sleep out what is left of the frame budget (8 ms), not a fixed 8 ms on top of the work.
|
||||
let spent = (@sys.monotonic_ms() - f0).to_int()
|
||||
@sys.sleep_ms(if spent >= 8 { 1 } else { 8 - spent })
|
||||
continue
|
||||
}
|
||||
None => ()
|
||||
@@ -236,18 +249,35 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
n.set_cursor_shape(comp.desired_cursor())
|
||||
let px = comp.compose_frame()
|
||||
need_present = need_present || comp.frame_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
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if need_present && n.frame_ready() {
|
||||
n.present(px)
|
||||
n.present_frame(width, height)
|
||||
need_present = false
|
||||
}
|
||||
}
|
||||
None => {
|
||||
comp.handle_gfx_events(gfx_surface)
|
||||
let pixmap = comp.present_to_gfx(gfx_ctx)
|
||||
if serve && gfx_out.length() > 0 && frames % 30 == 0 {
|
||||
ignore(@sys.write_file_bytes(gfx_out, @renderer.encode_png(pixmap)))
|
||||
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
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
// 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 {
|
||||
ignore(@sys.write_file_bytes(gfx_out, @renderer.encode_png(@raster.read_frame(width, height))))
|
||||
need_present = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,7 +296,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.prof_raster_ms = 0UL
|
||||
}
|
||||
}
|
||||
@sys.sleep_ms(16)
|
||||
// About 60 frames a second: sleep what is left of 16 ms after the work.
|
||||
let spent = (@sys.monotonic_ms() - f0).to_int()
|
||||
@sys.sleep_ms(if spent >= 16 { 1 } else { 16 - spent })
|
||||
}
|
||||
match kms {
|
||||
Some(k) => k.close()
|
||||
|
||||
Reference in new issue
Block a user