pub trait GpuGridModel:
Send
+ Sync
+ 'static {
Show 15 associated constants and 8 methods
const NAME: &'static str;
const ID: &'static str;
const DESCRIPTION: &'static str;
const PALETTE: &'static [[u8; 4]];
const STATS: &'static [StatDescriptor];
const BUFFERS: &'static [&'static str];
const STEP_BINDINGS: &'static [BindingDecl];
const DISPLAY_BINDINGS: &'static [BindingDecl];
const REDUCE_BINDINGS: &'static [BindingDecl];
const STEP_SHADER: &'static str;
const DISPLAY_SHADER: &'static str;
const REDUCE_SHADER: &'static str;
const WORKGROUP_SIZE: u32 = 16;
const ACTIONS: &'static [GpuGridAction] = _;
const REPLAYS_EXACTLY: bool = true;
// Required methods
fn param_descriptors() -> Vec<ParamDescriptor>;
fn dims(params: &[ParamValue]) -> (u32, u32);
fn seed_buffers(
width: u32,
height: u32,
params: &[ParamValue],
seed: Option<u64>,
) -> Vec<Vec<u32>>;
fn step_params_bytes(
width: u32,
height: u32,
params: &[ParamValue],
) -> Vec<u8> ⓘ;
fn stats(counts: &[u32]) -> Vec<StatValue>;
// Provided methods
fn buffer_lens(width: u32, height: u32) -> Vec<usize> { ... }
fn step_dims(width: u32, height: u32) -> (u32, u32) { ... }
fn action_params_bytes(
_action: usize,
width: u32,
height: u32,
params: &[ParamValue],
_seed: u32,
) -> Vec<u8> ⓘ { ... }
}Expand description
A grid model stepped by a compute shader, with its state resident in GPU storage buffers.
All Self::BUFFERS ping-pong together. A step reads every buffer’s current side and writes every
buffer’s next side. Each pass binds a buffer by its label, with an optional _in or _out suffix,
and the access mode picks the side. A read binding gets the current side, and a read_write binding
gets the next side. The binding module lists the reserved names.
Rust sees the shaders as opaque strings, so the compiler checks none of the contracts the items below state.
Required Associated Constants§
Sourceconst ID: &'static str
const ID: &'static str
Stable id that identifies the model in a model set, on the command line and in a spec file.
Sourceconst DESCRIPTION: &'static str
const DESCRIPTION: &'static str
One-line description shown in the UI.
Sourceconst PALETTE: &'static [[u8; 4]]
const PALETTE: &'static [[u8; 4]]
Palette used by the stats UI. The display shader writes RGBA directly, so it has its own copy of the colours, and the model must keep both copies in agreement.
Sourceconst STATS: &'static [StatDescriptor]
const STATS: &'static [StatDescriptor]
Stat series for the history chart.
Its length must equal the number of atomic<u32> in the reduce shader’s counters binding. A
shorter array validates, and the stats past its end read zero.
Sourceconst BUFFERS: &'static [&'static str]
const BUFFERS: &'static [&'static str]
Labels of the buffers ping-ponged per step. A shader’s binding names refer to these labels.
A plain model has one label, and a model that also carries per-cell RNG state has two. A label
must not be reserved or end in _in or _out. The engine panics at construction on such a label.
Sourceconst STEP_BINDINGS: &'static [BindingDecl]
const STEP_BINDINGS: &'static [BindingDecl]
Declarations of the step shader.
Sourceconst DISPLAY_BINDINGS: &'static [BindingDecl]
const DISPLAY_BINDINGS: &'static [BindingDecl]
Declarations of the display shader.
Sourceconst REDUCE_BINDINGS: &'static [BindingDecl]
const REDUCE_BINDINGS: &'static [BindingDecl]
Declarations of the reduce shader.
Sourceconst STEP_SHADER: &'static str
const STEP_SHADER: &'static str
Step shader, dispatched over Self::step_dims.
Sourceconst DISPLAY_SHADER: &'static str
const DISPLAY_SHADER: &'static str
Display shader, dispatched once per display texel.
The display texture is capped well under the largest grids, so a texel reads the cell at
texel * grid / tex. The Dims uniform of henad::dims carries both sizes.
Sourceconst REDUCE_SHADER: &'static str
const REDUCE_SHADER: &'static str
Reduce shader, dispatched once per cell.
A bit-packed model’s reduce shader reads a word and extracts its own bit.
Provided Associated Constants§
Sourceconst WORKGROUP_SIZE: u32 = 16
const WORKGROUP_SIZE: u32 = 16
Side N of the @workgroup_size(N, N) every shader declares, actions included.
The engine panics at construction on a shader that declares another literal size.
Sourceconst ACTIONS: &'static [GpuGridAction] = _
const ACTIONS: &'static [GpuGridAction] = _
One-off passes the user can trigger. Each gets a button in the Parameters panel.
Sourceconst REPLAYS_EXACTLY: bool = true
const REPLAYS_EXACTLY: bool = true
Whether two builds on one seed step through identical states.
A model whose passes leave the order of their writes to the GPU declares false. The testing kit then skips
the checks that compare two runs on one seed, and the app notes that a replayed run might differ from its
recorded row.
Required Methods§
Sourcefn param_descriptors() -> Vec<ParamDescriptor>
fn param_descriptors() -> Vec<ParamDescriptor>
Returns the full descriptor list.
Unlike crate::authoring::model::grid_model::GridModel, width and height are not prepended. A
GPU model spells its list out, so it can mirror the exact parameter order of the CPU model it is
compared against.
Sourcefn dims(params: &[ParamValue]) -> (u32, u32)
fn dims(params: &[ParamValue]) -> (u32, u32)
Returns the grid dimensions for these params. The engine clamps each dimension to at least 1.
Sourcefn seed_buffers(
width: u32,
height: u32,
params: &[ParamValue],
seed: Option<u64>,
) -> Vec<Vec<u32>>
fn seed_buffers( width: u32, height: u32, params: &[ParamValue], seed: Option<u64>, ) -> Vec<Vec<u32>>
Returns the initial contents of each ping-ponged buffer, uploaded once at construction.
The result holds one vector per Self::BUFFERS label, in that order, each with the length that
Self::buffer_lens returns. The engine asserts the count and the lengths at construction. Index 0 is the
primary state buffer that the shipped display and reduce shaders read.
Sourcefn step_params_bytes(width: u32, height: u32, params: &[ParamValue]) -> Vec<u8> ⓘ
fn step_params_bytes(width: u32, height: u32, params: &[ParamValue]) -> Vec<u8> ⓘ
Returns the step shader’s uniform block as raw bytes.
A model fills in the Params struct generated from its step shader and returns
bytemuck::bytes_of(¶ms).to_vec(). A model whose step needs nothing but the dimensions can
return the dimensions themselves.
Sourcefn stats(counts: &[u32]) -> Vec<StatValue>
fn stats(counts: &[u32]) -> Vec<StatValue>
Turns the counters read back from the reduce shader into values, in Self::STATS order.
counts has STATS.len() entries, and is all-zero until the first readback completes. The
engine pairs the values with Self::STATS by position and drops the values past the shorter
list. The testing kit’s StatCount check, given a device, catches a result with fewer values.
Provided Methods§
Sourcefn buffer_lens(width: u32, height: u32) -> Vec<usize>
fn buffer_lens(width: u32, height: u32) -> Vec<usize>
Returns the length in u32 elements of each ping-ponged buffer, in Self::BUFFERS order.
The default is one element per cell. A bit-packed model overrides this to return its word
count, and must override Self::step_dims to match, so that one invocation owns one word.
The engine asserts at construction that the result holds one length per buffer.
Sourcefn step_dims(width: u32, height: u32) -> (u32, u32)
fn step_dims(width: u32, height: u32) -> (u32, u32)
Returns the dispatch domain of the step pass, in invocations.
The default is one invocation per cell. Reduce always dispatches (width, height), and display
dispatches one invocation per texel.
Sourcefn action_params_bytes(
_action: usize,
width: u32,
height: u32,
params: &[ParamValue],
_seed: u32,
) -> Vec<u8> ⓘ
fn action_params_bytes( _action: usize, width: u32, height: u32, params: &[ParamValue], _seed: u32, ) -> Vec<u8> ⓘ
Returns an action’s uniform block as raw bytes.
seed is fresh on every press, so a shader that draws gets a new stream each time. The default
returns the step’s block, enough for an action that needs nothing but the dimensions.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".