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

Gpu

Struct Gpu 

Source
pub struct Gpu(/* private fields */);
Expand description

The PS1 GPU: its command port (GP0), its control port (GP1) and DMA channel 2, which feeds GP0.

Gpu owns the GpuDma token, so every operation that writes a GPU port is a method that needs &mut Gpu. That puts the borrow checker between two users of one command stream: drawing immediately while a linked-list walk feeds GP0 is a compile error, not a corrupted frame.

ⓘ
let frame = ot.frame();
frame.submit_with(gpu.dma_mut(), || {
    gpu.draw(&TriFlat::new([(0, 0), (8, 0), (0, 8)], 255, 0, 0)); // GP0 mid-walk
});

It is zero-sized, so holding and passing it costs nothing. Reading status (psx_gpu::is_draw_done, psx_io::gpu::status) needs no handle: a read can’t disturb the command stream.

use psx_gpu::display::{DisplayConfig, Resolution, VideoMode};
use psx_gpu::prim::FillRect;
use psx_gpu::Gpu;

fn start(dma: psx_io::periph::GpuDma) -> Gpu {
    let mut gpu = Gpu::new(dma, DisplayConfig::new(VideoMode::Ntsc, Resolution::R320X240));
    gpu.draw(&FillRect::new((0, 0), (320, 240), (0, 0, 32)));
    gpu
}

Implementations§

Source§

impl Gpu

Source

pub fn new(dma: GpuDma, display: DisplayConfig) -> Self

Take over the GPU: reset it, program display, point DMA at GP0 and turn the display on.

Source

pub fn from_dma_mut(dma: &mut GpuDma) -> &mut Self

The driver as a view of a token held elsewhere, such as the one a FramePair owns, for immediate drawing between its frames.

Source

pub fn dma_mut(&mut self) -> &mut GpuDma

The token, for APIs that start channel 2 themselves (frame submission, VRAM DMA). The driver stays borrowed meanwhile.

Source

pub fn release(self) -> GpuDma

Give the token back.

Source

pub fn set_display(&mut self, display: DisplayConfig)

Reprogram the display mode and the picture position.

Source

pub fn set_display_start(&mut self, origin: (u16, u16))

Show VRAM from origin (GP1(05h)): a double-buffer flip.

Source

pub fn set_display_enabled(&mut self, enabled: bool)

Turn the video output on or off (GP1(03h)).

Source

pub fn set_draw_area(&mut self, top_left: (u16, u16), bottom_right: (u16, u16))

Clip drawing to the rectangle from top_left to bottom_right (inclusive VRAM coordinates).

Source

pub fn set_draw_offset(&mut self, offset: (i16, i16))

Add offset to every vertex drawn from now on (GP0(E5h)), so a back buffer can be drawn in its own coordinates.

Source

pub fn set_mask_mode(&mut self, mode: MaskMode)

Set the mask-bit state (GP0(E6h)).

Source

pub fn set_draw_mode(&mut self, material: TextureMaterial)

Apply material’s texture page, blend equation, dither and texture window (GP0(E1h), GP0(E2h)).

Source

pub fn set_texture_window(&mut self, window: TextureWindow)

Set the texture window (GP0(E2h)).

Source

pub fn draw<P: GpuPacket>(&mut self, packet: &P)

Send packet to GP0 now, without an ordering table.

The same packet types go into an OtFrame, so a primitive has one encoder whether it is drawn now or linked into a frame.

Source

pub fn wait_idle(&mut self)

Wait until the GPU has drawn everything sent to it.

See crate::wait_idle for what that waits on.

Source

pub fn arm_draw_done(&mut self)

Clear GPUSTAT bit 24 (GP1(02h)) before kicking work that ends in GP0(1Fh); see psx_gpu::is_draw_done.

Source

pub fn signal_draw_done(&mut self)

Send GP0(1Fh), closing immediate drawing so is_draw_done rises once it is drawn.

Source

pub fn submit_static(&mut self, chain: &'static impl StaticChain)

Kick a 'static, immutable chain, such as DRAW_DONE_NODE, without waiting for it.

The chain outlives any walk, so there is nothing to wait for before reusing memory; a later kick waits for this walk on its own.

Trait Implementations§

Source§

impl Debug for Gpu

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Gpu

§

impl RefUnwindSafe for Gpu

§

impl Send for Gpu

§

impl Sync for Gpu

§

impl Unpin for Gpu

§

impl UnsafeUnpin for Gpu

§

impl UnwindSafe for Gpu

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> 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.