From 075c87d52a4d90c0f00f8ba7ba849677771a9be3 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 18:08:45 +0200 Subject: vt: defer scrolls and batch framebuffer pushes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Streaming output scrolled one framebuffer push per line (each a ~3-8 MB write-only copy). The vt now scrolls the logical grid instantly in RAM and defers the display shift: N pending scrolls are pushed together as one shift_up_n — one push regardless of batch size. - vt: PENDING_SCROLLS counter; scroll_up shifts CELLS only; flush renders nothing while pending (the diff would otherwise re-rasterise the whole screen per line); sync_scroll() does one gop::shift_up_n + RENDERED mirror + normal diff flush (which re-blits just the newly exposed rows and the cursor). - Sync triggers: batch of 16 rows, ~40 ms of stream pause (100 Hz TICKS), any CSI sequence (full-screen apps like the editor render immediately), clear_all/set_cursor_visible, interactive input (tty read_line/read_byte), and the shell before each prompt. - gop: shift_up → shift_up_n(n) (one shadow memcpy + one push). Verified in QEMU: mmap/hexdump streaming renders in coherent batches with the prompt syncing at the end; clear wipes clean; the editor scrolls and redraws immediately (45-line file, gutter + status bar intact, cursor correct); save/exit/cat round-trip unchanged. Release and dev builds pass. --- rsnix/src/gop.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'rsnix/src/gop.rs') diff --git a/rsnix/src/gop.rs b/rsnix/src/gop.rs index fa5378e..fa14eae 100644 --- a/rsnix/src/gop.rs +++ b/rsnix/src/gop.rs @@ -149,14 +149,16 @@ impl Framebuffer { } } - /// Shift the whole framebuffer up one row (16 pixels) and clear the - /// exposed bottom row. Called by `vt::scroll_up`; the vt then re-blits - /// only the new bottom row. + /// Shift the framebuffer content up by `n` text rows (16 pixels each) + /// and clear the exposed bottom rows. Called by `vt` when deferred + /// scrolls are pushed to the display; `n` can batch many scrolls into + /// one write-only push. /// /// With the RAM backbuffer, this is a cached shadow memcpy + a /// write-only push to the display — the display itself is never read /// (reads are uncached on real hardware and dominate the old path). - pub(crate) fn shift_up(&self) { + pub(crate) fn shift_up_n(&self, n: usize) { + let n = n.max(1).min(self.height / 16); // sanity let row_bytes = self.pitch * 16; let total = self.pitch * self.height; let row_words = row_bytes / 4; @@ -165,17 +167,17 @@ impl Framebuffer { if SHADOW.is_null() { // No shadow (allocation failed): fall back to shifting the // display directly. - ptr::copy(self.base.add(row_bytes), self.base, total - row_bytes); - let last_row = self.base.add(total - row_bytes); - for i in 0..row_words { + ptr::copy(self.base.add(n * row_bytes), self.base, total - n * row_bytes); + let last_row = self.base.add(total - n * row_bytes); + for i in 0..(n * row_words) { ptr::write_volatile(last_row.add(i * 4) as *mut u32, self.bg); } return; } - // Shift the shadow up one row (cached RAM — fast). - ptr::copy(SHADOW.add(row_words), SHADOW, words - row_words); - // Clear the exposed bottom row in the shadow. - for i in (words - row_words)..words { + // Shift the shadow up n rows (cached RAM — fast). + ptr::copy(SHADOW.add(n * row_words), SHADOW, words - n * row_words); + // Clear the exposed bottom rows in the shadow. + for i in (words - n * row_words)..words { *SHADOW.add(i) = self.bg; } // Push the shadow to the display: write-only, no reads. @@ -372,10 +374,11 @@ pub(crate) fn blit_glyph(col: usize, row: usize, ch: u16, fg: (u8, u8, u8), bg: } } -/// Shift the framebuffer up one row and clear the bottom row. -pub(crate) fn shift_up() { +/// Shift the framebuffer content up `n` text rows and clear the exposed +/// bottom rows. `n` batches deferred scrolls into one push. +pub(crate) fn shift_up_n(n: usize) { if let Some(fb) = unsafe { FB.as_ref() } { - fb.shift_up(); + fb.shift_up_n(n); } } -- cgit v1.2.3