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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/dev/odyssey/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,24 @@ pub(super) const ODSY_GL_PROGRAM_REPORTS: u32 = 16;
pub(super) const ODSY_GL_PROGRAM_ENTRIES: u32 = 2048;
pub(super) const ODSY_GL_WINDOW_ENTRIES: u32 = 0xc7;

/// The one modeled mode: the desktop target size.
/// The boot / reset / reference scanout size. A fresh board and every reset
/// present at this size; the guest's X server then programs the display
/// channel to whatever mode it wants, up to the modeled plane maximum below.
pub(super) const ODSY_WIDTH: u32 = 1280;
pub(super) const ODSY_HEIGHT: u32 = 1024;

/// The modeled plane maximum: the largest scanout the board will present, and
/// the size the rasterizer's planes (poly_marks and the clip/fill extent) are
/// allocated to. The display FIFO clamps any larger channel size to this.
/// 2560x1440 (QHD, the host monitor's native size) exceeds every mode IRIX
/// ships a video format for (the tallest shipped is 1920x1200_60), so the
/// guest needs a custom 2560x1440 timing entry to actually request it; the
/// board happily presents it once asked. It is well under the scanout's own
/// SCANOUT_MAX_DIM (16384) and a real V10's GL_MAX_VIEWPORT_DIMS (3840), and
/// the poly_marks plane it sizes is 2560*1440 = ~3.5 MiB.
pub(super) const ODSY_MAX_WIDTH: u32 = 2560;
pub(super) const ODSY_MAX_HEIGHT: u32 = 1440;

#[derive(Clone, Copy, Default)]
pub(super) struct OpenVertex {
pub word: u32,
Expand Down Expand Up @@ -966,9 +980,9 @@ impl Board {
self.stream.line_stipple[1] = 0xffff;
self.stream.line_stipple[2] = 0;
// No polygon is open; Board::reset clears the marks themselves.
self.stream.poly_row_lo = ODSY_HEIGHT;
self.stream.poly_row_lo = ODSY_MAX_HEIGHT;
self.stream.poly_row_hi = 0;
self.stream.poly_col_lo = ODSY_WIDTH;
self.stream.poly_col_lo = ODSY_MAX_WIDTH;
// Primitive assembly starts over: identity matrices, white, no
// primitive open (a reset can land inside one). Its viewport starts
// empty: nothing is drawn until the client's combined matrix arrives.
Expand Down Expand Up @@ -1231,7 +1245,7 @@ impl Board {
// The board's memory, at the size the strap reports.
self.vram = super::vram::Vram::new((self.widget.memory_size.max(32) as u64) << 20);

let pixels = ODSY_WIDTH as u64 * ODSY_HEIGHT as u64;
let pixels = ODSY_MAX_WIDTH as u64 * ODSY_MAX_HEIGHT as u64;
self.stream.poly_marks = vec![0u8; pixels as usize];

// The display reads board memory through a pointer that lives as
Expand Down
12 changes: 6 additions & 6 deletions src/dev/odyssey/display_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use std::sync::Arc;

use crate::devlog::LogModule;
use super::board::{ODSY_HEIGHT, ODSY_WIDTH};
use super::board::{ODSY_MAX_HEIGHT, ODSY_MAX_WIDTH};
use super::consts::{backend, cursor, dispmode, i2c, lut, overlay, ODSY_CHANNEL_HEIGHT, ODSY_CHANNEL_WIDTH, ODSY_FRAME_CLOCKS, ODSY_PIXEL_CLOCK_HZ};
use super::reader::{DisplayShared, SharedRegs};
use super::registers::reg;
Expand Down Expand Up @@ -322,17 +322,17 @@ impl DisplayFifo {
} else {
height = data;
}
if width > ODSY_WIDTH || height > ODSY_HEIGHT {
if width > ODSY_MAX_WIDTH || height > ODSY_MAX_HEIGHT {
crate::dlog!(
LogModule::Odyssey,
"sgi-odyssey: display channel {}x{} is larger than the modeled {}x{} planes",
width,
height,
ODSY_WIDTH,
ODSY_HEIGHT
ODSY_MAX_WIDTH,
ODSY_MAX_HEIGHT
);
width = width.min(ODSY_WIDTH);
height = height.min(ODSY_HEIGHT);
width = width.min(ODSY_MAX_WIDTH);
height = height.min(ODSY_MAX_HEIGHT);
}
if width != self.scanout.mode.width || height != self.scanout.mode.height {
self.set_scanout_size(width, height);
Expand Down
32 changes: 16 additions & 16 deletions src/dev/odyssey/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::devlog::LogModule;
use super::bits::{cmax, cmin};
use super::board::{
Board, ODSY_GL_CONSTANTS, ODSY_GL_LIGHTS, ODSY_GL_PROGRAM_ENTRIES, ODSY_GL_PROGRAM_REPORTS,
ODSY_HEIGHT, ODSY_WIDTH,
ODSY_MAX_HEIGHT, ODSY_MAX_WIDTH,
};
use super::consts::{
blend, colour, gl_cmd, light, line, mode, pattern, prog, tex, ucode, write, ODSY_BUFFERS,
Expand Down Expand Up @@ -1052,8 +1052,8 @@ impl Board {
// Pixel p is covered when x0 <= p + 0.5 < x1, clamped to the plane.
x0 = cmax((x0 - 0.5).ceil(), 0.0);
y0 = cmax((y0 - 0.5).ceil(), 0.0);
x1 = cmin((x1 - 0.5).ceil(), ODSY_WIDTH as f64) - 1.0;
y1 = cmin((y1 - 0.5).ceil(), ODSY_HEIGHT as f64) - 1.0;
x1 = cmin((x1 - 0.5).ceil(), ODSY_MAX_WIDTH as f64) - 1.0;
y1 = cmin((y1 - 0.5).ceil(), ODSY_MAX_HEIGHT as f64) - 1.0;
if x0 > x1 || y0 > y1 {
return;
}
Expand Down Expand Up @@ -1146,9 +1146,9 @@ impl Board {
}

let x0 = (minx as i64).max(0);
let x1 = (maxx as i64).min(ODSY_WIDTH as i64);
let x1 = (maxx as i64).min(ODSY_MAX_WIDTH as i64);
let y0 = (miny as i64).max(0);
let y1 = (maxy as i64).min(ODSY_HEIGHT as i64);
let y1 = (maxy as i64).min(ODSY_MAX_HEIGHT as i64);
if x0 >= x1 || y0 >= y1 {
return;
}
Expand Down Expand Up @@ -1236,7 +1236,7 @@ impl Board {

if y1 == y2 {
let lo = (x1.min(x2) as i64).max(0);
let hi = (x1.max(x2) as i64).min(ODSY_WIDTH as i64 - 1);
let hi = (x1.max(x2) as i64).min(ODSY_MAX_WIDTH as i64 - 1);
let mut i = lo;
while i <= hi {
if !omit_last || i != x2 as i64 {
Expand All @@ -1246,7 +1246,7 @@ impl Board {
}
} else {
let lo = (y1.min(y2) as i64).max(0);
let hi = (y1.max(y2) as i64).min(ODSY_HEIGHT as i64 - 1);
let hi = (y1.max(y2) as i64).min(ODSY_MAX_HEIGHT as i64 - 1);
let mut i = lo;
while i <= hi {
if !omit_last || i != y2 as i64 {
Expand All @@ -1262,7 +1262,7 @@ impl Board {
}
if dx.abs() >= dy.abs() {
let lo = (x1.min(x2) as i64).max(0);
let hi = (x1.max(x2) as i64).min(ODSY_WIDTH as i64);
let hi = (x1.max(x2) as i64).min(ODSY_MAX_WIDTH as i64);
let mut i = lo;
while i < hi {
let c = i as f64 + 0.5;
Expand All @@ -1273,7 +1273,7 @@ impl Board {
}
} else {
let lo = (y1.min(y2) as i64).max(0);
let hi = (y1.max(y2) as i64).min(ODSY_HEIGHT as i64);
let hi = (y1.max(y2) as i64).min(ODSY_MAX_HEIGHT as i64);
let mut i = lo;
while i < hi {
let c = i as f64 + 0.5;
Expand All @@ -1296,20 +1296,20 @@ impl Board {
/// convex trapezoids, for which every inside rule agrees.
pub fn gl_polygon_edge(&mut self, x1: i32, y1: i32, x2: i32, y2: i32) {
let lo = (y1.min(y2) as i64).max(0);
let hi = (y1.max(y2) as i64).min(ODSY_HEIGHT as i64);
let hi = (y1.max(y2) as i64).min(ODSY_MAX_HEIGHT as i64);
let mut row = lo;

while row < hi {
let c = row as f64 + 0.5;
let px = (x1 as f64 + (c - y1 as f64) * (x2 as f64 - x1 as f64) / (y2 as f64 - y1 as f64) - 0.5).ceil();

// A crossing right of the plane leaves every plane pixel outside.
if px >= ODSY_WIDTH as f64 {
if px >= ODSY_MAX_WIDTH as f64 {
row += 1;
continue;
}
let col: u32 = if px > 0.0 { px as u32 } else { 0 };
self.stream.poly_marks[(row as usize) * ODSY_WIDTH as usize + col as usize] ^= 1;
self.stream.poly_marks[(row as usize) * ODSY_MAX_WIDTH as usize + col as usize] ^= 1;
self.stream.poly_row_lo = (self.stream.poly_row_lo as i64).min(row) as u32;
self.stream.poly_row_hi = (self.stream.poly_row_hi as i64).max(row + 1) as u32;
self.stream.poly_col_lo = self.stream.poly_col_lo.min(col);
Expand All @@ -1322,11 +1322,11 @@ impl Board {
let mut row = self.stream.poly_row_lo;

while row < self.stream.poly_row_hi {
let base = row as usize * ODSY_WIDTH as usize;
let base = row as usize * ODSY_MAX_WIDTH as usize;
let mut inside: u8 = 0;

let mut col = self.stream.poly_col_lo;
while col < ODSY_WIDTH {
while col < ODSY_MAX_WIDTH {
inside ^= self.stream.poly_marks[base + col as usize];
self.stream.poly_marks[base + col as usize] = 0;
if paint && inside != 0 {
Expand All @@ -1336,9 +1336,9 @@ impl Board {
}
row += 1;
}
self.stream.poly_row_lo = ODSY_HEIGHT;
self.stream.poly_row_lo = ODSY_MAX_HEIGHT;
self.stream.poly_row_hi = 0;
self.stream.poly_col_lo = ODSY_WIDTH;
self.stream.poly_col_lo = ODSY_MAX_WIDTH;
}

pub fn gl_hold(&mut self, slot: u32, x: u32, y: u32) {
Expand Down
16 changes: 13 additions & 3 deletions src/dev/odyssey/tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,21 @@ fn the_display_channel_size_sets_the_scanout_mode() {
assert_eq!(size(&s), (1024, 768));
assert_eq!(shown(&mut s, 5, 5), 0x112233);

// Larger than the modelled planes: kept to them.
// Within the enlarged planes: 1920x1200 and 2560x1440 present at full size.
backend(&mut s, 0x3000_0000 | 0x2802 << 14 | 2);
backend(&mut s, 1600);
backend(&mut s, 1920);
backend(&mut s, 1200);
assert_eq!(size(&s), (1280, 1024));
assert_eq!(size(&s), (1920, 1200));
backend(&mut s, 0x3000_0000 | 0x2802 << 14 | 2);
backend(&mut s, 2560);
backend(&mut s, 1440);
assert_eq!(size(&s), (2560, 1440));

// Larger than the modelled planes: kept to them, per axis.
backend(&mut s, 0x3000_0000 | 0x2802 << 14 | 2);
backend(&mut s, 2600);
backend(&mut s, 1536);
assert_eq!(size(&s), (2560, 1440));

backend_entry(&mut s, ODSY_CHANNEL_HEIGHT, 720);
s.reset();
Expand Down
32 changes: 20 additions & 12 deletions src/disp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ use std::sync::Arc;
/// The refresh loop copies hardware state into this struct once per frame,
/// then builds a `CompositorSource` from it for the active compositor.
/// Row stride of every display buffer, in pixels.
pub const FB_STRIDE: usize = 2048;
///
/// Raised from 2048 to 2560 to let VPro/Odyssey (Tezro) and the shared present
/// path drive a native 2560x1440 desktop. The host RGBA framebuffer, the GL
/// output texture and the status bar all key off this. NOTE: Newport (ng1/*)
/// and GR2 still index their own buffers with a literal 2048 and are NOT
/// updated — their display/tests are knowingly left broken (see the 2560-only
/// decision); the user runs Tezro (Odyssey) and O2 (o2gfx), both of which copy
/// into the shared screen using FB_STRIDE and so track this value.
pub const FB_STRIDE: usize = 2560;
/// Rows of the display buffers and output textures: the tallest frame a
/// board can hand over (Newport and GR2 use the first 1024; IMPACT's
/// 1600x1200 modes need more).
Expand Down Expand Up @@ -738,7 +746,7 @@ pub struct StatusBarTexture {
impl StatusBarTexture {
pub fn new() -> Self {
Self {
buf: vec![0u32; 2048 * STATUS_BAR_HEIGHT],
buf: vec![0u32; FB_STRIDE * STATUS_BAR_HEIGHT],
tex: None,
}
}
Expand All @@ -751,7 +759,7 @@ impl StatusBarTexture {
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::NEAREST as i32);
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::NEAREST as i32);
gl.tex_image_2d(glow::TEXTURE_2D, 0, glow::RGBA as i32,
2048, STATUS_BAR_HEIGHT as i32, 0, glow::RGBA, glow::UNSIGNED_BYTE, glow::PixelUnpackData::Slice(None));
FB_STRIDE as i32, STATUS_BAR_HEIGHT as i32, 0, glow::RGBA, glow::UNSIGNED_BYTE, glow::PixelUnpackData::Slice(None));
t
};
self.tex = Some(t);
Expand All @@ -772,7 +780,7 @@ impl StatusBarTexture {
let tex = self.ensure_tex(gl);
unsafe {
gl.bind_texture(glow::TEXTURE_2D, Some(tex));
gl.pixel_store_i32(glow::UNPACK_ROW_LENGTH, 2048);
gl.pixel_store_i32(glow::UNPACK_ROW_LENGTH, FB_STRIDE as i32);
let u8_slice = std::slice::from_raw_parts(
self.buf.as_ptr() as *const u8,
self.buf.len() * 4,
Expand Down Expand Up @@ -1116,7 +1124,7 @@ impl StatusBar {
#[cfg(not(feature = "developer"))]
let line = format!(" {mips} MIPS {hz}Hz NET:");

let row_stride = 2048;
let row_stride = FB_STRIDE;
for row in 0..STATUS_BAR_HEIGHT {
let base = (bar_y + row) * row_stride;
if base + width <= rgba.len() { rgba[base..base + width].fill(BAR_BG); }
Expand Down Expand Up @@ -1208,7 +1216,7 @@ impl StatusBar {
// Rows filled in this column, counted from the bottom of the box.
let filled_rows = if col < full_cols { RECT } else if col == full_cols { partial } else { 0 };
for row in 0..RECT {
let idx = (bar_y + row) * 2048 + px;
let idx = (bar_y + row) * FB_STRIDE + px;
if idx >= rgba.len() { continue; }
rgba[idx] = if row >= RECT - filled_rows { color } else { BAR_BG };
}
Expand All @@ -1227,7 +1235,7 @@ impl StatusBar {
if px >= width { break; }
let c = if col < filled_cols { color } else { BAR_BG };
for row in 0..h {
let idx = (y + row) * 2048 + px;
let idx = (y + row) * FB_STRIDE + px;
if idx < rgba.len() { rgba[idx] = c; }
}
}
Expand All @@ -1240,7 +1248,7 @@ impl StatusBar {
for col in 0..w {
let px = x + col;
if px < width {
let idx = py * 2048 + px;
let idx = py * FB_STRIDE + px;
if idx < rgba.len() { rgba[idx] = color; }
}
}
Expand All @@ -1255,7 +1263,7 @@ impl StatusBar {
for col in 0..SQ {
let px = x + col;
if px < width {
let idx = py * 2048 + px;
let idx = py * FB_STRIDE + px;
if idx < rgba.len() { rgba[idx] = color; }
}
}
Expand All @@ -1279,7 +1287,7 @@ impl StatusBar {
let byte_idx = glyph_offset + row;
if byte_idx >= self.font.len() { break; }
let bits = self.font[byte_idx];
let row_base = (y + row) * 2048;
let row_base = (y + row) * FB_STRIDE;
for col in 0..8usize {
let px = x + col;
if px >= width { break; }
Expand Down Expand Up @@ -1319,7 +1327,7 @@ pub fn save_screenshot(path: &str, rgba: &[u32], width: usize, height: usize) ->
let mut rows: Vec<u8> = Vec::with_capacity(height * width * 3);
for y in 0..height {
for x in 0..width {
let px = rgba[y * 2048 + x];
let px = rgba[y * FB_STRIDE + x];
rows.push(( px & 0xFF) as u8);
rows.push(((px >> 8) & 0xFF) as u8);
rows.push(((px >> 16) & 0xFF) as u8);
Expand Down Expand Up @@ -1354,7 +1362,7 @@ mod rate_figure_tests {
more_cpus: std::array::from_fn(|i| (i == 0).then_some((cycles, 0))),
decoded_delta: 0, l1i_hits: 0, l1i_fetches: 0, uncached: 0, hb: 0, count_hz: 0, gfifo_pending: 0,
};
let mut rgba = vec![0u32; 2048 * super::STATUS_BAR_HEIGHT];
let mut rgba = vec![0u32; super::FB_STRIDE * super::STATUS_BAR_HEIGHT];
bar.render(&mut rgba, 640, 0, &stats(t0 + std::time::Duration::from_secs(1), 900_000_000));
bar.render(&mut rgba, 640, 0, &stats(t0 + std::time::Duration::from_secs(2), 40_000_000));
assert_eq!(bar.mips, 40.0);
Expand Down
11 changes: 8 additions & 3 deletions src/gl_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const FB_W: i32 = 2048;
const FB_H: i32 = 1024;
/// Output texture rows (prebuilt frames can be taller than Newport's 1024).
const OUT_H: i32 = crate::disp::FB_MAX_H as i32;
/// Output texture width. The prebuilt (Odyssey/O2) frame arrives at the shared
/// buffer stride (`FB_STRIDE`, 2560), wider than Newport's `FB_W` (2048), so the
/// FBO/output texture is sized to it. Newport's *source* textures stay `FB_W`.
const OUT_W: i32 = crate::disp::FB_STRIDE as i32;
const CURSOR_TEX_SIZE: i32 = 64;

const VERT_SRC: &str = "
Expand Down Expand Up @@ -327,7 +331,7 @@ impl GlCompositor {
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::NEAREST as i32);
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::NEAREST as i32);
gl.tex_image_2d(glow::TEXTURE_2D, 0, glow::RGBA as i32,
FB_W, OUT_H, 0, glow::RGBA, glow::UNSIGNED_BYTE, glow::PixelUnpackData::Slice(None));
OUT_W, OUT_H, 0, glow::RGBA, glow::UNSIGNED_BYTE, glow::PixelUnpackData::Slice(None));
self.tex_out = Some(tex_out);

let fbo = gl.create_framebuffer().unwrap();
Expand Down Expand Up @@ -479,7 +483,8 @@ impl Compositor for GlCompositor {
let tex_out = self.tex_out.unwrap();
unsafe {
gl.bind_texture(glow::TEXTURE_2D, Some(tex_out));
gl.pixel_store_i32(glow::UNPACK_ROW_LENGTH, FB_W);
// The prebuilt frame is a row of `FB_STRIDE` (= OUT_W) pixels.
gl.pixel_store_i32(glow::UNPACK_ROW_LENGTH, OUT_W);
let bytes = std::slice::from_raw_parts(frame.as_ptr() as *const u8, frame.len() * 4);
gl.tex_sub_image_2d(
glow::TEXTURE_2D, 0, 0, 0, w, h,
Expand Down Expand Up @@ -776,7 +781,7 @@ impl Compositor for GlCompositor {
// No flip: src row y → dst row y.
for y in 0..height {
let src_start = y * row_bytes;
let dst_start = y * 2048;
let dst_start = y * crate::disp::FB_STRIDE;
for x in 0..width {
let r = tight[src_start + x * 4 ] as u32;
let g = tight[src_start + x * 4 + 1] as u32;
Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ impl Renderer for GlRenderer {
self.current_win_h = win_h;
// Publish the display resolution for the event thread's aspect lock.
*self.display_res.lock() = (width as u32, height as u32);
// UV coords into the 2048×FB_MAX_H output texture
let max_u = width as f32 / 2048.0;
// UV coords into the FB_STRIDE×FB_MAX_H output texture
let max_u = width as f32 / crate::disp::FB_STRIDE as f32;
let max_v_main = height as f32 / crate::disp::FB_MAX_H as f32;
unsafe {
// Main display quad (letterboxed).
Expand Down