Skip to main content

GpuGridModel

Trait GpuGridModel 

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

Source

const NAME: &'static str

Name shown in the UI.

Source

const ID: &'static str

Stable id that identifies the model in a model set, on the command line and in a spec file.

Source

const DESCRIPTION: &'static str

One-line description shown in the UI.

Source

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.

Source

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.

Source

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.

Source

const STEP_BINDINGS: &'static [BindingDecl]

Declarations of the step shader.

Source

const DISPLAY_BINDINGS: &'static [BindingDecl]

Declarations of the display shader.

Source

const REDUCE_BINDINGS: &'static [BindingDecl]

Declarations of the reduce shader.

Source

const STEP_SHADER: &'static str

Step shader, dispatched over Self::step_dims.

Source

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.

Source

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§

Source

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.

Source

const ACTIONS: &'static [GpuGridAction] = _

One-off passes the user can trigger. Each gets a button in the Parameters panel.

Source

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§

Source

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.

Source

fn dims(params: &[ParamValue]) -> (u32, u32)

Returns the grid dimensions for these params. The engine clamps each dimension to at least 1.

Source

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.

Source

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(&params).to_vec(). A model whose step needs nothing but the dimensions can return the dimensions themselves.

Source

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§

Source

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.

Source

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.

Source

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".

Implementors§

Source§

impl GpuGridModel for GpuGameOfLife

Source§

const NAME: &'static str = "Game of Life (GPU)"

Source§

const ID: &'static str = "gpu_game_of_life"

Source§

const DESCRIPTION: &'static str = "Conway's Game of Life on a toroidal grid, stepped entirely on the GPU"

Source§

const PALETTE: &'static [[u8; 4]]

Source§

const STATS: &'static [StatDescriptor]

Source§

const BUFFERS: &'static [&'static str]

Source§

const STEP_BINDINGS: &'static [BindingDecl] = crate::binding_decls::bindings::GPU_GAME_OF_LIFE_STEP

Source§

const DISPLAY_BINDINGS: &'static [BindingDecl] = crate::binding_decls::bindings::GPU_GAME_OF_LIFE_DISPLAY

Source§

const REDUCE_BINDINGS: &'static [BindingDecl] = crate::binding_decls::bindings::GPU_GAME_OF_LIFE_REDUCE

Source§

const STEP_SHADER: &'static str = crate::shader_bindings::gpu_game_of_life::step::SHADER_STRING

Source§

const DISPLAY_SHADER: &'static str = crate::shader_bindings::gpu_game_of_life::display::SHADER_STRING

Source§

const REDUCE_SHADER: &'static str = crate::shader_bindings::gpu_game_of_life::reduce::SHADER_STRING

Source§

const ACTIONS: &'static [GpuGridAction]

Source§

impl GpuGridModel for GpuSir

Source§

const NAME: &'static str = "SIR Epidemic (GPU)"

Source§

const ID: &'static str = "gpu_sir"

Source§

const DESCRIPTION: &'static str = "Classic SIR compartmental model on a toroidal grid with Moore neighborhood, stepped entirely on the GPU"

Source§

const PALETTE: &'static [[u8; 4]]

Source§

const STATS: &'static [StatDescriptor]

Source§

const BUFFERS: &'static [&'static str]

Source§

const STEP_BINDINGS: &'static [BindingDecl] = crate::binding_decls::bindings::GPU_SIR_STEP

Source§

const DISPLAY_BINDINGS: &'static [BindingDecl] = crate::binding_decls::bindings::GPU_SIR_DISPLAY

Source§

const REDUCE_BINDINGS: &'static [BindingDecl] = crate::binding_decls::bindings::GPU_SIR_REDUCE

Source§

const STEP_SHADER: &'static str = crate::shader_bindings::gpu_sir::step::SHADER_STRING

Source§

const DISPLAY_SHADER: &'static str = crate::shader_bindings::gpu_sir::display::SHADER_STRING

Source§

const REDUCE_SHADER: &'static str = crate::shader_bindings::gpu_sir::reduce::SHADER_STRING

Source§

const ACTIONS: &'static [GpuGridAction]