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>
impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> VramAllocator<ROOM_PAGES, CLUT_ROWS>
Sourcepub const fn new(clut_base_y: u16) -> Self
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.
Sourcepub const fn with_clut_band(band: VramRect) -> Self
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.
Sourcepub const fn clut_bounds(&self) -> VramRect
pub const fn clut_bounds(&self) -> VramRect
The rectangle every CLUT this allocator hands out lies inside.
Sourcepub const fn clut_band_is_reserved(&self) -> bool
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.
Sourcepub fn reserve_rect(&mut self, rect: VramRect) -> VramHandle
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.
Sourcepub fn reserve_room_band(&mut self, base_x: u16, base_y: u16)
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.
Sourcepub fn alloc_window(
&mut self,
width_texels: u16,
height_texels: u16,
) -> Option<(TexturePage, TextureWindowPlacement, VramHandle)>
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).
Sourcepub fn alloc_room_page(&mut self) -> Option<(TexturePage, VramHandle)>
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.
Sourcepub fn alloc_model_slot(
&mut self,
halfwords_per_row: u16,
depth: TextureDepth,
) -> Option<(TexturePage, VramHandle)>
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.
Sourcepub fn free(&mut self, handle: VramHandle)
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>
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>
fn clone(&self) -> VramAllocator<ROOM_PAGES, CLUT_ROWS>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Debug for VramAllocator<ROOM_PAGES, CLUT_ROWS>
impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> Debug for VramAllocator<ROOM_PAGES, CLUT_ROWS>
Source§impl<const ROOM_PAGES: usize, const CLUT_ROWS: usize> VramRegionSource for VramAllocator<ROOM_PAGES, CLUT_ROWS>
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)>
fn alloc_page_run( &mut self, count: u16, depth: TextureDepth, page_y: u16, ) -> Option<(TexturePage, VramHandle)>
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)>
fn alloc_clut(&mut self, entries: u16) -> Option<(Clut, VramHandle)>
entries palette slots (16 for 4bpp, 256 for 8bpp).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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)