🔥 Draw the scanout at each refresh, without the host's dirty log
The display showed the guest's scanout again at a refresh only where the host's dirty log said the guest wrote it (scanout_written, QEMU's log over BAR 2's allocations). The scanout shows only at boot and in recovery, and the owner takes its full cost for the simplicity (2026-11-07): the callback, RvgGraphicsScanoutWrittenFn and RvgGraphicsCallbacks' scanout_written, are gone from the C API, with reims-vgpu's ScanoutWrittenFn and reims-graphics' Host::scanout_written. Each refresh while the guest has a scanout now asks the screen to show it again (Screen::present). The window draws it only while it shows the scanout: while a presented surface shows, a refresh draws nothing, and the guest's presents alone draw, as before, so an accelerated desktop's refreshes cost no frame (a 4K window at 120 Hz would otherwise copy about 4 GB/s for nothing). For the host: RvgGraphicsCallbacks loses its scanout_written field, so the cursor callbacks after it move up one pointer; QEMU's reims-graphics-pci no longer sets it (the commit before). For the guest: the boot and recovery screens show what the guest wrote by the next refresh, as before. Window::frames_asked counts the frames a window is asked for, which the new tests read: a refresh draws the scanout while no surface shows, and nothing while one does.
This commit is contained in:
1 parent
2925e0dd1d
commit
a0dc2e80ff
22 files changed
+191
-252
No files matched your search
@@ -22,11 +22,11 @@
|
||||
//! The replies (a pipeline's reflection, a `COMPLETE`) come back on the control completion ring.
|
||||
//! Every other ring is a command queue's own (below), so each ring keeps a single producer and a
|
||||
//! single consumer, and their `consumer_idle` handshakes never race.
|
||||
//! `reims-vgpu.graphics-refresh` runs at the display's refresh rate
|
||||
//! ([`Screen::mode`]): at each refresh it asks the host whether the guest wrote the scanout
|
||||
//! ([`Host::scanout_written`]) and has the screen show it where it did, sends `VBLANK` while the
|
||||
//! guest has it on, stamped with the refresh's time on its grid (`RefreshGrid`) as a panel's
|
||||
//! hardware stamps its vblank (dropping one the completion ring has no room for), sends
|
||||
//! `reims-vgpu.graphics-refresh` runs at the display's refresh rate ([`Screen::mode`]): at each
|
||||
//! refresh it has the screen show the scanout again while the guest has one
|
||||
//! ([`Screen::present`]), sends `VBLANK` while the guest has it on, stamped with the refresh's
|
||||
//! time on its grid (`RefreshGrid`) as a panel's hardware stamps its vblank (dropping one the
|
||||
//! completion ring has no room for), sends
|
||||
//! `DISPLAY_CHANGED` once the display's mode is not the one the guest was last told, and then
|
||||
//! tells the host of the refresh ([`Host::refreshed`]), which answers there the presents the
|
||||
//! display first shows at it.
|
||||
@@ -316,11 +316,6 @@ pub trait Host: Send + Sync + 'static {
|
||||
/// answered or taken).
|
||||
fn raise_interrupt(&self, vector: u32);
|
||||
|
||||
/// Whether the guest wrote any of the `length` bytes at `offset` in the region since the last
|
||||
/// time this asked, which starts the next span: the host's dirty log of the range, taken and
|
||||
/// cleared. On the refresh thread.
|
||||
fn scanout_written(&self, offset: u64, length: u64) -> bool;
|
||||
|
||||
/// Context `context` was closed (its process closed the device or died): the host drops every
|
||||
/// object whose id lies in the context's range (`context << RGFX_CONTEXT_OBJ_ID_SHIFT` and up,
|
||||
/// below the next context's), and gives `answer` ([`RGFX_STATUS_OK`]) once every command
|
||||
@@ -2575,9 +2570,7 @@ impl Shared {
|
||||
display.changed,
|
||||
)
|
||||
};
|
||||
if let Some(scanout) = scanout
|
||||
&& self.host.scanout_written(scanout.offset, scanout.span())
|
||||
{
|
||||
if scanout.is_some() {
|
||||
self.screen.present();
|
||||
}
|
||||
if let Some(count) = vblank {
|
||||
|
||||
@@ -65,12 +65,9 @@ enum Seen {
|
||||
},
|
||||
}
|
||||
|
||||
/// A host that counts its interrupts and answers whether the scanout was written as the test
|
||||
/// sets it.
|
||||
/// A host that counts its interrupts and records the presents and refreshes it is told of.
|
||||
struct TestHost {
|
||||
interrupts: Arc<AtomicU32>,
|
||||
written: Arc<AtomicBool>,
|
||||
asked: Arc<Mutex<Vec<(u64, u64)>>>,
|
||||
presented: Presented,
|
||||
refreshes: Arc<AtomicU32>,
|
||||
seen: Arc<Mutex<Vec<Seen>>>,
|
||||
@@ -84,10 +81,6 @@ impl Host for TestHost {
|
||||
assert_eq!(vector, 0);
|
||||
self.interrupts.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
fn scanout_written(&self, offset: u64, length: u64) -> bool {
|
||||
self.asked.lock().push((offset, length));
|
||||
self.written.load(Ordering::SeqCst)
|
||||
}
|
||||
fn refreshed(&self) {
|
||||
self.refreshes.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
@@ -120,8 +113,6 @@ struct Rig {
|
||||
mode: Arc<Mutex<Mode>>,
|
||||
told: Arc<Mutex<Vec<Told>>>,
|
||||
interrupts: Arc<AtomicU32>,
|
||||
written: Arc<AtomicBool>,
|
||||
asked: Arc<Mutex<Vec<(u64, u64)>>>,
|
||||
presented: Presented,
|
||||
/// The refreshes the host was told of.
|
||||
refreshes: Arc<AtomicU32>,
|
||||
@@ -143,23 +134,17 @@ const MODE: Mode = Mode {
|
||||
impl Rig {
|
||||
fn new() -> Rig {
|
||||
let interrupts = Arc::new(AtomicU32::new(0));
|
||||
let written = Arc::new(AtomicBool::new(false));
|
||||
let asked = Arc::new(Mutex::new(Vec::new()));
|
||||
let presented = Arc::new(Mutex::new(Vec::new()));
|
||||
let refreshes = Arc::new(AtomicU32::new(0));
|
||||
let seen = Arc::new(Mutex::new(Vec::new()));
|
||||
let host = TestHost {
|
||||
interrupts: Arc::clone(&interrupts),
|
||||
written: Arc::clone(&written),
|
||||
asked: Arc::clone(&asked),
|
||||
presented: Arc::clone(&presented),
|
||||
refreshes: Arc::clone(&refreshes),
|
||||
seen: Arc::clone(&seen),
|
||||
};
|
||||
let mut rig = Rig::with_host(Box::new(host));
|
||||
rig.interrupts = interrupts;
|
||||
rig.written = written;
|
||||
rig.asked = asked;
|
||||
rig.presented = presented;
|
||||
rig.refreshes = refreshes;
|
||||
rig.seen = seen;
|
||||
@@ -176,8 +161,6 @@ impl Rig {
|
||||
let mode = Arc::new(Mutex::new(MODE));
|
||||
let told = Arc::new(Mutex::new(Vec::new()));
|
||||
let interrupts = Arc::new(AtomicU32::new(0));
|
||||
let written = Arc::new(AtomicBool::new(false));
|
||||
let asked = Arc::new(Mutex::new(Vec::new()));
|
||||
let presented = Arc::new(Mutex::new(Vec::new()));
|
||||
let region = Arc::new(Region::new(REGION_SIZE as usize).unwrap());
|
||||
let device = Device::with_lanes(
|
||||
@@ -195,8 +178,6 @@ impl Rig {
|
||||
mode,
|
||||
told,
|
||||
interrupts,
|
||||
written,
|
||||
asked,
|
||||
presented,
|
||||
refreshes: Arc::new(AtomicU32::new(0)),
|
||||
seen: Arc::new(Mutex::new(Vec::new())),
|
||||
@@ -524,9 +505,6 @@ impl Host for ResettingHost {
|
||||
self.resets.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn present_surface(&self, _iosurface_id: u32, _generation: Option<u64>, answer: PresentAnswer) {
|
||||
answer.answer(RGFX_STATUS_OK);
|
||||
}
|
||||
@@ -851,22 +829,19 @@ fn refresh_times_keep_to_their_grid_under_a_late_wake() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A refresh shows the scanout where the host's log says the guest wrote it, asking for the
|
||||
/// scanout's range; `VBLANK` carries the refresh count while it is on; the host is told of each
|
||||
/// A refresh shows nothing again before the guest has a scanout, and the scanout at each refresh
|
||||
/// once it has one; `VBLANK` carries the refresh count while it is on; the host is told of each
|
||||
/// refresh
|
||||
#[test]
|
||||
fn a_refresh_presents_written_pixels_and_sends_vblank() {
|
||||
fn a_refresh_presents_the_scanout_and_sends_vblank() {
|
||||
let mut rig = Rig::new();
|
||||
rig.start();
|
||||
let alloc = RGFX_ALLOCATIONS_OFFSET;
|
||||
rig.send(scanout(16, 4, 128, alloc));
|
||||
rig.complete();
|
||||
rig.told();
|
||||
rig.refresh();
|
||||
assert_eq!(rig.told(), []);
|
||||
assert_eq!(*rig.asked.lock(), [(alloc, 128 * 3 + 64)]);
|
||||
assert_eq!(rig.refreshes.load(Ordering::SeqCst), 1);
|
||||
rig.written.store(true, Ordering::SeqCst);
|
||||
rig.send(scanout(16, 4, 128, RGFX_ALLOCATIONS_OFFSET));
|
||||
rig.complete();
|
||||
rig.told();
|
||||
rig.refresh();
|
||||
assert_eq!(rig.told(), [Told::Present]);
|
||||
let s = rig.send(vblank(1));
|
||||
@@ -971,13 +946,11 @@ fn a_reset_puts_the_device_back_as_new() {
|
||||
fn a_reset_keeps_the_scanout_and_what_the_guest_writes_there_shows() {
|
||||
let mut rig = Rig::new();
|
||||
let alloc = RGFX_ALLOCATIONS_OFFSET;
|
||||
let span = 64 * 3 + 16 * 4;
|
||||
// The firmware's scanout.
|
||||
rig.start();
|
||||
rig.send(scanout(16, 4, 64, alloc));
|
||||
rig.complete();
|
||||
rig.told();
|
||||
rig.written.store(true, Ordering::SeqCst);
|
||||
let restart = |rig: &mut Rig| {
|
||||
(rig.produced, rig.consumed, rig.seqno) = (0, 0, 0);
|
||||
rig.start();
|
||||
@@ -994,10 +967,17 @@ fn a_reset_keeps_the_scanout_and_what_the_guest_writes_there_shows() {
|
||||
!rig.told().iter().any(|t| matches!(t, Told::Scanout(_))),
|
||||
"a reset told the screen of the scanout"
|
||||
);
|
||||
rig.asked.lock().clear();
|
||||
rig.refresh();
|
||||
assert_eq!(rig.told(), [Told::Present]);
|
||||
assert_eq!(*rig.asked.lock(), [(alloc, span)]);
|
||||
assert_eq!(
|
||||
rig.device
|
||||
.shared
|
||||
.display
|
||||
.lock()
|
||||
.scanout
|
||||
.map(|s| (s.offset, s.span())),
|
||||
Some((alloc, 64 * 3 + 16 * 4))
|
||||
);
|
||||
|
||||
// The guest's next driver sets another scanout, and then blanks the display.
|
||||
restart(&mut rig);
|
||||
@@ -1007,10 +987,17 @@ fn a_reset_keeps_the_scanout_and_what_the_guest_writes_there_shows() {
|
||||
rig.device
|
||||
.mmio_write(RGFX_REG_STATUS.into(), RGFX_STATUS_RESET);
|
||||
rig.told();
|
||||
rig.asked.lock().clear();
|
||||
rig.refresh();
|
||||
assert_eq!(rig.told(), [Told::Present]);
|
||||
assert_eq!(*rig.asked.lock(), [(alloc + 0x1000, 64 + 8 * 4)]);
|
||||
assert_eq!(
|
||||
rig.device
|
||||
.shared
|
||||
.display
|
||||
.lock()
|
||||
.scanout
|
||||
.map(|s| (s.offset, s.span())),
|
||||
Some((alloc + 0x1000, 64 + 8 * 4))
|
||||
);
|
||||
restart(&mut rig);
|
||||
rig.send(scanout(0, 0, 0, 0));
|
||||
rig.complete();
|
||||
@@ -1018,10 +1005,8 @@ fn a_reset_keeps_the_scanout_and_what_the_guest_writes_there_shows() {
|
||||
rig.device
|
||||
.mmio_write(RGFX_REG_STATUS.into(), RGFX_STATUS_RESET);
|
||||
rig.told();
|
||||
rig.asked.lock().clear();
|
||||
rig.refresh();
|
||||
assert_eq!(rig.told(), []);
|
||||
assert_eq!(*rig.asked.lock(), []);
|
||||
}
|
||||
|
||||
/// The host's doorbell file wakes the control thread as a `DOORBELL` write does
|
||||
@@ -1205,9 +1190,6 @@ impl Host for QueueTestHost {
|
||||
fn raise_interrupt(&self, vector: u32) {
|
||||
self.vectors.lock().push(vector);
|
||||
}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn context_closed(&self, context: u32, answer: crate::device::CompleteAnswer) {
|
||||
self.closed.lock().push(context);
|
||||
answer.answer(RGFX_STATUS_OK);
|
||||
@@ -1818,9 +1800,6 @@ impl HoldsHost {
|
||||
|
||||
impl Host for HoldsHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn context_closed(&self, context: u32, answer: CompleteAnswer) {
|
||||
self.seen.lock().push((RGFX_CMD_CONTEXT_CLOSE, context, 0));
|
||||
answer.answer(RGFX_STATUS_OK);
|
||||
@@ -2324,9 +2303,6 @@ const RESET_TOLD: u32 = u32::MAX;
|
||||
|
||||
impl Host for ResetTellingHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn stage3_message(&self, _completion: &CompletionPoster, message: &[u8]) {
|
||||
let (header, _) = RgfxMsgHeader::read_from_prefix(message).unwrap();
|
||||
self.0.lock().push((header.r#type, thread_name()));
|
||||
@@ -2494,9 +2470,6 @@ fn the_deferred_budget_reads_as_the_host_gives_it() {
|
||||
struct Budget;
|
||||
impl Host for Budget {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn features(&self) -> u64 {
|
||||
u64::from(RGFX_FEATURE_SURFACE_CACHE | RGFX_FEATURE_SURFACE_DEFERRED)
|
||||
}
|
||||
@@ -2537,9 +2510,6 @@ fn the_driver_takes_private_render_state_where_offered() {
|
||||
struct Private;
|
||||
impl Host for Private {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn features(&self) -> u64 {
|
||||
u64::from(RGFX_FEATURE_PRIVATE_RENDER_STATE)
|
||||
}
|
||||
@@ -2563,9 +2533,6 @@ fn the_driver_takes_opencl_mode_where_offered() {
|
||||
struct OpenCl;
|
||||
impl Host for OpenCl {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn features(&self) -> u64 {
|
||||
u64::from(RGFX_FEATURE_OPENCL_MODE)
|
||||
}
|
||||
@@ -2589,9 +2556,6 @@ fn the_host_time_reads_the_vblank_clock_once_taken() {
|
||||
struct Clock;
|
||||
impl Host for Clock {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn features(&self) -> u64 {
|
||||
u64::from(RGFX_FEATURE_HOST_TIME)
|
||||
}
|
||||
@@ -2639,9 +2603,6 @@ fn surface_pages_hand_the_host_their_runs() {
|
||||
struct Pages(Seen);
|
||||
impl Host for Pages {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn features(&self) -> u64 {
|
||||
u64::from(RGFX_FEATURE_SURFACE_PAGES) | (1 << 40)
|
||||
}
|
||||
@@ -2843,9 +2804,6 @@ impl Host for TakingHost {
|
||||
fn raise_interrupt(&self, vector: u32) {
|
||||
self.0.raised.lock().push((vector, thread_name()));
|
||||
}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn stage3_message(&self, completion: &CompletionPoster, message: &[u8]) {
|
||||
let (header, _) = RgfxMsgHeader::read_from_prefix(message).unwrap();
|
||||
self.0.handed.lock().push(header.r#type);
|
||||
@@ -3445,9 +3403,6 @@ impl OrderHost {
|
||||
|
||||
impl Host for OrderHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn context_closed(&self, _context: u32, answer: CompleteAnswer) {
|
||||
self.record(RGFX_CMD_CONTEXT_CLOSE);
|
||||
answer.answer(RGFX_STATUS_OK);
|
||||
|
||||
@@ -76,9 +76,6 @@ impl FuzzHost {
|
||||
|
||||
impl Host for FuzzHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn context_closed(&self, context: u32, answer: CompleteAnswer) {
|
||||
self.carry_out(answer.seqno, |seen| {
|
||||
for textures in seen.named.values_mut() {
|
||||
|
||||
@@ -67,9 +67,6 @@ impl Host for PeerHost {
|
||||
self.raised.vectors.lock().push_back(vector);
|
||||
self.raised.moved.notify_all();
|
||||
}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn features(&self) -> u64 {
|
||||
self.features
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ struct AnswerHost;
|
||||
|
||||
impl Host for AnswerHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn stage3_message(&self, completion: &CompletionPoster, message: &[u8]) {
|
||||
let (header, _) = RgfxMsgHeader::read_from_prefix(message).unwrap();
|
||||
if header.r#type == RGFX_CMD_RENDER_PIPELINE_CREATE {
|
||||
@@ -174,9 +171,6 @@ struct HoldingHost {
|
||||
|
||||
impl Host for HoldingHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn stage3_message(&self, completion: &CompletionPoster, message: &[u8]) {
|
||||
let (header, _) = RgfxMsgHeader::read_from_prefix(message).unwrap();
|
||||
match header.r#type {
|
||||
|
||||
@@ -53,9 +53,6 @@ impl GateHost {
|
||||
|
||||
impl Host for GateHost {
|
||||
fn raise_interrupt(&self, _vector: u32) {}
|
||||
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn stage3_message(&self, _completion: &CompletionPoster, message: &[u8]) {
|
||||
let (header, _) = RgfxMsgHeader::read_from_prefix(message).unwrap();
|
||||
let mut gated = self.0.state.lock();
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
//!
|
||||
//! **Scanout.** `SET_SCANOUT` names the pixels the display shows, in the scanout's room of the
|
||||
//! region (`RGFX_SCANOUT_SPAN` bytes at `RGFX_ALLOCATIONS_OFFSET`, before the processes' blocks,
|
||||
//! so the display never shows a process's memory); the screen reads them in place. It shows them again at a refresh of its host screen only where the guest wrote
|
||||
//! them since ([`Screen::present`], which `refresh` calls on the host's dirty log). A reset of the
|
||||
//! device keeps the scanout (`device`'s module doc); only `SET_SCANOUT` changes it.
|
||||
//! so the display never shows a process's memory); the screen reads them in place. It shows them
|
||||
//! again at each refresh while the guest has a scanout ([`Screen::present`], which `refresh`
|
||||
//! calls), as the guest may have written them since. A reset of the device keeps the scanout
|
||||
//! (`device`'s module doc); only `SET_SCANOUT` changes it.
|
||||
//!
|
||||
//! **Cursor.** `SET_CURSOR` copies the guest's image, premultiplied BGRA8, out of the region,
|
||||
//! and hands the screen straight-alpha RGBA ([`straight_rgba`]); `MOVE_CURSOR` tells it where the
|
||||
@@ -85,12 +86,13 @@ pub trait Screen: Send + Sync + 'static {
|
||||
fn mode(&self) -> Mode;
|
||||
|
||||
/// The guest set the pixels the display shows, or blanked it (`None`). The screen shows
|
||||
/// them at once, and then at a refresh where the guest wrote them ([`Screen::present`]),
|
||||
/// across the device's resets, until the guest sets others.
|
||||
/// them at once, and then at each refresh ([`Screen::present`]), across the device's resets,
|
||||
/// until the guest sets others.
|
||||
fn scanout(&self, scanout: Option<Scanout>);
|
||||
|
||||
/// The guest wrote the pixels the display shows since the last refresh: the screen shows
|
||||
/// them again.
|
||||
/// A refresh while the guest has a scanout: the screen shows its pixels again, as the guest
|
||||
/// may have written them since, where it shows the scanout and not something of the host's
|
||||
/// in its place.
|
||||
fn present(&self);
|
||||
|
||||
/// The guest set its cursor image, or removed it (`None`).
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
#define RVG_GRAPHICS_DOORBELL_CONTROL 0
|
||||
|
||||
// Where the guest's allocations start in the region, the scanout among them: below it are the
|
||||
// control rings, which the host's dirty log need not cover.
|
||||
// control rings.
|
||||
#define RVG_GRAPHICS_ALLOCATIONS_OFFSET 4194304
|
||||
|
||||
// The graphics device.
|
||||
@@ -178,19 +178,6 @@ typedef void (*RvgDestroyFn)(void *ctx);
|
||||
// guest gets no interrupt.
|
||||
typedef void (*RvgGraphicsRaiseFn)(void *ctx, uint32_t vector);
|
||||
|
||||
// `scanout_written(ctx, offset, length)`: whether the guest wrote any of the `length` bytes at
|
||||
// `offset` in the region since the last call, which starts the next span: the host's dirty log
|
||||
// of the guest's writes to that range, taken and cleared (QEMU: memory_region_set_log on the
|
||||
// region, and memory_region_snapshot_and_clear_dirty). The range lies at or past
|
||||
// RVG_GRAPHICS_ALLOCATIONS_OFFSET. The display shows the scanout again only where it answers
|
||||
// true.
|
||||
//
|
||||
// Thread: the device's refresh thread (`reims-vgpu.graphics-refresh`), at each refresh of the
|
||||
// display, never inside a call of the host's into the library, and with no lock of the
|
||||
// library's held: it may wait for a lock the host holds while it calls the device (QEMU's BQL).
|
||||
// May call: as raise_interrupt. Without it, every refresh shows the scanout again.
|
||||
typedef bool (*RvgGraphicsScanoutWrittenFn)(void *ctx, uint64_t offset, uint64_t length);
|
||||
|
||||
// A position or size in pixels.
|
||||
typedef struct {
|
||||
uint16_t x;
|
||||
@@ -247,7 +234,6 @@ typedef struct {
|
||||
// one of them, after rvg_graphics_device_release has returned.
|
||||
RvgDestroyFn destroy;
|
||||
RvgGraphicsRaiseFn raise_interrupt;
|
||||
RvgGraphicsScanoutWrittenFn scanout_written;
|
||||
// The guest set its cursor's image: `rgba` holds its pixels as straight-alpha RGBA (the
|
||||
// guest gives them premultiplied, BGRA), each side 1 to 256 pixels, the hot spot inside.
|
||||
// Followed by `cursor_show` where whether the cursor shows changed.
|
||||
@@ -406,8 +392,8 @@ typedef struct {
|
||||
// sized for its mode (1920 x 1080 where it has none). The window keeps its size: the
|
||||
// display offers the guest one mode, the window's size in pixels at the refresh rate of the
|
||||
// host screen it opens on, and tells the guest when the person resizes it. The guest's
|
||||
// scanout is blitted out of the region into the window's drawables on the GPU, at the
|
||||
// screen's rate, where scanout_written says the guest wrote it.
|
||||
// scanout is blitted out of the region into the window's drawables on the GPU at each of the
|
||||
// display's refreshes, at the screen's rate, while the display shows no presented surface.
|
||||
const RvgWindowConfig *window;
|
||||
// The guest's RAM, or NULL. With it, where the host's page is the guest's 4 KiB, the GPU uses
|
||||
// an IOSurface's own pages in place, through views of them; without it each surface's GPU
|
||||
|
||||
@@ -103,7 +103,6 @@ fn a_panic_in_a_callback_of_the_first_export_ends_in_the_hook() {
|
||||
ctx: std::ptr::null_mut(),
|
||||
destroy: Some(panicking_destroy),
|
||||
raise_interrupt: None,
|
||||
scanout_written: None,
|
||||
cursor_glyph: None,
|
||||
cursor_show: None,
|
||||
cursor_move: None,
|
||||
|
||||
@@ -28,8 +28,6 @@ fn ns_exception() -> Retained<AnyObject> {
|
||||
fn a_host_raise_is_fatal_at_the_call() {
|
||||
let d = catch_death(|| host_call("raise_interrupt", || throw(ns_exception())));
|
||||
assert_eq!(d.unwrap_err(), host_raised("raise_interrupt"));
|
||||
let d = catch_death(|| host_call("scanout_written", || throw(ns_exception())));
|
||||
assert_eq!(d.unwrap_err(), host_raised("scanout_written"));
|
||||
let d = catch_death(|| host_call("cursor_move", || throw(NSObject::new().into_super())));
|
||||
assert_eq!(d.unwrap_err(), host_raised("cursor_move"));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ pub const RVG_GRAPHICS_REG_DOORBELL: u32 = 0x020;
|
||||
pub const RVG_GRAPHICS_DOORBELL_CONTROL: u32 = 0;
|
||||
|
||||
/// Where the guest's allocations start in the region, the scanout among them: below it are the
|
||||
/// control rings, which the host's dirty log need not cover.
|
||||
/// control rings.
|
||||
pub const RVG_GRAPHICS_ALLOCATIONS_OFFSET: u64 = 0x40_0000;
|
||||
|
||||
const _: () = {
|
||||
@@ -102,20 +102,6 @@ const _: () = {
|
||||
/// guest gets no interrupt.
|
||||
pub type RvgGraphicsRaiseFn = Option<unsafe extern "C-unwind" fn(ctx: *mut c_void, vector: u32)>;
|
||||
|
||||
/// `scanout_written(ctx, offset, length)`: whether the guest wrote any of the `length` bytes at
|
||||
/// `offset` in the region since the last call, which starts the next span: the host's dirty log
|
||||
/// of the guest's writes to that range, taken and cleared (QEMU: memory_region_set_log on the
|
||||
/// region, and memory_region_snapshot_and_clear_dirty). The range lies at or past
|
||||
/// RVG_GRAPHICS_ALLOCATIONS_OFFSET. The display shows the scanout again only where it answers
|
||||
/// true.
|
||||
///
|
||||
/// Thread: the device's refresh thread (`reims-vgpu.graphics-refresh`), at each refresh of the
|
||||
/// display, never inside a call of the host's into the library, and with no lock of the
|
||||
/// library's held: it may wait for a lock the host holds while it calls the device (QEMU's BQL).
|
||||
/// May call: as raise_interrupt. Without it, every refresh shows the scanout again.
|
||||
pub type RvgGraphicsScanoutWrittenFn =
|
||||
Option<unsafe extern "C-unwind" fn(ctx: *mut c_void, offset: u64, length: u64) -> bool>;
|
||||
|
||||
/// The graphics device's callbacks.
|
||||
///
|
||||
/// The cursor's three tell the host the guest's cursor on the device's display, for a host that
|
||||
@@ -138,7 +124,6 @@ pub struct RvgGraphicsCallbacks {
|
||||
/// one of them, after rvg_graphics_device_release has returned.
|
||||
pub destroy: RvgDestroyFn,
|
||||
pub raise_interrupt: RvgGraphicsRaiseFn,
|
||||
pub scanout_written: RvgGraphicsScanoutWrittenFn,
|
||||
/// The guest set its cursor's image: `rgba` holds its pixels as straight-alpha RGBA (the
|
||||
/// guest gives them premultiplied, BGRA), each side 1 to 256 pixels, the hot spot inside.
|
||||
/// Followed by `cursor_show` where whether the cursor shows changed.
|
||||
@@ -168,8 +153,8 @@ pub struct RvgGraphicsDeviceConfig {
|
||||
/// sized for its mode (1920 x 1080 where it has none). The window keeps its size: the
|
||||
/// display offers the guest one mode, the window's size in pixels at the refresh rate of the
|
||||
/// host screen it opens on, and tells the guest when the person resizes it. The guest's
|
||||
/// scanout is blitted out of the region into the window's drawables on the GPU, at the
|
||||
/// screen's rate, where scanout_written says the guest wrote it.
|
||||
/// scanout is blitted out of the region into the window's drawables on the GPU at each of the
|
||||
/// display's refreshes, at the screen's rate, while the display shows no presented surface.
|
||||
pub window: *const RvgWindowConfig,
|
||||
/// The guest's RAM, or NULL. With it, where the host's page is the guest's 4 KiB, the GPU uses
|
||||
/// an IOSurface's own pages in place, through views of them; without it each surface's GPU
|
||||
@@ -293,18 +278,9 @@ unsafe fn create(
|
||||
});
|
||||
raise
|
||||
});
|
||||
let scanout_written = callbacks.scanout_written.map(|f| {
|
||||
let t = table.clone();
|
||||
let written: reims_vgpu::ScanoutWrittenFn = Arc::new(move |offset, length| {
|
||||
// SAFETY: the host's function over its ctx.
|
||||
ffi::host_call("scanout_written", || unsafe { f(t.ctx(), offset, length) })
|
||||
});
|
||||
written
|
||||
});
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt,
|
||||
scanout_written,
|
||||
cursor_glyph: cursor_glyph(&table, callbacks.cursor_glyph),
|
||||
cursor_show: cursor_show(&table, callbacks.cursor_show),
|
||||
cursor_move: cursor_move(&table, callbacks.cursor_move),
|
||||
|
||||
@@ -17,7 +17,6 @@ fn callbacks() -> RvgGraphicsCallbacks {
|
||||
ctx: std::ptr::null_mut(),
|
||||
destroy: Some(destroy),
|
||||
raise_interrupt: Some(raise),
|
||||
scanout_written: None,
|
||||
cursor_glyph: None,
|
||||
cursor_show: None,
|
||||
cursor_move: None,
|
||||
|
||||
@@ -78,13 +78,6 @@ static void on_graphics_raise(void *ctx, uint32_t vector) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool on_graphics_scanout_written(void *ctx, uint64_t offset, uint64_t length) {
|
||||
(void)ctx;
|
||||
(void)offset;
|
||||
(void)length;
|
||||
return true;
|
||||
}
|
||||
|
||||
static _Atomic int graphics_moved;
|
||||
|
||||
static void on_graphics_cursor_move(void *ctx) {
|
||||
@@ -101,7 +94,6 @@ static void check_graphics(void) {
|
||||
&graphics_destroyed,
|
||||
on_graphics_destroy,
|
||||
on_graphics_raise,
|
||||
on_graphics_scanout_written,
|
||||
NULL,
|
||||
NULL,
|
||||
on_graphics_cursor_move};
|
||||
|
||||
@@ -244,6 +244,8 @@ pub struct Window {
|
||||
open_posted: AtomicBool,
|
||||
/// A cursor refresh is posted to the UI thread and has not run yet.
|
||||
cursor_posted: AtomicBool,
|
||||
/// How many frames the window was asked to draw ([`Window::new_frame`]).
|
||||
frames_asked: AtomicU64,
|
||||
/// What the render thread draws with.
|
||||
surface: Surface,
|
||||
/// What it posts to the UI thread.
|
||||
@@ -291,6 +293,7 @@ impl Window {
|
||||
attached: AtomicBool::new(false),
|
||||
open_posted: AtomicBool::new(false),
|
||||
cursor_posted: AtomicBool::new(false),
|
||||
frames_asked: AtomicU64::new(0),
|
||||
surface: Surface::new(),
|
||||
posts,
|
||||
})
|
||||
@@ -340,9 +343,16 @@ impl Window {
|
||||
|
||||
/// The guest presented a frame: the window draws it.
|
||||
pub fn new_frame(&self) {
|
||||
self.frames_asked.fetch_add(1, Ordering::Relaxed);
|
||||
self.surface.request_draw();
|
||||
}
|
||||
|
||||
/// How many frames the window was asked to draw ([`Window::new_frame`]) since it was made,
|
||||
/// whether it drew each or took several in one draw.
|
||||
pub fn frames_asked(&self) -> u64 {
|
||||
self.frames_asked.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// The display offers the guest `width` by `height` first: the window opens sized for it
|
||||
/// until the guest sets a mode. It sizes a window that has opened already for nothing.
|
||||
pub fn offered_mode(&self, width: u16, height: u16) {
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
//! its render thread last drew into it, rounded down to even (a window of odd pixels shows the
|
||||
//! guest's mode unscaled, beside a column or row of black), at the refresh rate of the host screen
|
||||
//! it opened on; when that size changes (the person resized the window) the device tells the guest
|
||||
//! (`DISPLAY_CHANGED`). The guest's scanout shows in the window at once and then whenever the
|
||||
//! host's dirty log says the guest wrote it, at the screen's rate; the window draws it at the
|
||||
//! screen's pace. The guest's cursor image is the host's cursor over the image, shown while the
|
||||
//! guest shows its cursor; the guest's cursor position moves nothing, since the host's pointer
|
||||
//! moves the guest's (the window never draws the cursor into the image itself).
|
||||
//! (`DISPLAY_CHANGED`). The guest's scanout shows in the window at once and then again at each of
|
||||
//! the display's refreshes, at the screen's rate, while no presented surface shows in its place;
|
||||
//! the window draws it at the screen's pace. While a surface shows, a refresh draws nothing: the
|
||||
//! guest's presents draw it ([`Presented`]). The guest's cursor image is the host's cursor over
|
||||
//! the image, shown while the guest shows its cursor; the guest's cursor position moves nothing,
|
||||
//! since the host's pointer moves the guest's (the window never draws the cursor into the image
|
||||
//! itself).
|
||||
//!
|
||||
//! **Without a window** the display offers 1920 × 1080 at 60 Hz and shows nothing.
|
||||
//!
|
||||
@@ -136,13 +138,9 @@ pub use decode::{GraphicsVideo, GraphicsVideoSession, PlanePages, VideoDecode, V
|
||||
|
||||
/// Raises MSI-X vector `vector`: the device's interrupt.
|
||||
pub type GraphicsRaiseFn = Arc<dyn Fn(u32) + Send + Sync>;
|
||||
/// Whether the guest wrote any of the `length` bytes at `offset` in the region since the last
|
||||
/// ask: the host's dirty log over the scanout, taken and cleared.
|
||||
pub type ScanoutWrittenFn = Arc<dyn Fn(u64, u64) -> bool + Send + Sync>;
|
||||
|
||||
/// A graphics device's callbacks. `scanout_written` is called on the device's refresh thread
|
||||
/// (`reims-vgpu.graphics-refresh`), and `raise_interrupt` on the thread that posts the event it
|
||||
/// raises for: the device's control thread (`reims-vgpu.graphics-control`), one of ring 0's
|
||||
/// A graphics device's callbacks. `raise_interrupt` is called on the thread that posts the event
|
||||
/// it raises for: the device's control thread (`reims-vgpu.graphics-control`), one of ring 0's
|
||||
/// threads (`reims-vgpu.graphics-ring0-<i>`), which carry out a guest process's control messages,
|
||||
/// its presents and a block's pages and downloads, each on its lane, its refresh thread, a command
|
||||
/// queue's service thread (`reims-vgpu.graphics-queue-<id>`) or one of its lane's threads
|
||||
@@ -152,11 +150,10 @@ pub type ScanoutWrittenFn = Arc<dyn Fn(u64, u64) -> bool + Send + Sync>;
|
||||
/// a closed process's objects and answers its close (`reims-vgpu.graphics-closes-<i>`), or the
|
||||
/// platform's thread that runs a command buffer's scheduled or completed handler; or the host's
|
||||
/// own, inside [`GraphicsDevice::mmio_write_taking`].
|
||||
/// Each is called never inside another call of the host's into the device, and with no lock held
|
||||
/// It is called never inside another call of the host's into the device, and with no lock held
|
||||
/// that a function of the device's waits for, directly or through a thread of the library's, so
|
||||
/// they may call it at once. `scanout_written` runs with no lock of the library's held.
|
||||
/// `raise_interrupt` may run under these: a command queue's claim on its next message, on the
|
||||
/// queue's service thread and inside `mmio_write_taking`; there, at a command buffer's
|
||||
/// it may call it at once. It may run under these: a command queue's claim on its next message,
|
||||
/// on the queue's service thread and inside `mmio_write_taking`; there, at a command buffer's
|
||||
/// `CB_SUBMITTED` answered on the calling thread, the decoder's contexts' lock, the buffer's
|
||||
/// context's table read, its queue's answer slot and the reset gate read; the device caches'
|
||||
/// lock, with the download's answer slot, at a `SURFACE_DOWNLOAD` answered at once; a command
|
||||
@@ -173,9 +170,6 @@ pub type ScanoutWrittenFn = Arc<dyn Fn(u64, u64) -> bool + Send + Sync>;
|
||||
pub struct GraphicsCallbacks {
|
||||
/// Raises the device's interrupt. Without it the guest gets no interrupt.
|
||||
pub raise_interrupt: Option<GraphicsRaiseFn>,
|
||||
/// The host's dirty log over the scanout, on the refresh thread. Without it the guest's
|
||||
/// scanout is taken as written at every refresh.
|
||||
pub scanout_written: Option<ScanoutWrittenFn>,
|
||||
/// The guest set its cursor's image: its pixels as straight-alpha RGBA, which the guest
|
||||
/// gave premultiplied BGRA (`reims-graphics`' `display`), and its hot spot.
|
||||
pub cursor_glyph: Option<CursorGlyphFn>,
|
||||
@@ -909,6 +903,11 @@ impl<P: Platform> Presented<P> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the display shows a presented surface's texture in place of the scanout.
|
||||
fn shows_surface(&self) -> bool {
|
||||
self.texture.lock().is_some()
|
||||
}
|
||||
|
||||
/// The texture shown, and the hold of its block, for a window draw of it; `None` for the
|
||||
/// scanout.
|
||||
pub(crate) fn shown(&self) -> Option<(P::Texture, Arc<DisplayHold>)> {
|
||||
@@ -2111,7 +2110,7 @@ impl<P: ApiPlatform> GraphicsControl<P> {
|
||||
|
||||
/// The host's callbacks and its stage-3 decoder as the device's [`Host`].
|
||||
struct CallbackHost<P: ApiPlatform> {
|
||||
/// The host's interrupt and dirty-log callbacks.
|
||||
/// The host's callbacks: the device raises its interrupt through them.
|
||||
callbacks: GraphicsCallbacks,
|
||||
/// The `RGFX_FEATURE_*` the decoder carries out, fixed at the device's make: the guest reads
|
||||
/// them on a vCPU, which takes no lock of the decoder's.
|
||||
@@ -2130,13 +2129,6 @@ impl<P: ApiPlatform> Host for CallbackHost<P> {
|
||||
}
|
||||
}
|
||||
|
||||
fn scanout_written(&self, offset: u64, length: u64) -> bool {
|
||||
self.callbacks
|
||||
.scanout_written
|
||||
.as_ref()
|
||||
.is_none_or(|f| f(offset, length))
|
||||
}
|
||||
|
||||
fn present_surface(&self, iosurface_id: u32, generation: Option<u64>, answer: PresentAnswer) {
|
||||
self.control
|
||||
.present_surface(iosurface_id, generation, answer);
|
||||
@@ -2295,6 +2287,8 @@ pub(crate) struct WindowScreen {
|
||||
window: Arc<Window>,
|
||||
/// What it shows.
|
||||
shown: Arc<Shown>,
|
||||
/// Whether it shows a presented surface in place of the scanout ([`Presented`]).
|
||||
shows_surface: Box<dyn Fn() -> bool + Send + Sync>,
|
||||
/// The refresh rate of the host screen it opened on, in thousandths of a hertz.
|
||||
refresh_mhz: u32,
|
||||
/// The guest's cursor, as last told.
|
||||
@@ -2515,9 +2509,11 @@ impl WindowScreen {
|
||||
// Presents wait for the window's draw only where it has a sink to draw them.
|
||||
let _ = presented.window.set(Arc::clone(&window));
|
||||
}
|
||||
let presented = Arc::clone(presented);
|
||||
let screen = WindowScreen {
|
||||
window: Arc::clone(&window),
|
||||
shown,
|
||||
shows_surface: Box::new(move || presented.shows_surface()),
|
||||
refresh_mhz,
|
||||
cursor: Mutex::new(CursorState {
|
||||
image: false,
|
||||
@@ -2626,8 +2622,12 @@ impl Screen for WindowScreen {
|
||||
self.window.new_frame();
|
||||
}
|
||||
|
||||
/// The window draws the scanout again where it shows it; while it shows a presented surface,
|
||||
/// a refresh draws nothing, and the guest's presents draw it ([`Presented`]).
|
||||
fn present(&self) {
|
||||
self.window.new_frame();
|
||||
if !(self.shows_surface)() {
|
||||
self.window.new_frame();
|
||||
}
|
||||
}
|
||||
|
||||
/// The host's cursor over the image takes the guest's image; with none, nothing shows
|
||||
|
||||
@@ -22,7 +22,6 @@ fn headless(raised: &Arc<AtomicU32>) -> GraphicsDevice<FakePlatform> {
|
||||
assert_eq!(vector, 0);
|
||||
raised.fetch_add(1, Ordering::SeqCst);
|
||||
})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -108,7 +107,6 @@ fn headless_on(raised: &Arc<AtomicU32>) -> (GraphicsDevice<FakePlatform>, Arc<Fa
|
||||
assert_eq!(vector, 0);
|
||||
raised.fetch_add(1, Ordering::SeqCst);
|
||||
})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -160,7 +158,6 @@ fn on_metal_guest_texture_ids_are_kept_from_the_host_s() {
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: None,
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -970,7 +967,6 @@ fn a_per_queue_ring_decodes_and_completes_a_command_buffer() {
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: Some(Arc::new(move |vector| vrec.lock().push(vector))),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -1054,7 +1050,6 @@ fn an_out_of_line_command_buffer_is_carried_out_from_one_copy() {
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: None,
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -1145,7 +1140,6 @@ fn a_doorbell_write_answers_a_command_buffer_on_its_thread() {
|
||||
let name = std::thread::current().name().map(str::to_owned);
|
||||
record.lock().push((vector, name));
|
||||
})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -1244,7 +1238,6 @@ fn a_doorbell_s_answer_allocates_nothing() {
|
||||
raise_interrupt: Some(Arc::new(move |_| {
|
||||
count.fetch_add(1, Ordering::SeqCst);
|
||||
})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -1366,7 +1359,6 @@ fn a_landed_download_s_answer_at_its_doorbell_allocates_nothing() {
|
||||
count.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -1445,7 +1437,6 @@ fn a_lone_buffer_s_doorbell_to_its_cb_submitted() {
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: Some(Arc::new(|_| {})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -1820,7 +1811,6 @@ fn calling_back(ring: u64) -> (Arc<GraphicsDevice<FakePlatform>>, Returned) {
|
||||
let name = std::thread::current().name().map(str::to_owned);
|
||||
record.lock().push(name);
|
||||
})),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -2120,24 +2110,13 @@ fn the_sink_imports_only_the_scanout_s_pages() {
|
||||
assert_eq!(platform.call_log().count(IMPORT), 3);
|
||||
}
|
||||
|
||||
/// The regions the host's dirty log was asked about, in order.
|
||||
type Asked = Arc<Mutex<Vec<(u64, u64)>>>;
|
||||
|
||||
/// A graphics device on the testkit's platform with a display window, whose dirty log answers
|
||||
/// every ask written, recording it in `asked`. The platform draws no sink, so the window never
|
||||
/// opens: the test draws what it shows through a sink of its own ([`windowed_draw`]).
|
||||
fn windowed(asked: &Asked) -> (GraphicsDevice<FakePlatform>, Arc<FakePlatform>) {
|
||||
/// A graphics device on the testkit's platform with a display window. The platform draws no
|
||||
/// sink, so the window never opens: the test draws what it shows through a sink of its own
|
||||
/// ([`windowed_draw`]), and counts the frames it is asked for ([`frames_asked`]).
|
||||
fn windowed() -> (GraphicsDevice<FakePlatform>, Arc<FakePlatform>) {
|
||||
let platform = Arc::new(FakePlatform::new());
|
||||
let asked = Arc::clone(asked);
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: None,
|
||||
scanout_written: Some(Arc::new(move |offset, length| {
|
||||
asked.lock().push((offset, length));
|
||||
true
|
||||
})),
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
callbacks: GraphicsCallbacks::default(),
|
||||
window: Some(WindowConfig::default()),
|
||||
memory_map: None,
|
||||
};
|
||||
@@ -2210,27 +2189,30 @@ fn draws_the_scanout(
|
||||
blit.args[1..3] == [Arg::U64(0), Arg::U64(stride)]
|
||||
}
|
||||
|
||||
/// Waits about 2 s for the refresh thread to ask the host's dirty log about `range`.
|
||||
fn asked_about(asked: &Asked, range: (u64, u64)) -> bool {
|
||||
for _ in 0..2000 {
|
||||
if asked.lock().contains(&range) {
|
||||
return true;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
false
|
||||
/// The frames `device`'s window was asked to draw so far.
|
||||
fn frames_asked(device: &GraphicsDevice<FakePlatform>) -> u64 {
|
||||
device
|
||||
.window
|
||||
.as_ref()
|
||||
.expect("a window")
|
||||
.window()
|
||||
.frames_asked()
|
||||
}
|
||||
|
||||
/// Waits ([`eventually`]) for `device`'s window to be asked for `count` frames past `from`.
|
||||
fn frames_asked_past(device: &GraphicsDevice<FakePlatform>, from: u64, count: u64) -> bool {
|
||||
eventually(|| frames_asked(device) >= from + count)
|
||||
}
|
||||
|
||||
/// The guest's driver fails after it took the device, as the kext does where the device lists no
|
||||
/// usable display or `IOFramebuffer`'s start fails: the firmware sets its scanout, the kext resets
|
||||
/// the device to take it, starts it and asks `GET_DISPLAYS`, and resets it on the way out. The
|
||||
/// window keeps the firmware's scanout, so the frames the OS then draws into the firmware's
|
||||
/// framebuffer reach it: the refresh thread asks the host's dirty log over that scanout again,
|
||||
/// showing it where the guest wrote it, and the window's draw blits it out of the region
|
||||
/// framebuffer reach it: each refresh asks the window to draw that scanout again, and the
|
||||
/// window's draw blits it out of the region
|
||||
#[test]
|
||||
fn a_failure_after_the_take_keeps_the_firmware_s_scanout_in_the_window() {
|
||||
let asked = Asked::default();
|
||||
let (device, platform) = windowed(&asked);
|
||||
let (device, platform) = windowed();
|
||||
let (draw, drawable) = windowed_draw(&device, &platform, 64, 32);
|
||||
let scanout = Scanout {
|
||||
width: 64,
|
||||
@@ -2287,7 +2269,7 @@ fn a_failure_after_the_take_keeps_the_firmware_s_scanout_in_the_window() {
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
|
||||
// The OS draws its next frame into the firmware's framebuffer.
|
||||
asked.lock().clear();
|
||||
let frames = frames_asked(&device);
|
||||
// SAFETY: the scanout lies in the device's region, mapped while the device lives.
|
||||
unsafe {
|
||||
std::ptr::write_bytes(
|
||||
@@ -2297,8 +2279,8 @@ fn a_failure_after_the_take_keeps_the_firmware_s_scanout_in_the_window() {
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
asked_about(&asked, (scanout.offset, scanout.span())),
|
||||
"no refresh asked about the firmware's scanout after the failure"
|
||||
frames_asked_past(&device, frames, 2),
|
||||
"no refresh drew the firmware's scanout after the failure"
|
||||
);
|
||||
let shown = device.shown.as_ref().unwrap();
|
||||
assert_eq!(*shown.scanout.lock(), Some(scanout));
|
||||
@@ -2314,8 +2296,7 @@ fn a_failure_after_the_take_keeps_the_firmware_s_scanout_in_the_window() {
|
||||
/// its surface
|
||||
#[test]
|
||||
fn a_reset_shows_the_scanout_in_place_of_the_surface_shown() {
|
||||
let asked = Asked::default();
|
||||
let (device, platform) = windowed(&asked);
|
||||
let (device, platform) = windowed();
|
||||
let (draw, drawable) = windowed_draw(&device, &platform, 64, 32);
|
||||
let (mut guest, _ring) = surface_and_queue(&device);
|
||||
let scanout = RgfxSetScanout {
|
||||
@@ -2363,6 +2344,70 @@ fn a_reset_shows_the_scanout_in_place_of_the_surface_shown() {
|
||||
assert_eq!(shown_width(&device), Some(64));
|
||||
}
|
||||
|
||||
/// While the window shows the guest's scanout, each refresh asks it to draw the scanout again,
|
||||
/// as the guest may have written it since; before the guest sets one, a refresh asks for nothing
|
||||
#[test]
|
||||
fn a_refresh_draws_the_scanout_again_while_no_surface_shows() {
|
||||
let (device, _platform) = windowed();
|
||||
device.mmio_write(RGFX_REG_STATUS.into(), RGFX_STATUS_DRIVER_READY);
|
||||
let mut guest = Guest::new(&device);
|
||||
// Six refreshes at the window's 60 Hz.
|
||||
let frames = frames_asked(&device);
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
assert_eq!(
|
||||
frames_asked(&device),
|
||||
frames,
|
||||
"a refresh with no scanout asked for a frame"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(64, 32, 256)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let frames = frames_asked(&device);
|
||||
assert!(
|
||||
frames_asked_past(&device, frames, 3),
|
||||
"the refreshes drew the scanout {} times",
|
||||
frames_asked(&device) - frames
|
||||
);
|
||||
}
|
||||
|
||||
/// While the window shows a presented surface, a refresh asks it for no frame: the guest's
|
||||
/// presents alone draw it. Once the guest presents the scanout again, each refresh draws it
|
||||
#[test]
|
||||
fn a_refresh_draws_nothing_while_a_presented_surface_shows() {
|
||||
let (device, _platform) = windowed();
|
||||
let (mut guest, _ring) = surface_and_queue(&device);
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(64, 32, 256)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
assert!(frames_asked_past(&device, frames_asked(&device), 2));
|
||||
|
||||
// With no window open, the present is answered as it is shown.
|
||||
let status = answered(&device, &mut guest, present_surface(0x77));
|
||||
assert_eq!(status, RGFX_STATUS_OK);
|
||||
assert_eq!(shown_width(&device), Some(64));
|
||||
// Past a refresh that found the scanout shown before the present.
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
let frames = frames_asked(&device);
|
||||
// Six refreshes at the window's 60 Hz.
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
assert_eq!(
|
||||
frames_asked(&device),
|
||||
frames,
|
||||
"a refresh asked for a frame while the surface showed"
|
||||
);
|
||||
|
||||
let status = answered(&device, &mut guest, present_surface(0));
|
||||
assert_eq!(status, RGFX_STATUS_OK);
|
||||
assert_eq!(shown_width(&device), None);
|
||||
assert!(
|
||||
frames_asked_past(&device, frames, 2),
|
||||
"no refresh drew the scanout presented again"
|
||||
);
|
||||
}
|
||||
|
||||
/// The display pipe's present: a surface the decoder holds no texture over is answered invalid
|
||||
/// with nothing shown, and 0 (the scanout) is answered at once on a device with no window
|
||||
#[test]
|
||||
@@ -9312,7 +9357,6 @@ fn on_metal_an_identity_colour_matrix_reads_as_no_colour() {
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: None,
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -9508,7 +9552,6 @@ fn on_metal_a_read_of_the_display_gives_the_scanout_s_pixels() {
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: None,
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
@@ -9826,7 +9869,6 @@ fn one_queue_raising(
|
||||
let config = GraphicsConfig {
|
||||
callbacks: GraphicsCallbacks {
|
||||
raise_interrupt: Some(raise),
|
||||
scanout_written: None,
|
||||
..GraphicsCallbacks::default()
|
||||
},
|
||||
window: None,
|
||||
|
||||
@@ -41,7 +41,7 @@ pub use cursor::{CursorGlyph, CursorGlyphFn, CursorMoveFn, CursorShowFn};
|
||||
pub use error::Error;
|
||||
pub use graphics::{
|
||||
GraphicsCallbacks, GraphicsConfig, GraphicsDevice, GraphicsRaiseFn, GraphicsVideo,
|
||||
GraphicsVideoSession, PlanePages, ScanoutWrittenFn, VideoDecode, VideoPlane,
|
||||
GraphicsVideoSession, PlanePages, VideoDecode, VideoPlane,
|
||||
};
|
||||
pub use memory::{MemoryFile, MemoryMap};
|
||||
pub use platform::ApiPlatform;
|
||||
|
||||
@@ -17,6 +17,12 @@ impl WindowLink {
|
||||
pub(crate) fn new(window: Arc<Window>) -> WindowLink {
|
||||
WindowLink { window }
|
||||
}
|
||||
|
||||
/// The window, for the tests' look at it.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn window(&self) -> &Window {
|
||||
&self.window
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WindowLink {
|
||||
|
||||
+3
-4
@@ -104,7 +104,7 @@ refusal logs a line saying which, and no file is duplicated until every entry ha
|
||||
|
||||
| inside | may call |
|
||||
|---|---|
|
||||
| `raise_interrupt`, `scanout_written` | `rvg_status_message` and the `rvg_graphics_device_*` functions, except the release of its own device |
|
||||
| `raise_interrupt` | `rvg_status_message` and the `rvg_graphics_device_*` functions, except the release of its own device |
|
||||
| `cursor_glyph`, `cursor_show`, `cursor_move` | every function: the library never waits for the display thread |
|
||||
| a window callback (`pointer`, `wheel`, `key`, `close`, `scroll`) | every function; it must not block (section 5) |
|
||||
| a `destroy` | nothing |
|
||||
@@ -212,7 +212,6 @@ returns. The library logs through the `log` crate; a Rust host installs its own
|
||||
| callback | thread | serialized with | order |
|
||||
|---|---|---|---|
|
||||
| `raise_interrupt` | the thread that posts the event it raises for: the device's control thread, `reims-vgpu.graphics-control`; one of ring 0's threads, `reims-vgpu.graphics-ring0-<i>`, which carry out a guest process's control messages, its presents and a block's pages and downloads, each on its lane; its refresh thread, `reims-vgpu.graphics-refresh`; a command queue's service thread, `reims-vgpu.graphics-queue-<id>`, or one of its lane's threads, which walk and commit its command buffers, `reims-vgpu.graphics-lane-<id>`; a pipeline compile's thread, `reims-vgpu.graphics-compile-<n>`; a thread that makes IOSurfaces' and pages blocks' views, `reims-vgpu.graphics-surfaces-<i>`; a thread that makes indirect command buffers, `reims-vgpu.icb-create-<i>`; a thread that lets go of a closed process's objects and answers its close, `reims-vgpu.graphics-closes-<i>`; or the platform's thread that runs a command buffer's scheduled or completed handler; or the host's own, inside `rvg_graphics_device_mmio_write_taking`. Never inside another call of the host's | nothing: they may call at once | each after the completion ring's message it raises for is published |
|
||||
| `scanout_written` | the device's refresh thread, `reims-vgpu.graphics-refresh`, once a refresh while the guest has a scanout; never inside a call of the host's, and with no lock of the library's held | the refreshes: one at a time | the refreshes' |
|
||||
| `cursor_glyph`, `cursor_show`, `cursor_move` | the display thread: one serial worker for the whole process (after 5 s idle it exits, and the next callback starts a new one) | every display callback of the process: one at a time | the order the device's control thread took the guest's cursor commands, and its resets |
|
||||
| a window's `pointer`, `wheel`, `key`, `close`, `scroll` | on macOS the process's main thread, where AppKit runs; on Linux the library's thread `reims-vgpu.ui`; never inside a call of the host's | every window callback of the process: one at a time | the order the events arrived |
|
||||
| `destroy` (each table) | the device's: once its threads have ended, after their last callback, possibly on one of them after the release has returned; the window's: once the release has closed the window, on the releasing thread or, while a window callback runs, the window's thread once it returns; either, on the caller's thread, in a refused create | nothing | once, after every call of its table |
|
||||
@@ -227,8 +226,8 @@ A queue's worker, the display thread among them, has core's `WORKER_STACK`, 512
|
||||
|
||||
The device's callbacks may wait for a lock the host holds while it calls the device (QEMU's BQL):
|
||||
no function of the device waits for its threads, and the library calls them with no lock held that
|
||||
one of its functions waits for, directly or through a thread of the library's. `scanout_written`
|
||||
runs with none of the library's locks held. `raise_interrupt` may run under these:
|
||||
one of its functions waits for, directly or through a thread of the library's. `raise_interrupt`
|
||||
may run under these:
|
||||
- a command queue's claim on its next message, on the queue's service thread and inside
|
||||
`rvg_graphics_device_mmio_write_taking`;
|
||||
- there, at a command buffer's `CB_SUBMITTED` answered on the calling thread, the decoder's
|
||||
|
||||
@@ -494,12 +494,11 @@ API, and its order, is, and the header names the thread each callback arrives on
|
||||
|
||||
### 7.2 Locks around the host's callbacks
|
||||
|
||||
The device calls `raise_interrupt` and `scanout_written` with no lock held that one of its
|
||||
functions waits for, directly or through a thread of the library's, so a host may take its own lock
|
||||
(QEMU's BQL) in either; api.md section 5, "The locks around `raise_interrupt`", lists the locks of
|
||||
the library's it may run under. No `ReentrantMutex` is held across `SerialQueue::sync`: the sync
|
||||
block runs on the caller's thread, so a block that takes a recursive lock its caller holds would
|
||||
re-enter it.
|
||||
The device calls `raise_interrupt` with no lock held that one of its functions waits for, directly
|
||||
or through a thread of the library's, so a host may take its own lock (QEMU's BQL) in it; api.md
|
||||
section 5, "The locks around `raise_interrupt`", lists the locks of the library's it may run under.
|
||||
No `ReentrantMutex` is held across `SerialQueue::sync`: the sync block runs on the caller's thread,
|
||||
so a block that takes a recursive lock its caller holds would re-enter it.
|
||||
|
||||
### 7.3 Threads
|
||||
|
||||
|
||||
@@ -1403,9 +1403,10 @@ stage 2.
|
||||
|
||||
**Display.** The modes offered are the host window's size and its screen's
|
||||
refresh rate (the guest runs at the host screen's rate). The host presents the
|
||||
scanout buffer to the display's window at the host's refresh rate, only when
|
||||
the guest wrote it, which it learns from KVM's dirty log over the scanout range
|
||||
(QEMU's VGA devices do the same). The GPU reads the buffer in place: the host
|
||||
scanout buffer to the display's window at each refresh while the window shows
|
||||
no presented surface, with no dirty log: the scanout shows only at boot and in
|
||||
recovery, where its full cost is paid for the simpler design (owner,
|
||||
2026-11-07). The GPU reads the buffer in place: the host
|
||||
pages under the scanout are imported at its first draw, and again only when
|
||||
the guest moves the scanout or changes its size, so no copy is made on the way
|
||||
to the window, and no other page of the region is pinned for it. While vblank is
|
||||
|
||||
@@ -237,7 +237,6 @@ public:
|
||||
callbacks.struct_size = sizeof(callbacks);
|
||||
callbacks.ctx = this;
|
||||
callbacks.raise_interrupt = &Kext::raise;
|
||||
callbacks.scanout_written = &Kext::scanoutWritten;
|
||||
RvgGraphicsDeviceConfig config = {};
|
||||
config.struct_size = sizeof(config);
|
||||
config.callbacks = &callbacks;
|
||||
@@ -673,8 +672,6 @@ private:
|
||||
k->m_changed.notify_all();
|
||||
}
|
||||
|
||||
static bool scanoutWritten(void *, uint64_t, uint64_t) { return false; }
|
||||
|
||||
void armControl()
|
||||
{
|
||||
store32(ring0Complete() + kArmed, 1);
|
||||
|
||||
Reference in new issue
Block a user