Skip to main content

FieldSampler

Struct FieldSampler 

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

A compiled pipeline that fills a FieldBuffer on the GPU.

Implementations§

Source§

impl FieldSampler

Source

pub fn new(device: &Device) -> Result<Self>

Compile the kernel.

§Errors

Propagates composition failure, which would mean this crate’s own shaders are inconsistent.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for FieldSampler

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,