perf: fast display (row runs, bulk fills, pixel scroll), terminal draws changed cells only + scrolls pixels, print! batched (was IPC per fmt fragment), snake sleeps on timer
This commit is contained in:
@@ -118,15 +118,36 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
/// `count` u32s from `offset` set to `value`.
|
||||
/// `count` u32s from `offset` set to `value`: one check, then a run of
|
||||
/// stores (drawing fills thousands at a time).
|
||||
pub fn fill_u32(&self, offset: ByteOffset, count: usize, value: u32) {
|
||||
let bytes = count.checked_mul(4).expect("window fill too large");
|
||||
self.at(offset, bytes, 4);
|
||||
let addr = self.at(offset, bytes, 4) as *mut u32;
|
||||
for i in 0..count {
|
||||
self.write(offset + i * 4, value);
|
||||
// SAFETY: the whole run was checked in range and aligned.
|
||||
unsafe { core::ptr::write_volatile(addr.add(i), value) }
|
||||
}
|
||||
}
|
||||
|
||||
/// `values` stored from `offset` on, in one checked run.
|
||||
pub fn write_u32s(&self, offset: ByteOffset, values: &[u32]) {
|
||||
let addr = self.at(offset, values.len() * 4, 4) as *mut u32;
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
// SAFETY: the whole run was checked in range and aligned.
|
||||
unsafe { core::ptr::write_volatile(addr.add(i), *v) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves `len` bytes from `from` to `to` inside the window; the two may
|
||||
/// overlap.
|
||||
pub fn copy_within(&self, from: ByteOffset, to: ByteOffset, len: usize) {
|
||||
let src = self.at(from, len, 1) as *const u8;
|
||||
let dst = self.at(to, len, 1) as *mut u8;
|
||||
// SAFETY: both ranges are inside the mapped window; `copy` allows
|
||||
// overlap. Plain memory moves, not device registers.
|
||||
unsafe { core::ptr::copy(src, dst, len) }
|
||||
}
|
||||
|
||||
/// `count` words from `offset` as atomics, for memory shared with
|
||||
/// threads or processes that only ever touch it atomically.
|
||||
pub fn atomics(&self, offset: ByteOffset, count: usize) -> &'static [AtomicUsize] {
|
||||
|
||||
Reference in New Issue
Block a user