Skip to main content

CpuCanvas

Struct CpuCanvas 

Source
pub struct CpuCanvas { /* private fields */ }
Expand description

A CPU canvas: an off-screen Pixmap (the vello_cpu raster target, per the CONS-CORE spec) plus the batched SDF instances drawn onto it. The host pushes quads + lines, then CpuCanvas::rasterize evaluates the sdf coverage for every instance over its bounding box and alpha-composites it into the pixmap.

Coverage math is byte-for-byte the same the GPU lane runs, so a CPU frame matches a GPU frame (the sdf_primitives parity test pins this).

Implementations§

Source§

impl CpuCanvas

Source

pub fn new(width: u32, height: u32, camera: Camera, background: [u8; 4]) -> Self

A fresh width × height canvas cleared to background (straight RGBA8), under camera.

No serial clear here: the background is no longer painted up-front in a single-threaded for over 1M pixels (that was a pure Amdahl serial tail). Instead [raster_batches] fills each row’s background inside the gatling scanline kernel — the workers that own a row clear it before compositing, so the clear scales across all cores with zero extra alloc.

Source

pub fn pixmap(&self) -> &Pixmap

The raster target — the vello_cpu pixmap (spec §2: “CpuCanvas → vello_cpu pixmap”). Exposed so a host can hand its glyph/curve overlay (L1 vello) the same target later.

Source

pub fn rasterize(&mut self) -> Frame

Rasterize every batched instance onto the pixmap (lines under quads, the graph convention: chips draw on top of edges). Returns the straight (un-premultiplied) RGBA8 Frame.

GATLING multicore (LAW 2): the raster fans across all cores by scanline row — each row is owned by exactly one thread, so the blends never contend, and the per-pixel compositing order (all lines in order, then all quads in order) is preserved bit-for-bit vs the sequential path (the parallel_raster_matches_sequential test pins this). Below a pixel-work threshold the frame stays single-threaded (zero pool overhead on small draws).

Source

pub fn rasterize_with_workers(&mut self, workers: usize) -> Frame

rasterize with an explicit gatling worker count: 0 ⇒ one per core (the production path), 1 ⇒ the forced single-threaded path. Exposed so a bench can time the same parallel region at 1 vs N workers and report the real cores-busy / speedup (rather than guessing from a sweep average). The output is identical for any worker count (the parallel_raster_matches_sequential test pins bit-identity at N vs 1).

Source

pub fn raster_only(&mut self, workers: usize)

Run only the compositing raster (bg clear + y-bucketed SDF blend) at workers gatling workers — the region the GATLING scanline kernel governs, without the memory-bandwidth-bound un-premultiply (frame). Exposed for the scaling bench so cores-busy can be measured on the part that is CPU-bound, separate from the RAM-bandwidth-capped pixmap→RGBA8 conversion.

Source

pub fn frame(&self) -> Frame

Snapshot the current pixmap as a straight-RGBA8 Frame (un-premultiplied) without consuming the canvas.

Parallel un-premultiply: the per-pixel un-premultiply is embarrassingly parallel, so it runs through the same gatling scanline kernel into a pre-allocated output buffer (zero per-pixel alloc) instead of the old single-threaded flat_map().collect() over the whole framebuffer — that collect was the second half of the Amdahl serial tail.

Source

pub fn frame_with_workers(&self, workers: usize) -> Frame

frame with an explicit worker count (see rasterize_with_workers).

Trait Implementations§

Source§

impl Canvas for CpuCanvas

Source§

fn push_quads(&mut self, quads: &[QuadInstance])

Append a batch of SDF quad instances (circles / rings / markers, already lowered via QuadInstance). Zero-copy slice — the canvas decides whether it copies into a vertex buffer (GPU) or rasters in place (CPU).
Source§

fn push_lines(&mut self, lines: &[LineInstance])

Append a batch of thick-AA line instances.
Source§

fn camera(&self) -> &Camera

The camera this canvas draws under (the shared L0 Camera).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.