pub struct FieldSampler { /* private fields */ }Expand description
A compiled pipeline that fills a FieldBuffer on the GPU.
Implementations§
Source§impl FieldSampler
impl FieldSampler
Sourcepub fn new(device: &Device) -> Result<Self>
pub fn new(device: &Device) -> Result<Self>
Compile the kernel.
§Errors
Propagates composition failure, which would mean this crate’s own shaders are inconsistent.
Sourcepub fn sample(
&self,
device: &Device,
queue: &Queue,
params: GridParams,
field: GpuField,
) -> Result<FieldBuffer>
pub fn sample( &self, device: &Device, queue: &Queue, params: GridParams, field: GpuField, ) -> Result<FieldBuffer>
Allocate a FieldBuffer and fill it on the GPU.
Nothing is uploaded but two uniforms — the grid and the field id, 48
bytes between them — where
FieldBuffer::sampled copies four bytes
per sample.
§Errors
Error::GridTooLarge if the sample count
needs more workgroups than the adapter will dispatch.
Sourcepub fn sample_stack(
&self,
device: &Device,
queue: &Queue,
params: GridParams,
field: GpuField,
brushes: &[GpuBrush],
) -> Result<FieldBuffer>
pub fn sample_stack( &self, device: &Device, queue: &Queue, params: GridParams, field: GpuField, brushes: &[GpuBrush], ) -> Result<FieldBuffer>
Allocate a FieldBuffer and fill it from a base field and an edit
log, on the GPU.
The general mechanism GPU-011b chose, and the argument for choosing it
over composing a consumer’s WGSL is on FieldSampler.
brushes is folded first to last over the base, exactly as
BrushStack does. That order is part of
the value: a log mixing adds and subtracts does not commute, and one
containing a smooth add is not even associative (M-36..M-38), so a
shader that reordered for parallelism would compute a different solid.
§Errors
Error::GridTooLarge if the sample count
needs more workgroups than the adapter will dispatch.
Sourcepub fn fold_into(
&self,
device: &Device,
queue: &Queue,
base: &FieldBuffer,
out: &FieldBuffer,
brushes: &[GpuBrush],
) -> Result<()>
pub fn fold_into( &self, device: &Device, queue: &Queue, base: &FieldBuffer, out: &FieldBuffer, brushes: &[GpuBrush], ) -> Result<()>
Fold an edit log over samples the caller already put in base, writing
out.
sample_stack with the base field taken out of the
shader’s vocabulary: the log, the fold order and the arithmetic are the
same kernel, and what changes is only where the first value comes from.
This is the case this module’s own doc calls out — a consumer whose base
is an arbitrary analytic SDF — and the cost of serving it is that the
base is uploaded once instead of never.
The base and the output are two buffers rather than one folded in place, because the caller re-derives the output from a pristine base on every call — that is what makes a cached base impossible to leave stale — and an in-place fold would consume it.
out is taken by shared reference because nothing on this side mutates
it: the write is a queue submission, exactly as it is for the buffer
sample_stack allocates and returns.
§Errors
Error::SampleCountMismatch if
base and out do not describe the same number of samples — a fold
between two grids would read the wrong positions and produce a buffer
that still looks meshable.
Error::GridTooLarge if the sample count
needs more workgroups than the adapter will dispatch.