Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

first_vram_overlap

Function first_vram_overlap 

Source
pub const fn first_vram_overlap(rects: &[VramRect]) -> Option<(usize, usize)>
Expand description

Index of the first pair of rectangles in rects that share a pixel.

This exists because VRAM is the one PS1 resource with no allocator between the writer and the hardware: a picture uploaded to the wrong row silently reinterprets whatever was there, and the symptom is a wrong-looking texture somewhere else entirely, often only on the map that fills VRAM deepest.

A game that hardcodes its layout should list every fixed rectangle it owns (framebuffers, texture-page bands, CLUT rows, HUD and font strips) and pin the list at compile time, which costs no image bytes:

use psx_vram::{first_vram_overlap, VramRect};

const LAYOUT: [VramRect; 3] = [
    VramRect::new(0, 0, 320, 240),     // framebuffer A
    VramRect::new(0, 240, 320, 240),   // framebuffer B
    VramRect::new(0, 480, 320, 32),    // CLUT block
];
const _: () = assert!(
    matches!(first_vram_overlap(&LAYOUT), None),
    "VRAM layout overlaps",
);

A dynamic allocator’s reachable output is a rectangle too. Bound it and list that bound, so a later change to the bound, the band or the row count fails the build rather than corrupting VRAM on one map.