diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c5f1c3ec..b23eece99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,10 @@ hashes are given where a change is easiest to understand by reading the commit. out pale and scrambled) and its tabs are grey again, not red and green. - VPro: the check mark of a checked menu toggle (IRIS GL pop-up menus, such as powerflip's) draws as a check mark, not a black bar twice the box's width. +- VPro: text in X edit fields on a TrueColor desktop (nedit's file dialog, + any Motif text field) no longer loses the columns the text cursor has passed over. +- VPro: buttonfly's button labels draw as letters, not as pale boxes; large + LUMINANCE and INTENSITY textures are no longer stored as four 4-bit channels. - Maximum IMPACT: every other screen row stayed black (PROM menus and monitor, issue 777) in builds since 2026-11-17; both raster engines draw again. - IMPACT (Indigo2 and Octane): texture colour tables diff --git a/Cargo.toml b/Cargo.toml index ac166b7ff..54ef7176d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,12 @@ perfetto = [] # live either way. jit_go_count is load-bearing in tests: several JIT tests # assert on it to prove they compared compiled code, not the interpreter. rexdiag = [] +# VPro texture packing check: records how each upload into board memory +# packed its texels and checks every texture level descriptor against the +# upload that wrote its memory; `vpro status` reports disagreements. A +# diagnostic with a small cost per upload and per texture bind, so off by +# default and independent of `developer`: `lightning,vprodiag` builds. +vprodiag = [] # Stale-code detector: verify, at execution time, that the instruction word an # engine is about to run still matches what memory holds at that VA. # diff --git a/FEATURES.md b/FEATURES.md index 33c1e48a5..da72dd9c4 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -37,6 +37,7 @@ Select with `cargo build --release --features `; add | `r5ksc_triton` | Disabled O2/Triton integrated L2 model; deliberately refuses to compile. | `r5ksc` | | `idle-pause` | Park the CPU in recognized guest idle loops; opt-in. | — | | `tcache` | Keep cache tags/state but use authoritative ppmem RAM for cacheable data. | — | +| `vprodiag` | VPro texture packing check: each texture level is checked against the upload that wrote its memory, reported by `vpro status`. Off by default; small cost per upload. | — | | `cache-ecc` | Cache parity/ECC injection and Cache Error exceptions for SGI IDE diagnostics; adds miss/exception checks. Off by default. | — | | `decode-cache` | Compatibility flag; decoded-instruction caching for the shadow model is unconditional. | — | | `tcache_verify` | Assert transparent-cache/RAM coherence on accesses; very slow. | `tcache` | @@ -1016,6 +1017,7 @@ both the interpreter and jitv2. | `developer_ip7` | CP0 Compare / timer delivery stats and debug prints | | `developerx` | Break into the monitor on IBE/DBE/ADEL/ADES/TLB errors | | `rexdiag` | REX3 per-GO activity bits and dispatch counters. **On by default**; drop with `--no-default-features` to measure their cost | +| `vprodiag` | VPro texture packing check (`vpro status`, "texture packing"): every texture level the guest names is checked against the upload that wrote that memory. Off by default; works with `lightning` | | `gputrace` | REX3 annotated trace (`rex trace`) and replayable bus recording (`rex rec`); GR2, IMPACT, O2 and VPro annotated traces (`gr2 trace`, `mgras trace`, `re trace`, `vpro trace`); O2 engine recording (`re rec`). On with `developer`; opt in for plain and `lightning` builds | | `llstats` | Per-address LL/SC reservation histogram (`ll stats`); lightning-compatible | | `perfetto` | Record Perfetto traces for ui.perfetto.dev: per-thread event rings, a writer thread, host or guest timeline. See [docs/perfetto.md](docs/perfetto.md) | diff --git a/TESTING.md b/TESTING.md index 374c1283e..d2c714681 100644 --- a/TESTING.md +++ b/TESTING.md @@ -88,6 +88,17 @@ in each. Both write to `/shared/results/TAG`; the host-side `test/gltest/glsuite-compare.sh A B` lists every difference between two runs. Running both on the CPU and the GPU raster unit and comparing is how the GPU unit is checked against the reference end to end. + +`test/gltest/texpack.sh` makes the library upload a texture every way glprim +can: each sized internal format and each unsized source format, small (FIFO +image) and 256x256 (DMA), with and without mipmap levels, plus ABGR, 16-bit +sources, a sub-image and `gluBuild2DMipmaps`. On VPro, in a build with +`--features vprodiag`, the board model checks +every texture level the library names against the upload that wrote that +memory, and `vpro status` shows the count and the first disagreements +("texture packing"). A texture packed one way and sampled another can round +trip through `glGetTexImage` unnoticed, so the texture sweep alone does not +catch it; run `texpack.sh` and read `vpro status` after it. The same suite on a real board, from the same binaries, against a guest emulating that board is how the model is checked against hardware; the board's quirks then show up as differences instead of as failures. Cases diff --git a/clanker/INDEX.md b/clanker/INDEX.md index 89b18103c..2a9bf26d3 100644 --- a/clanker/INDEX.md +++ b/clanker/INDEX.md @@ -320,6 +320,8 @@ Odyssey (VPro V6/V8/V10/V12): the Octane2/Fuel/Tezro graphics board. Modelled on | Note | Kind | Title | |---|---|---| | [pattern-shape-0-is-plane-anchored-32x32.md](odyssey/pattern-shape-0-is-plane-anchored-32x32.md) | rule | X pattern quads with shape 0 sample a 32x32 pattern at plane coordinates (MSB first); taken for "no pattern", menu check marks filled solid | +| [x-30-bit-save-under-is-write-code-0x10c.md](odyssey/x-30-bit-save-under-is-write-code-0x10c.md) | rule | the TrueColor save-under reads with packed write code 0x10c (ABGR 2_10_10_10_REV); looked up by low byte it was refused and text under the cursor vanished | +| [luminance-texture-uploads-keep-their-bytes.md](odyssey/luminance-texture-uploads-keep-their-bytes.md) | rule | L8 and LA8 textures uploaded by address (word 4 0x80001000, codes 0x42/0x48) keep their bytes, not 4/4/4/4; buttonfly glyphs drew as boxes. `vpro status` checks every level against the upload that wrote it; run test/gltest/texpack.sh | | [write-pair-names-the-field-packing-not-the-pixel-mode.md](odyssey/write-pair-names-the-field-packing-not-the-pixel-mode.md) | rule | Copies and screen DMA puts pack the destination as word 7's write format/type says (COLOR_INDEX, RGBA/US_4_4_4_4), not as the selected pixel mode, which is often another window's: Icon Catalog scroll garbage and red/green tabs | | [x-index-reads-by-address-return-the-field-byte.md](odyssey/x-index-reads-by-address-return-the-field-byte.md) | rule | The X server saves screen pixels with colour-index DMA reads of board memory by address (word 0 `0x2000`, format byte `0x41`); refusing them left black blocks where Motif text cursors had been. Answer with the field's byte | | [gaps-found-by-the-2026-11-07-sweeps.md](odyssey/gaps-found-by-the-2026-11-07-sweeps.md) | open | Model gaps the full test sweep found on both raster units: CI8 reads return 0, X screen reads over some windows are noise, 10:10:10:2 pbuffers and 12-bit z16 visuals, double-buffered gltest shows only the clear | diff --git a/clanker/odyssey/luminance-texture-uploads-keep-their-bytes.md b/clanker/odyssey/luminance-texture-uploads-keep-their-bytes.md new file mode 100644 index 000000000..dcd1bd56e --- /dev/null +++ b/clanker/odyssey/luminance-texture-uploads-keep-their-bytes.md @@ -0,0 +1,43 @@ +# Luminance and luminance-alpha texture uploads by address keep their bytes + +Status: fixed 2026-11-21 (`dma_fields`); check added (`check_level_packing`, feature `vprodiag`, in `packing.rs`). + +**Symptom.** buttonfly's button labels (a texture font) drew every glyph as +a pale opaque box with the letter faint inside it. glprim's 256x256 +LUMINANCE and INTENSITY textures were stored the same wrong way (found by +the check below, not by eye). + +**What the library sends.** A texture big enough to go by DMA is uploaded +into board memory with no level selected: word 4 `0x80001000` (2-byte +pixel and fields, format byte 0) and word 7 code `0x48` (LUMINANCE_ALPHA +bytes) or `0x42` (LUMINANCE bytes; INTENSITY is sent as luminance). The +draws then name the level as format index 0xb (luminance byte, alpha byte) +or 4 (one byte), `texel_storage`. buttonfly also builds mip levels 1-3 on +the board with `TEX_RECT` draws (`texture_build_level`); those were right. + +**Cause.** With no level selected, `dma_fields` took the field's packing +from `copy::source_codec(2, 0)`: four 4-bit components. A clear texel +(L 0xff, A 0) was stored as 0xfff0 and sampled with alpha 0xf0. + +**Rule.** A DMA upload to board memory by address with 2-byte fields +stores code 0x42 as `FIELD_ONE` and code 0x48 as `FIELD_TWO`. Other codes +keep `source_codec`; the copy path is unchanged (its tests send the same +word 4 for 2-byte id/overlay pairs). An ALPHA source by DMA was not seen +disagreeing; no rule for it. + +**How to find the next one.** Every upload into board memory (DMA, FIFO +image into a scratch surface, board-built mip level) records its surface and +packing; each `TEX_LEVEL` descriptor over that memory is checked against it +once (`Board::check_level_packing`; build with `--features vprodiag`). `vpro status` shows "texture packing: N +levels checked ..., M disagree" and the distinct kinds of disagreement; +`log odyssey on` logs each. Run `test/gltest/texpack.sh` in the guest and +read the status. On 2026-11-21 it covered all 32 sized formats, the six +unsized source formats, both upload paths, mipmaps, ABGR, 16-bit sources, +sub-images and `gluBuild2DMipmaps`: only the luminance case disagreed. +A texture packed one way and sampled another can still round-trip through +`glGetTexImage`, which is why the texture sweep's `texread` missed these. + +Tests: `tests/dma.rs` `a_luminance_alpha_texture_upload_keeps_its_alpha`, +`a_luminance_texture_upload_keeps_its_byte`, +`a_level_is_checked_against_the_upload_that_wrote_it`, +`an_eight_byte_level_over_lanes_is_the_same_packing`. diff --git a/clanker/odyssey/x-30-bit-save-under-is-write-code-0x10c.md b/clanker/odyssey/x-30-bit-save-under-is-write-code-0x10c.md new file mode 100644 index 000000000..ee07266f4 --- /dev/null +++ b/clanker/odyssey/x-30-bit-save-under-is-write-code-0x10c.md @@ -0,0 +1,34 @@ +# The 30-bit visual's save-under reads with write code 0x10c, a packed type + +Status: fixed 2026-11-21 (`DMA_X_PACKED`, `dma_read_layout`). + +**Symptom.** In a Motif text field on the TrueColor desktop (nedit's Save +As name field, any X edit field), characters the text cursor has passed over +lose the columns under it, so `/root/hello` turns into `/root/ŀ:ll:`. +The 8-bit login field (`x-index-reads-by-address-return-the-field-byte.md`) +was fine. + +**What the X server sends** (`vpro trace` + `vpro rec`): the same three +steps as the index case, but the save is word 4 `0x82233062` (front, field +at unit 2, 4-byte fields) and word 7 `0xb301010c`. Its write code +(`write::CODE_MASK`, bits 8:0) is **0x10c**: format 0xc (ABGR), type 8, +ABGR 2_10_10_10_REV, four bytes a pixel. The restore puts the saved words +back with an image header of the same code (`0x0fa1110c`), burst tag 0x12. + +**Cause.** `dma_read_layout` looked the code up by its low byte only +(`image::CODE_MASK`, 0x0c) in `DMA_X_LAYOUTS`, which has the byte codes +0x4c/0x4b/0x49/0x41. No match, the read was refused, and the X server's +buffer kept whatever it held before: in the recording every one of the 19 +restores was the flat background word `0x11c4711c`. + +**Rule.** An X read whose write code has bit 8 set is looked up by the whole +nine-bit code in `DMA_X_PACKED`, laid out as the write table +(`pixel_write.rs`) packs that code. 0x10c and 0x10b (RGBA 10_10_10_2) are +listed; add others when a trace shows them. + +**How it was found.** Decode the restore's burst words straight out of the +`vpro rec` file (`W` records at offset 0x100000 after each `0x4570` +header): a restore that is all one value while the screen under the cursor +held text means the save, not the put, is wrong. + +Test: `tests/dma.rs` `a_30_bit_save_under_returns_abgr_2_10_10_10_rev`. diff --git a/debug.md b/debug.md index bbb7b30d1..0f4b94b22 100644 --- a/debug.md +++ b/debug.md @@ -493,7 +493,7 @@ guest. `y = 0` is the top display line throughout. | Command | Description | |---|---| -| `vpro [status]` | Board summary: identity, interrupts, swap bank, FIFO and raster queue levels, display frames, the scan-out mode and the video timing decoded from the guest's tables and clock part (totals, fields, blank lines, refresh rate), cursor, product and memory, drawing words and the pixel mode, primitive assembly, unmodelled reports | +| `vpro [status]` | Board summary: identity, interrupts, swap bank, FIFO and raster queue levels, display frames, the scan-out mode and the video timing decoded from the guest's tables and clock part (totals, fields, blank lines, refresh rate), cursor, product and memory, drawing words and the pixel mode, primitive assembly, unmodelled reports; with `--features vprodiag`, the texture packing check: how many texture levels were checked against the upload that wrote their memory, how many disagree, and the first few kinds of disagreement (level format, upload path, word 4 and code) | | `vpro regs` | Host interface registers (no wait) and the widget's modelled registers: memory and flow-control config, FIFO set-up words, DMA and statistics addresses, BUZZ words, NIC, i2c, back-end index | | `vpro fifo` | Command FIFO levels, raster queue, the command parser's state, the 2D stream, the open GL primitive, the image raster and query records | | `vpro state` | The state a draw is made under: primitive assembly (open primitive, held vertices, colour and texture coordinate), the transform (matrices, viewport, depth range, user clip planes), the raster words decoded (cull, polygon modes and offset, line and point sizes, stipples, scissor, window), the shader and back-end state the stages run with, and the board's own drawing words (draw mask, dest, plane mask, colour mode, depth function, write mask, blend word) | diff --git a/src/dev/odyssey/board.rs b/src/dev/odyssey/board.rs index 9a8f70867..238bd9144 100644 --- a/src/dev/odyssey/board.rs +++ b/src/dev/odyssey/board.rs @@ -115,6 +115,9 @@ pub(super) struct Reports { pub dma_code_reported: bool, /// One bit per dma::REPORT_* reason. pub dma_read_reported: u32, + /// The texture packing check (Board::check_level_packing). + #[cfg(feature = "vprodiag")] + pub packing: super::packing::PackingCheck, } /// The vertex side's texture registers: the current texture coordinate @@ -599,6 +602,8 @@ impl Default for Board { dma_readback_reported: false, dma_code_reported: false, dma_read_reported: 0, + #[cfg(feature = "vprodiag")] + packing: Default::default(), }, draw_mask: 0, draw_word: 0, @@ -970,6 +975,8 @@ impl Board { self.tex.coord_r = 0; self.tex.coord_q = ODSY_F32_ONE; self.diag.tex_rect_reported = false; + #[cfg(feature = "vprodiag")] + self.diag.packing.uploads.clear(); self.stream.vertex_x.fill(0); self.stream.vertex_y.fill(0); self.stream.vertex_count = 0; diff --git a/src/dev/odyssey/command.rs b/src/dev/odyssey/command.rs index 7cff4c629..dcf391ac3 100644 --- a/src/dev/odyssey/command.rs +++ b/src/dev/odyssey/command.rs @@ -82,6 +82,8 @@ impl Board { let at = (tag - reg::TEX_LEVEL) as usize * 3; let op = self.cmd.operand; self.tex_mut().levels[at..at + 3].copy_from_slice(&op[..3]); + #[cfg(feature = "vprodiag")] + self.check_level_packing(op[0], op[1]); return; } if tag == gl_cmd::TEXCOORD_3F || tag == gl_cmd::TEXCOORD_4F { diff --git a/src/dev/odyssey/debug.rs b/src/dev/odyssey/debug.rs index 57f34563c..e9923fd06 100644 --- a/src/dev/odyssey/debug.rs +++ b/src/dev/odyssey/debug.rs @@ -410,6 +410,20 @@ impl Odyssey { g.diag.reported_addr_count.load(std::sync::atomic::Ordering::Relaxed), g.diag.reported_cmd_count ); + #[cfg(feature = "vprodiag")] + { + let p = &g.diag.packing; + let _ = writeln!( + out, + " texture packing: {} levels checked against the upload that wrote them, {} disagree", + p.checked, p.mismatch_count + ); + for m in &p.mismatches { + let _ = writeln!(out, " {m}"); + } + } + #[cfg(not(feature = "vprodiag"))] + let _ = writeln!(out, " texture packing: not checked (build with --features vprodiag)"); } None => { let _ = writeln!(out, " board busy: state not read (FIFO {} words, raster {} jobs)", fifo.queued_words(), raster.pending()); diff --git a/src/dev/odyssey/dma.rs b/src/dev/odyssey/dma.rs index db6493764..73c9bd138 100644 --- a/src/dev/odyssey/dma.rs +++ b/src/dev/odyssey/dma.rs @@ -218,8 +218,30 @@ impl Board { ((hdr[dma::HDR_ORIGIN] & 0xffff) as i32).wrapping_add(self.win.read_origin[0]), ((hdr[dma::HDR_ORIGIN] >> 16) as i32).wrapping_add(self.win.read_origin[1]), ); + // A luminance or luminance-alpha texture uploaded by address with + // no level selected names 2-byte fields with format byte 0, which + // would read as four 4-bit components; the source's bytes are the + // field's (traced: buttonfly's texture font, word 4 0x80001000 and + // code 0x48 into a format-0xb level; glprim's 256x256 LUMINANCE + // and INTENSITY textures, code 0x42 into a format-4 level). Packed + // as 4/4/4/4, a clear texel's alpha came back 0xf0 and every glyph + // drew as a box. The board model's packing check (feature + // vprodiag, Board::check_level_packing) found the luminance case. + let one_or_two = if read || drawable || bytes != 2 { + None + } else { + match hdr[dma::HDR_CONTROL] & image::CODE_MASK { + image::CODE_LUM => Some(super::field::FIELD_ONE), + image::CODE_LUM_ALPHA => Some(super::field::FIELD_TWO), + _ => None, + } + }; let codec = |at: u8| { - let named = super::copy::source_codec(bytes, fmt & 0xff); + let named = if let Some(field) = one_or_two { + super::field::Codec::Texel { bytes: 2, field } + } else { + super::copy::source_codec(bytes, fmt & 0xff) + }; if drawable && read { return self.drawable_codec(origin.0, origin.1, at).filter(|c| super::copy::codec_bytes(*c) == bytes).unwrap_or(named); } @@ -305,6 +327,29 @@ impl Board { } } let obj = memory.then_some(()); + // The texture packing check: a backing-store page (dma_raw) is + // no texture and is not checked. + #[cfg(feature = "vprodiag")] + let fmt = hdr[dma::HDR_FORMAT]; + #[cfg(feature = "vprodiag")] + let page = hdr[dma::HDR_CONTROL] & image::CODE_MASK == 0 && matches!(fmt, dma::FMT_RAW16 | dma::FMT_RAW32 | dma::FMT_RAW64); + #[cfg(feature = "vprodiag")] + if memory && !page { + use super::packing::{kind_codec, UploadPacking}; + if let Some(codec) = kind_codec(to.v.kind) { + // The surface dma_fields() wrote through. + self.note_upload(UploadPacking { + base: if drawable { self.draw_word } else { hdr[dma::HDR_DEST] } & ADDR_MASK, + pitch: hdr[dma::HDR_WIDTH] & PITCH_MASK, + log2: ((fmt >> 16) & 0xf) as u8 + 1, + codec, + word4: fmt, + code: hdr[dma::HDR_CONTROL] & write::CODE_MASK, + how: "DMA", + checked: false, + }); + } + } let mut e = [DmaEntry::default(); dma::MAX_PAGES]; let x = hdr[dma::HDR_ORIGIN] & 0xffff; let y = hdr[dma::HDR_ORIGIN] >> 16; @@ -791,6 +836,17 @@ pub(super) static DMA_X_LAYOUTS: [DmaLayout; 4] = [ lay(image::CODE_CI, 1, [BI, 0, 0, 0, 0, 0, 0, 0]), ]; +/// X reads whose word 7 names a packed type (bits 8:5 nonzero beyond the +/// byte types), by the whole write code (write::CODE_MASK): the write +/// table's packing (pixel_write.rs) run backwards. The X server's 30-bit +/// TrueColor visual saves screen pixels as 0x10c, ABGR 2_10_10_10_REV +/// (traced: the Motif text cursor's save-under in nedit), and puts them +/// back under the same code. +pub(super) static DMA_X_PACKED: [(u32, DmaLayout); 2] = [ + (0x10c, pack(0x0c, 4, [fld(3, 2, 30), fld(2, 10, 20), fld(1, 10, 10), fld(0, 10, 0)])), // ABGR, 2_10_10_10_REV + (0x10b, pack(0x0b, 4, [fld(0, 10, 22), fld(1, 10, 12), fld(2, 10, 2), fld(3, 2, 0)])), // RGBA, 10_10_10_2 +]; + /// Whether a read header's class and code are sent both for a colour read /// and for a depth or stencil read. fn shared_depth_code(cls: u32, code: u32) -> bool { @@ -811,7 +867,11 @@ impl Board { let drawable = hdr[dma::HDR_DEST] & dma::SENTINEL != 0; let mut l: Option<&'static DmaLayout> = None; - if xcode != 0 { + let wide = hdr[dma::HDR_CONTROL] & write::CODE_MASK; + + if wide > image::CODE_MASK { + l = DMA_X_PACKED.iter().find(|(c, _)| *c == wide).map(|(_, t)| t); + } else if xcode != 0 { for t in DMA_X_LAYOUTS.iter() { if t.code as u32 == xcode { l = Some(t); @@ -1724,6 +1784,8 @@ impl Board { // image through the FIFO, Board::image_put()). let gpu = self.gpu_unit(); let to = if gpu { super::pipe::backend::DestMem::of(mem.untracked(), &self.dest_views()).colour[0] } else { self.dest_mem().colour[0] }; + #[cfg(feature = "vprodiag")] + self.note_selected_upload("mip-level build", 0); for y in 0..hd { for x in 0..wd { let v = from.load_word(2 * x as i32, 2 * y as i32).unwrap_or(0); diff --git a/src/dev/odyssey/draw.rs b/src/dev/odyssey/draw.rs index 2a87a33f0..1f9a152cd 100644 --- a/src/dev/odyssey/draw.rs +++ b/src/dev/odyssey/draw.rs @@ -853,6 +853,10 @@ impl Board { let z = f32::from_bits(self.image.box_words[6]) as f64; self.image.fragment = None; + #[cfg(feature = "vprodiag")] + if self.dest_views().scratch { + self.note_selected_upload("FIFO image", 0); + } if z == 0.0 || !z.is_finite() || self.dest_views().scratch { return; } diff --git a/src/dev/odyssey/mod.rs b/src/dev/odyssey/mod.rs index c80d9780f..a341e7693 100644 --- a/src/dev/odyssey/mod.rs +++ b/src/dev/odyssey/mod.rs @@ -83,6 +83,8 @@ mod interface; mod clip; mod logic; mod mmio; +#[cfg(feature = "vprodiag")] +mod packing; mod pixel_dma; mod pipe; mod pixel_write; diff --git a/src/dev/odyssey/packing.rs b/src/dev/odyssey/packing.rs new file mode 100644 index 000000000..a4d88cd19 --- /dev/null +++ b/src/dev/odyssey/packing.rs @@ -0,0 +1,127 @@ +//! The texture packing check (feature `vprodiag`): how each upload into +//! board memory packed its texels, checked against every texture level +//! descriptor later named over that memory. A texture packed one way and +//! sampled another round-trips through glGetTexImage unnoticed, so the +//! guest's own tests cannot see it; `vpro status` reports what this finds. + +use super::board::Board; +use super::view::Kind; +use super::vram::{Format, ADDR_MASK, PITCH_MASK}; +use crate::devlog::LogModule; + +/// How many uploads the packing check remembers. +const UPLOADS_KEPT: usize = 64; +/// How many disagreements it keeps as text. +const MISMATCHES_KEPT: usize = 16; + +/// How an upload into board memory laid its texels out: the surface's +/// base, row of tiles and pixel size, the field's packing, and what the +/// guest sent (word 4 and the write code, or the path). +#[derive(Clone, Copy, Debug)] +pub(super) struct UploadPacking { + pub base: u32, + pub pitch: u32, + pub log2: u8, + pub codec: super::field::Codec, + pub word4: u32, + pub code: u32, + pub how: &'static str, + pub checked: bool, +} + +/// Whether two codecs store a word the same way: a field of eight bytes or +/// more holds four 12-bit lanes whatever its FIELD_FMT (field::texel_pack). +fn same_packing(a: super::field::Codec, b: super::field::Codec) -> bool { + use super::field::Codec; + let lanes = |c| matches!(c, Codec::Lanes | Codec::Texel { bytes: 8.., .. }); + a == b || (lanes(a) && lanes(b)) +} + +/// The packing a view's kind stores, None for a depth view. +pub(super) fn kind_codec(k: Kind) -> Option { + use super::field::{Codec, FIELD_FOUR}; + match k { + Kind::Rgba8 => Some(Codec::Texel { bytes: 4, field: FIELD_FOUR }), + Kind::Byte => Some(Codec::Byte), + Kind::Coded(c) => Some(c), + _ => None, + } +} + +impl Board { + /// Remember how an upload into board memory stored its texels. + pub fn note_upload(&mut self, p: UploadPacking) { + let u = &mut self.diag.packing.uploads; + u.retain(|q| q.base != p.base); + if u.len() >= UPLOADS_KEPT { + u.remove(0); + } + u.push(p); + } + + /// Note an upload through the pixel mode's selected surface (a FIFO + /// image into a scratch surface, a board-built mip level). + pub fn note_selected_upload(&mut self, how: &'static str, code: u32) { + let f = Format::decode(self.pixel_mode[2]); + if let Some(codec) = kind_codec(self.dest_views().colour[0].kind) { + self.note_upload(UploadPacking { + base: self.pixel_mode[0] & ADDR_MASK, + pitch: self.pixel_mode[1] & PITCH_MASK, + log2: f.fb_log2, + codec, + word4: self.pixel_mode[2], + code, + how, + checked: false, + }); + } + } + + /// A level descriptor (words 0 and 1) named over memory an upload + /// wrote: the level's storage (address, row and format index) should + /// be the one the upload stored in. A disagreement means the texels + /// were packed one way and are sampled another; it is counted, kept + /// for `vpro status` and logged. Each upload is checked once. + pub fn check_level_packing(&mut self, word0: u32, word1: u32) { + let base = word0 & ADDR_MASK; + if base == 0 { + return; + } + let Some(i) = self.diag.packing.uploads.iter().position(|q| q.base == base && !q.checked) else { + return; + }; + let p = self.diag.packing.uploads[i]; + self.diag.packing.uploads[i].checked = true; + let Some((s, f)) = super::field::level_surface(word0, word1) else { + return; + }; + self.diag.packing.checked += 1; + if s.bpp_log2 == p.log2 && same_packing(f.codec, p.codec) && s.pitch == p.pitch { + return; + } + self.diag.packing.mismatch_count += 1; + // One line for each kind of disagreement: the level's format word + // and the upload's path, word 4 and code. + let kind = format!( + "level format {:#010x} ({} bytes, {:?}) over a {} upload (word 4 {:#010x}, code {:#x}) stored as {} bytes, {:?}", + word1 & !0xfff, 1u32 << s.bpp_log2, f.codec, p.how, p.word4, p.code, 1u32 << p.log2, p.codec + ); + let line = format!("{kind}; level {:#x} pitch {}, upload pitch {}", word0, s.pitch, p.pitch); + crate::dlog!(LogModule::Odyssey, "sgi-odyssey: texture packing disagrees: {}", line); + if self.diag.packing.mismatches.len() < MISMATCHES_KEPT && !self.diag.packing.mismatches.iter().any(|m| m.starts_with(&kind)) { + self.diag.packing.mismatches.push(line); + } + } +} + +/// The check's state, in the board's reports. +#[derive(Default)] +pub(super) struct PackingCheck { + /// The packing of the latest uploads into board memory, by base. + pub uploads: Vec, + /// Level descriptors checked against an upload, and those whose + /// storage disagrees with it (the first few kept as text). + pub checked: u32, + pub mismatch_count: u32, + pub mismatches: Vec, +} diff --git a/src/dev/odyssey/tests/dma.rs b/src/dev/odyssey/tests/dma.rs index 8b7a7872c..2445c1827 100644 --- a/src/dev/odyssey/tests/dma.rs +++ b/src/dev/odyssey/tests/dma.rs @@ -542,3 +542,136 @@ fn a_ci16_image_put_lands_its_indices_in_the_index_field() { assert_eq!(index_at(&s, 146, 313), 0); assert_eq!(index_at(&s, 147, 314), 0); } + +/// The X server's 30-bit TrueColor save of screen pixels, as the Motif text +/// cursor's save-under sends it in nedit's file dialog: the frame buffer +/// named by address with the window's pixel mode selected, word 7 write +/// code 0x10c (ABGR, 2_10_10_10_REV), four bytes a pixel. Refusing the +/// code left the guest's buffer as it was, and the cursor's restore then +/// painted that back: the glyph columns under the cursor vanished. +#[test] +fn a_30_bit_save_under_returns_abgr_2_10_10_10_rev() { + use crate::dev::odyssey::field::Layout; + use crate::dev::odyssey::vram::Format; + const MODE: u32 = 0x2000_6960; + let (mut s, _, ram) = fenced_board(); + for w in [select(reg::DEST_SELECT), 0x2000, 0x50, MODE, 0] { + s.mmio_write(ODSY_USER_CMD_FIFO, w as u64, 4); + } + s.gpu_sync(); + let f = Format::decode(MODE); + let rows = Rows::new(s.vram_ptr(), View::colour(&Surface::new(0x2000, 0x50, f.fb_log2), Layout::of(f).field(false), MAX_DIM)); + rows.store_word(200, 300, 0xffff_ffff); + rows.store_word(201, 300, 0x4747_4700); + ram.put(PAGE_A, &[0xa5; 40]); + let mut expect = [0xa5u8; 40]; + + put_table(&ram, TABLE, [0x2000, 300 << 16 | 200, 0x50, 0x10002, 0x8223_3062, 0, 8, 0xb301_010c], &[pte(PAGE_A + 16, 8)]); + descriptor(&mut s, TABLE); + + // Ten bits a channel: 0x47 widens to 0x11d, as the plane holds it. + expect[16..20].copy_from_slice(&0xffff_ffffu32.to_be_bytes()); + expect[20..24].copy_from_slice(&0x11d4_751du32.to_be_bytes()); + assert_eq!(ram.get(PAGE_A, 40), expect); +} + +/// buttonfly's texture font: a luminance-alpha texture uploaded by address +/// with no level selected, word 4 0x80001000 (2-byte fields, format byte +/// 0) and source code 0x48, into the level its descriptor later names as +/// format 0xb, a luminance byte then an alpha byte. Each texel keeps its +/// two bytes. Stored as four 4-bit components, a clear texel (L 0xff, A 0) +/// read back with alpha 0xf0 and every glyph drew as an opaque box. +#[test] +fn a_luminance_alpha_texture_upload_keeps_its_alpha() { + let (mut s, _, ram) = board_with_ram(); + colour_destination(&mut s); + ram.put(PAGE_B, &[0xff, 0x00, 0x80, 0xff, 0x3c, 0x5a]); + let header = [0x16d000, 0, 0x10, 1 << 16 | 3, 0x8000_1000, 0, 6, 0x3200_0048]; + put_table(&ram, TABLE, header, &[pte(PAGE_B, 6)]); + + descriptor(&mut s, TABLE); + + let lum_alpha = Codec::Texel { bytes: 2, field: crate::dev::odyssey::field::FIELD_TWO }; + let word = |x| mem_word(&s, 0x16d000, 0x10, 1, lum_alpha, x, 0); + assert_eq!(word(0), 0xffff_ff00); + assert_eq!(word(1), 0x8080_80ff); + assert_eq!(word(2), 0x3c3c_3c5a); +} + +/// Level descriptor `i`'s three words, as the library sends them. +fn tex_level(s: &mut Board, i: u32, word0: u32, word1: u32) { + for w in [select(reg::TEX_LEVEL + i), word0, word1, 0] { + s.mmio_write(ODSY_USER_CMD_FIFO, w as u64, 4); + } +} + +/// The board model checks each texture level the library names against +/// the upload that wrote its memory: buttonfly's luminance-alpha font +/// (format index 0xb over a 2-byte upload of code 0x48) agrees; the same +/// memory named as format index 0xc (four 4-bit components) does not, and +/// the disagreement is counted and kept for `vpro status`. +#[cfg(feature = "vprodiag")] +#[test] +fn a_level_is_checked_against_the_upload_that_wrote_it() { + let (mut s, _, ram) = board_with_ram(); + colour_destination(&mut s); + ram.put(PAGE_B, &[0xff, 0x00, 0x80, 0xff]); + put_table(&ram, TABLE, [0x16d000, 0, 0x10, 1 << 16 | 2, 0x8000_1000, 0, 4, 0x3200_0048], &[pte(PAGE_B, 4)]); + descriptor(&mut s, TABLE); + + tex_level(&mut s, 0, 0x16d000, 0x00b0_0010); + s.gpu_sync(); + assert_eq!((s.diag.packing.checked, s.diag.packing.mismatch_count), (1, 0)); + + // Each upload is checked once: a second draw's descriptor is not. + tex_level(&mut s, 0, 0x16d000, 0x00c0_0010); + s.gpu_sync(); + assert_eq!((s.diag.packing.checked, s.diag.packing.mismatch_count), (1, 0)); + + descriptor(&mut s, TABLE); + tex_level(&mut s, 0, 0x16d000, 0x00c0_0010); + s.gpu_sync(); + assert_eq!((s.diag.packing.checked, s.diag.packing.mismatch_count), (2, 1)); + assert!(s.diag.packing.mismatches[0].contains("word 4 0x80001000"), "{}", s.diag.packing.mismatches[0]); +} + +/// glprim's 256x256 LUMINANCE (and INTENSITY) texture: a one-byte source, +/// code 0x42, uploaded by address with no level selected under the same +/// word 4 as buttonfly's font, into the level its descriptor names as +/// format index 4, one byte a texel's value. The board model's packing +/// check found it stored as four 4-bit components. +#[test] +fn a_luminance_texture_upload_keeps_its_byte() { + let (mut s, _, ram) = board_with_ram(); + colour_destination(&mut s); + ram.put(PAGE_B, &[0x00, 0x80, 0xff, 0x5a]); + put_table(&ram, TABLE, [0x16d000, 0, 0x10, 1 << 16 | 4, 0x8000_1000, 0, 4, 0x3205_0042], &[pte(PAGE_B, 4)]); + + descriptor(&mut s, TABLE); + tex_level(&mut s, 0, 0x16d000, 0x0040_0010); + s.gpu_sync(); + + let one = Codec::Texel { bytes: 2, field: crate::dev::odyssey::field::FIELD_ONE }; + let word = |x| mem_word(&s, 0x16d000, 0x10, 1, one, x, 0); + assert_eq!([word(0), word(1), word(2), word(3)], [0, 0x8080_8080, 0xffff_ffff, 0x5a5a_5a5a]); + #[cfg(feature = "vprodiag")] + assert_eq!((s.diag.packing.checked, s.diag.packing.mismatch_count), (1, 0)); +} + +/// An 8-byte level names format index 33 (four components) over an +/// upload stored as four 12-bit lanes: the same storage, not a +/// disagreement. +#[cfg(feature = "vprodiag")] +#[test] +fn an_eight_byte_level_over_lanes_is_the_same_packing() { + let (mut s, _, ram) = board_with_ram(); + colour_destination(&mut s); + ram.put(PAGE_B, &[0x11, 0x22, 0x33, 0x44]); + put_table(&ram, TABLE, [0x16b000, 0, 0x10, 1 << 16 | 1, 0x8002_5000, 0, 4, 0x3201_004b], &[pte(PAGE_B, 4)]); + + descriptor(&mut s, TABLE); + tex_level(&mut s, 0, 0x16b000, 0x8210_0010); + s.gpu_sync(); + + assert_eq!((s.diag.packing.checked, s.diag.packing.mismatch_count), (1, 0)); +} diff --git a/test/gltest/texpack.sh b/test/gltest/texpack.sh new file mode 100644 index 000000000..7607cf2f3 --- /dev/null +++ b/test/gltest/texpack.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# texpack.sh: run in the guest (cd to glprim's directory first). Every way +# glprim makes the library upload a texture: each sized internal format and +# each unsized source format, small (FIFO image) and 256x256 (DMA), with +# and without mipmap levels, plus ABGR, 16-bit sources, a sub-image and +# the gluBuild2DMipmaps scene. On VPro (iris built with --features +# vprodiag), compare the board model's packing +# check before and after (`vpro status`, "texture packing"): each level +# descriptor is checked against the upload that wrote its memory. +H=${HOLD:-200} +MIP=linear_mipmap_linear,linear +run() { echo "$*"; ./glprim -p none --scene tex --hold $H "$@" > /dev/null 2>&1; } +for f in alpha4 alpha8 alpha12 alpha16 luminance4 luminance8 luminance12 luminance16 \ + luminance4_alpha4 luminance6_alpha2 luminance8_alpha8 luminance12_alpha4 \ + luminance12_alpha12 luminance16_alpha16 intensity4 intensity8 intensity12 \ + intensity16 r3_g3_b2 rgb4 rgb5 rgb8 rgb10 rgb12 rgb16 rgba2 rgba4 rgb5_a1 \ + rgba8 rgb10_a2 rgba12 rgba16; do + for n in 8 256; do + run --texifmt $f --texsize $n + run --texifmt $f --texsize $n --texfilter $MIP + done +done +for f in rgba rgb luminance luminance_alpha alpha intensity; do + for n in 8 256; do + run --texfmt $f --texsize $n + run --texfmt $f --texsize $n --texfilter $MIP + run --texfmt $f --texsize $n --texushort + done +done +for n in 8 256; do + run --texabgr --texsize $n + run --texsize $n --texsubrect 2,2,4,4 +done +for f in rgba rgb luminance luminance_alpha alpha intensity; do + echo "texmod $f"; ./glprim -p none --scene texmod --texfmt $f --hold $H > /dev/null 2>&1 +done