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
impl Gpu
Sourcepub fn new(dma: GpuDma, display: DisplayConfig) -> Self
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.
Sourcepub fn from_dma_mut(dma: &mut GpuDma) -> &mut Self
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.
Sourcepub fn dma_mut(&mut self) -> &mut GpuDma
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.
Sourcepub fn set_display(&mut self, display: DisplayConfig)
pub fn set_display(&mut self, display: DisplayConfig)
Reprogram the display mode and the picture position.
Sourcepub fn set_display_start(&mut self, origin: (u16, u16))
pub fn set_display_start(&mut self, origin: (u16, u16))
Show VRAM from origin (GP1(05h)): a double-buffer flip.
Sourcepub fn set_display_enabled(&mut self, enabled: bool)
pub fn set_display_enabled(&mut self, enabled: bool)
Turn the video output on or off (GP1(03h)).
Sourcepub fn set_draw_area(&mut self, top_left: (u16, u16), bottom_right: (u16, u16))
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).
Sourcepub fn set_draw_offset(&mut self, offset: (i16, i16))
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.
Sourcepub fn set_mask_mode(&mut self, mode: MaskMode)
pub fn set_mask_mode(&mut self, mode: MaskMode)
Set the mask-bit state (GP0(E6h)).
Sourcepub fn set_draw_mode(&mut self, material: TextureMaterial)
pub fn set_draw_mode(&mut self, material: TextureMaterial)
Apply material’s texture page, blend equation, dither and
texture window (GP0(E1h), GP0(E2h)).
Sourcepub fn set_texture_window(&mut self, window: TextureWindow)
pub fn set_texture_window(&mut self, window: TextureWindow)
Set the texture window (GP0(E2h)).
Sourcepub fn draw<P: GpuPacket>(&mut self, packet: &P)
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.
Sourcepub fn wait_idle(&mut self)
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.
Sourcepub fn arm_draw_done(&mut self)
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.
Sourcepub fn signal_draw_done(&mut self)
pub fn signal_draw_done(&mut self)
Send GP0(1Fh), closing immediate drawing so is_draw_done rises
once it is drawn.
Sourcepub fn submit_static(&mut self, chain: &'static impl StaticChain)
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.