Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ hashes are given where a change is easiest to understand by reading the commit.

## November 2026

### Display

- The O2's display scans out and presents a frame only when the screen may have
changed: the rendering engine wrote memory, a GBE register changed (IRIX's
per-frame rewrites of the same value do not count), a shadow register went live
at vertical blanking, or a snapshot was restored. An idle desktop no longer
decodes 1.3 million pixels sixty times a second. The decode writes the final
pixel format, so the frame goes to the renderer by a row copy. A screenshot, a
frame request or a VNC client still gets a fresh frame, and a window still
has its status bar redrawn about ten times a second. While a window or a VNC
client watches, the screen is scanned at least once a second whatever marked
it, so a guest that draws with CPU stores and no command (a Linux frame buffer
console) is at most a second stale.
- The VPro (Octane2, Tezro) display composes no frames while nothing shows or
reads them: `--ci` with no window, and no screenshot, frame request or VNC
client. With the GPU raster unit a frame was a GPU scan-out, a readback and a
pass over every pixel, sixty times a second, for nobody. The retrace still runs
and the screen's size is still known; a request composes the next frame whole.
- Newport (Indy, Indigo2 XL): the display marks the frame buffer changed after a
GFIFO entry's effect, not before it. A frame that took the mark while a draw
was still landing composed without it, and nothing marked again until the next
command, so the last draw of a burst could stay off the screen while the guest
idled.
- `screen frames [reset]` on the monitor says how many frames a board's display
thread ran, composed and skipped. The O2 and the VPro count them; the other
boards say they do not yet.

### Bench rig

- The bare-metal bench rig (`[testdev]`) takes `cpu = "r14000_500"`, the
Expand Down
1 change: 1 addition & 0 deletions debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ to learn the cursor's hotspot exactly.
| `screen shot <file.png> [x y w h]` | The composed screen as PNG (no host status bar), optionally cropped |
| `screen pix <x> <y>` | One pixel, `rrggbb` |
| `screen wait [quiet_ms] [timeout_ms]` | Wait until the screen has not changed for `quiet_ms` (default 500, at most 10000 ms) |
| `screen frames [reset]` | How many frames the display thread ran, composed and skipped (O2 and VPro; the other boards say they do not count), and zero them |
| `screen cursor` | The cursor glyph as text, with its hotspot |
| `ptr pos` | Where the pointer is |
| `ptr move <x> <y>` | Put the pointer on a pixel |
Expand Down
16 changes: 16 additions & 0 deletions src/dev/crime_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ impl O2Memory {
.collect()
}

/// The scan-out's change flag: marked when the rendering engine wrote
/// memory or memory was restored.
pub fn screen_changed(&self) -> &std::sync::Arc<crate::gfx_display::ScreenChanged> {
&self.shared.changed
}

/// Put back words [`Self::bank_words`] gave, concatenated, with every
/// page's generation bumped so no compiled code outlives them.
pub fn restore_words(&self, words: &[u32]) -> Result<(), String> {
Expand All @@ -457,6 +463,7 @@ impl O2Memory {
b.bump_gen_all();
at += n;
}
self.shared.changed.mark();
Ok(())
}

Expand Down Expand Up @@ -551,6 +558,9 @@ impl std::ops::IndexMut<usize> for O2Memory {
pub struct WindowState {
mapped: std::sync::atomic::AtomicU32,
decode_gen: std::sync::atomic::AtomicU64,
/// Marked when the rendering engine has written memory, and when a snapshot
/// puts memory back: the scan-out reads it.
changed: std::sync::Arc<crate::gfx_display::ScreenChanged>,
}

/// Memory as a master on its own thread sees it: guest physical addresses
Expand Down Expand Up @@ -594,6 +604,12 @@ impl RamWindow {
// Release, after the run's bytes (`PpMemory::bump_gen`).
unsafe { (*self.gens.add(page)).fetch_add(1, std::sync::atomic::Ordering::Release) };
}
// One mark per run that wrote, after its bytes. The engine may have
// drawn into a buffer that is not on screen: that costs a frame, and a
// missed change would cost the picture.
if !self.dirty.is_empty() {
self.shared.changed.mark();
}
self.dirty.clear();
}

Expand Down
38 changes: 17 additions & 21 deletions src/dev/kona/back/display/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use crate::cpu::mips_core::CyclesPtr;
use crate::dev::ng1::rex3::Renderer;
use crate::disp::{Rex3Screen, StatusSource, FB_STRIDE};
use crate::gfx_display::{DisplayStop, GfxDisplay};
use crate::gfx_display::{DisplayStop, FrameRequests, GfxDisplay};
use parking_lot::Mutex;
use std::sync::atomic::{AtomicU32, AtomicU64, Ordering};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;


Expand All @@ -27,13 +27,11 @@ struct Local {
pub struct Display {
renderer: Mutex<Option<Box<dyn Renderer>>>,
screen: Mutex<Rex3Screen>,
/// Requests and what has been presented of them, as counts: a request is
/// pending until a frame composed after it has been presented, and one made
/// while a frame is composed is still pending after that frame.
screenshot_asked: AtomicU64,
screenshot_done: AtomicU64,
frame_asked: AtomicU64,
frame_done: AtomicU64,
/// Requests: one is pending until a frame composed after it has been
/// presented, and one made while a frame is composed is still pending after
/// that frame.
screenshot: FrameRequests,
frame: FrameRequests,
screenshots: AtomicU32,
display_stop: DisplayStop,
local: Mutex<Option<Local>>,
Expand All @@ -55,10 +53,8 @@ impl Display {
Display {
renderer: Mutex::new(None),
screen: Mutex::new(Rex3Screen::new()),
screenshot_asked: AtomicU64::new(0),
screenshot_done: AtomicU64::new(0),
frame_asked: AtomicU64::new(0),
frame_done: AtomicU64::new(0),
screenshot: FrameRequests::default(),
frame: FrameRequests::default(),
screenshots: AtomicU32::new(0),
display_stop: DisplayStop::default(),
local: Mutex::new(None),
Expand Down Expand Up @@ -87,7 +83,7 @@ impl Display {
/// composing and hand it to `present`: a request made while the frame is
/// composed is not in it, and stays pending after that frame is presented.
pub fn note(&self) -> Due {
Due { screenshot: self.screenshot_asked.load(Ordering::Acquire), frame: self.frame_asked.load(Ordering::Acquire) }
Due { screenshot: self.screenshot.note(), frame: self.frame.note() }
}

/// Whether a screenshot or a frame has been asked for and not yet presented.
Expand All @@ -113,7 +109,7 @@ impl Display {
}
screen.frame_seq = screen.frame_seq.wrapping_add(1);
// A requested screenshot is saved as presented.
if due.screenshot != self.screenshot_done.load(Ordering::Acquire) {
if self.screenshot.answers(due.screenshot) {
let pixels = screen.rgba.clone();
let n = self.screenshots.fetch_add(1, Ordering::Relaxed);
let path = format!("screenshot_{:04}.png", n);
Expand All @@ -140,8 +136,8 @@ impl Display {
}
// Mark only the requests this frame answers: one made while it was
// composed stays pending for the next.
self.screenshot_done.store(due.screenshot, Ordering::Release);
self.frame_done.store(due.frame, Ordering::Release);
self.screenshot.answer(due.screenshot);
self.frame.answer(due.frame);
}

/// The display thread's last act: release the renderer, unless the stop came
Expand All @@ -166,11 +162,11 @@ impl GfxDisplay for Display {
}

fn request_screenshot(&self) {
self.screenshot_asked.fetch_add(1, Ordering::AcqRel);
self.screenshot.request();
}

fn screenshot_pending(&self) -> bool {
self.screenshot_asked.load(Ordering::Acquire) != self.screenshot_done.load(Ordering::Acquire)
self.screenshot.pending()
}

fn cycles(&self) -> CyclesPtr {
Expand All @@ -183,11 +179,11 @@ impl GfxDisplay for Display {
}

fn request_frame(&self) {
self.frame_asked.fetch_add(1, Ordering::AcqRel);
self.frame.request();
}

fn frame_pending(&self) -> bool {
self.frame_asked.load(Ordering::Acquire) != self.frame_done.load(Ordering::Acquire)
self.frame.pending()
}
}

Expand Down
38 changes: 35 additions & 3 deletions src/dev/ng1/rex3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,12 @@ pub struct Rex3 {
#[cfg(feature = "rex-dirty-upload")]
fb_damage: DamageTracker,
pub screen: Arc<Mutex<Rex3Screen>>,
/// Test hook: while set the processor parks at `test_hold_point`, and
/// `test_held` says it has.
#[cfg(test)]
pub(super) test_hold: AtomicBool,
#[cfg(test)]
pub(super) test_held: AtomicBool,
/// Drives the real REX3 `VV_INT_N` pin (vertical retrace / Kaleidoscope).
pub vblank_cb: Mutex<Option<crate::irq::IrqLine>>,
/// Drives the real REX3 `FIFO_INT_N` pin (GFIFO/BFIFO above/below
Expand Down Expand Up @@ -1704,6 +1710,10 @@ impl Rex3 {
#[cfg(feature = "rex-dirty-upload")]
fb_damage: DamageTracker::new_full(),
screen,
#[cfg(test)]
test_hold: AtomicBool::new(false),
#[cfg(test)]
test_held: AtomicBool::new(false),
vblank_cb: Mutex::new(None),
pf_wait: crate::PfLevel::new(),
pf_fifo_full: crate::PfLevel::new(),
Expand Down Expand Up @@ -3272,6 +3282,17 @@ impl Rex3 {
self.flush_gpu_replay(FlushReason::WaitIdle);
}

#[cfg(test)]
fn test_hold_point(&self) {
if self.test_hold.load(Ordering::SeqCst) {
self.test_held.store(true, Ordering::SeqCst);
while self.test_hold.load(Ordering::SeqCst) {
std::thread::yield_now();
}
self.test_held.store(false, Ordering::SeqCst);
}
}

fn register_processor(&self) {
// Publish our thread handle so gfifo_push can unpark us when we park.
let _ = self.processor_unparker.set(thread::current());
Expand All @@ -3288,8 +3309,10 @@ impl Rex3 {
continue;
}

#[cfg(not(feature = "rex-dirty-upload"))]
self.fb_dirty.store(true, Ordering::Relaxed);
// Test hook: parks the processor with the entry peeked and
// nothing applied yet.
#[cfg(test)]
self.test_hold_point();

if !is_busy {
self.gfxbusy.store(true, Ordering::Relaxed);
Expand Down Expand Up @@ -3317,6 +3340,15 @@ impl Rex3 {
}
}

// Marked after the entry's effect, with release order, so a
// frame that takes the mark reads the pixels it follows. Marked
// before it, a frame could take the mark while a GO was still
// drawing and compose without it; nothing marks again until the
// next entry, and an idle frame does not compose, so the last
// draw of a burst stayed off the screen.
#[cfg(not(feature = "rex-dirty-upload"))]
self.fb_dirty.store(true, Ordering::Release);

// Advance head and release busy atomically — CPU thread sees all writes
// (context registers + FB) only after both process_register and execute_go
// have completed.
Expand Down Expand Up @@ -3789,7 +3821,7 @@ impl Rex3 {
#[cfg(feature = "rex-dirty-upload")]
let fb_was_dirty = self.fb_damage.has_damage();
#[cfg(not(feature = "rex-dirty-upload"))]
let fb_was_dirty = self.fb_dirty.swap(false, Ordering::Acquire);
let fb_was_dirty = self.fb_dirty.swap(false, Ordering::AcqRel);
let should_render = fb_was_dirty
|| palette_dirty
|| dbg_overlay
Expand Down
39 changes: 39 additions & 0 deletions src/dev/ng1/rex3_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10847,3 +10847,42 @@ fn rexget_clears_the_sign_extension() {
// Writing then reading a negative coordinate leaves its 23-bit form.
assert_eq!((-0x80i32 as u32).rexset(9, 7).rexget(9, 7), 0x007F_FF80);
}

/// The display thread reads a frame while the processor holds a GO it has
/// peeked but not applied. The draw lands after that frame, so the mark must
/// be up afterwards: nothing else marks until the next command, and an idle
/// frame does not compose.
#[cfg(not(feature = "rex-dirty-upload"))]
#[test]
fn burst_ordering_the_last_draw_is_marked_after_the_frame_that_missed_it() {
let rex = &make_rex3_unstarted();
start_rex3_processor_only(rex);
rex3init(rex);
reg(rex, REX3_DRAWMODE1, DM1_CI8_SRC);
reg(rex, REX3_WRMASK, 0xFF);
reg(rex, REX3_COLORI, 0x5a);
reg(rex, REX3_XYENDI, xy(63, 15));
reg(rex, REX3_XYSTARTI, xy(0, 0));
wait(rex);
let _ = rex.fb_dirty.swap(false, Ordering::AcqRel);

let hash = |rex: &Rex3| {
let fb = unsafe { &*rex.fb_rgb.get() };
fb.iter().take(2048 * 16).fold(0u64, |h, &p| h.wrapping_mul(1099511628211).wrapping_add(p as u64 + 1))
};

rex.test_hold.store(true, Ordering::SeqCst);
w32(rex, go_addr(REX3_DRAWMODE0), DM0_DRAW_BLOCK);
while !rex.test_held.load(Ordering::SeqCst) {
std::thread::yield_now();
}
// The display's frame: take the mark, then read the pixels.
let during = rex.fb_dirty.swap(false, Ordering::AcqRel);
let seen = hash(rex);
rex.test_hold.store(false, Ordering::SeqCst);
wait(rex);
let after = hash(rex);
let leftover = rex.fb_dirty.swap(false, Ordering::AcqRel);
assert_ne!(seen, after, "the held GO must draw after the frame read");
assert!(leftover, "the draw landed after the frame (mark taken during the hold: {during}) and nothing marked it afterwards, so the next idle frame leaves it unseen");
}
Loading