pub struct BumpBudget {
pub lines: u32,
pub binning: u32,
pub tiles: u32,
pub seg_counts: u32,
pub segments: u32,
pub blend_spill: u32,
pub ptcl: u32,
pub max_binding_bytes: u32,
}Expand description
How much bump-allocated scratch a renderer reserves, in elements.
Every field here is a count the GPU also reports back through
BumpAllocators, which is what makes the reservation measurable
rather than guessed: BumpBudget::observe takes what a frame asked
for and grows the budget to cover it.
Growth is one-way within a process. A window that once drew a map
keeps room to draw a map, on the grounds that it probably will again,
and that handing the memory back costs a reallocation of every buffer
at the moment the user is busiest. A renderer that opts in
(Renderer::set_shrink_scratch in vello) hands it back once its
scene has stayed much lighter for a while.
Fields§
§lines: u32Flattened line segments (LineSoup).
binning: u32Words of per-bin draw-object lists, not counting the draw-info region they share a buffer with.
tiles: u32Per-path tile allocations (Tile).
seg_counts: u32Line/tile crossings counted by path_count (SegmentCount).
segments: u32Per-tile path segments (PathSegment).
blend_spill: u32Words of spilled blend scratch.
ptcl: u32Words of per-tile command list beyond the structural
n_tiles * PTCL_INITIAL_ALLOC floor.
max_binding_bytes: u32Bytes of the largest buffer the device can bind. No bump-allocated
buffer, floors included, is sized past it. WebGPU’s default is
128 MiB, below Self::CEILING for lines and segments.
Implementations§
Source§impl BumpBudget
impl BumpBudget
Sourcepub const UPSTREAM: Self
pub const UPSTREAM: Self
Upstream vello’s constants, kept for reference and as the scale the ceiling below is expressed in.
Sourcepub const INITIAL: Self
pub const INITIAL: Self
What a renderer starts from, before it has seen a frame: zero,
with BufferSizes applying the viewport floor underneath. A
renderer that never draws anything reserves what the floor says
and no more.
Sourcepub const CEILING: Self
pub const CEILING: Self
Nothing grows past this – four times upstream’s reservation. No user interface reaches it; a scene that did would have rendered wrong on upstream too, and this way the renderer can say so instead of reserving without limit.
Sourcepub fn floor_for_viewport(n_tiles: u32) -> Self
pub fn floor_for_viewport(n_tiles: u32) -> Self
The least a viewport of n_tiles can be rendered with, per the
measurements at the constants above.
Sourcepub fn floor_for_scene(n_tiles: u32, n_path_tags: u32) -> Self
pub fn floor_for_scene(n_tiles: u32, n_path_tags: u32) -> Self
The viewport floor, extended by the encoded path stream’s known first-frame complexity.
Most buffers scale with screen area. Flattened lines also scale with the amount of path data, especially for dashed strokes, and there is no previous frame from which to learn on the first render.
Sourcepub fn with_max_binding_bytes(self, bytes: u32) -> Self
pub fn with_max_binding_bytes(self, bytes: u32) -> Self
This budget with every buffer limited to bytes per binding.
Sourcepub fn binding_capacity<T>(&self) -> u32
pub fn binding_capacity<T>(&self) -> u32
Elements of T that fit in one binding.
Sourcepub fn observe(&mut self, used: &BumpAllocators) -> bool
pub fn observe(&mut self, used: &BumpAllocators) -> bool
Grow to cover what a frame reported using, with headroom.
Returns true if anything changed, which is the caller’s cue to
drop pooled buffers of the sizes that are no longer asked for.
The headroom matters because feedback arrives after the render that produced it: reserving exactly the previous usage would repeatedly under-provision a growing scene. A failure may prevent later stages from reporting their final demand, so convergence is not guaranteed in a single subsequent render.
A counter that has wrapped (see [CORRUPT_COUNT]) is ignored rather
than believed: growing from it would pin a binding’s worth of memory
per buffer for the rest of the process on one bad readback.
Sourcepub fn observe_within(&mut self, used: &BumpAllocators, ceiling: &Self) -> bool
pub fn observe_within(&mut self, used: &BumpAllocators, ceiling: &Self) -> bool
BumpBudget::observe, growing no field past ceiling.
Sourcepub fn fit_total_bytes(&mut self, max_bytes: u64)
pub fn fit_total_bytes(&mut self, max_bytes: u64)
Shrink every reservation by the same factor until the whole budget
fits in max_bytes. A browser’s GPU process has a hard memory limit
(Safari’s is 600 MB); seven buffers each allowed a full binding reach
most of a gigabyte, and a GPU process killed there mid-frame took the
macOS window server down with it.
Sourcepub fn ceiling_for_viewport(n_tiles: u32) -> Self
pub fn ceiling_for_viewport(n_tiles: u32) -> Self
The most a viewport of n_tiles may grow to.
BumpBudget::CEILING is flat, and upstream’s constants it is
scaled from were picked at 1080p. The floors beneath it scale with
the viewport, so on a large enough target a flat ceiling sits below
what the viewport structurally needs: blend spill, in particular, is
TILE_WIDTH * TILE_HEIGHT words per tile per nesting level past the
on-chip stack, and a 5120x2880 desktop with one spilled level
everywhere asks for 14.7M words against a flat ceiling of 4.2M. A
frame like that overflows, observes, is refused growth, and
overflows again, forever – a black screen that looks like progress.
The device’s binding limit still applies on top.
Sourcepub fn size_in_bytes(&self) -> u64
pub fn size_in_bytes(&self) -> u64
Bytes this budget reserves, not counting the viewport floors.