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

VramAllocator

Struct VramAllocator 

Source
pub struct VramAllocator<const ROOM_PAGES: usize, const CLUT_ROWS: usize> { /* private fields */ }
Expand description

One owner for all of VRAM: texture pages, room-material windows, model strips and CLUT rows, with free. A coarse 64×16-pixel occupancy grid keeps page/strip/framebuffer reservations from overlapping; a composed TextureWindowAtlas sub-allocates room-material windows inside a reserved band; a ClutRowAllocator hands out CLUT rows.

Implementations§

Source§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> VramAllocator<ROOM_PAGES, CLUT_ROWS>

Source

pub const fn new(clut_base_y: u16) -> Self

Build an empty allocator. clut_base_y is the first CLUT-band row.

The band spans the whole 1024-pixel row and is not reserved in the page grid, so a texture page placed at page row 256 runs through it. Use with_clut_band to keep the two apart.

Source

pub const fn with_clut_band(band: VramRect) -> Self

Build an empty allocator whose CLUTs all lie in band, with band reserved in the page grid so no texture page, model strip or room page can overlap it.

A texture page is 256 rows tall, so every page at page row 256 reaches VRAM row 511; a CLUT band that shares rows with such a page also shares its pixels, and a sampler that runs a texel past the bottom of its window reads palette words as texture. The only VRAM that no page covers is the strip under a 320 x 480 framebuffer, so band is expected to be that strip, e.g. VramRect::new(0, 480, 320, 32) with CLUT_ROWS == 32.

band must start at x 0, be CLUT_ROWS rows tall, and align to the 64 x 16 pixel occupancy cells.

Source

pub const fn clut_bounds(&self) -> VramRect

The rectangle every CLUT this allocator hands out lies inside.

Source

pub const fn clut_band_is_reserved(&self) -> bool

Whether the CLUT band is reserved in the page grid, which makes it disjoint from every texture rectangle by construction.

Source

pub fn reserve_rect(&mut self, rect: VramRect) -> VramHandle

Reserve a fixed rectangle (e.g. the double-buffered framebuffer, or a region still owned by legacy hardcoded uploads). Returns a handle that can be freed but is normally permanent.

Source

pub fn reserve_room_band(&mut self, base_x: u16, base_y: u16)

Select the preferred room-material page band. Physical pages are reserved lazily as the logical atlas first touches them, so a six-page capacity no longer pins six pages for a scene that uses only one.

Source

pub fn alloc_window( &mut self, width_texels: u16, height_texels: u16, ) -> Option<(TexturePage, TextureWindowPlacement, VramHandle)>

Allocate a room-material window (delegates to the composed TextureWindowAtlas; the band must be reserved first).

Source

pub fn alloc_room_page(&mut self) -> Option<(TexturePage, VramHandle)>

Reserve a whole room-material page (large UI / background textures use a full page without a GP0(E2) window). The room band must be reserved first via reserve_room_band.

Source

pub fn alloc_model_slot( &mut self, halfwords_per_row: u16, depth: TextureDepth, ) -> Option<(TexturePage, VramHandle)>

Allocate an indexed model-atlas strip halfwords_per_row wide (rounded up to whole 64-halfword tpage bases) at page row 256.

Placement is measured in physical VRAM halfwords, so the same allocator works for 4bpp and 8bpp atlases. depth controls how the GPU interprets those halfwords when the returned tpage word is emitted.

Source

pub fn free(&mut self, handle: VramHandle)

Release a reservation.

Trait Implementations§

Source§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Clone for VramAllocator<ROOM_PAGES, CLUT_ROWS>

Source§

fn clone(&self) -> VramAllocator<ROOM_PAGES, CLUT_ROWS>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Debug for VramAllocator<ROOM_PAGES, CLUT_ROWS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> VramRegionSource for VramAllocator<ROOM_PAGES, CLUT_ROWS>

Source§

fn alloc_page_run( &mut self, count: u16, depth: TextureDepth, page_y: u16, ) -> Option<(TexturePage, VramHandle)>

Reserve count contiguous texture pages at page row page_y (0 or 256), returning the base TexturePage and a free handle.
Source§

fn alloc_clut(&mut self, entries: u16) -> Option<(Clut, VramHandle)>

Reserve a CLUT of entries palette slots (16 for 4bpp, 256 for 8bpp).
Source§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Copy for VramAllocator<ROOM_PAGES, CLUT_ROWS>

Auto Trait Implementations§

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Freeze for VramAllocator<ROOM_PAGES, CLUT_ROWS>

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> RefUnwindSafe for VramAllocator<ROOM_PAGES, CLUT_ROWS>

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Send for VramAllocator<ROOM_PAGES, CLUT_ROWS>

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Sync for VramAllocator<ROOM_PAGES, CLUT_ROWS>

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Unpin for VramAllocator<ROOM_PAGES, CLUT_ROWS>

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> UnsafeUnpin for VramAllocator<ROOM_PAGES, CLUT_ROWS>

§

impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> UnwindSafe for VramAllocator<ROOM_PAGES, CLUT_ROWS>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.