Skip to main content

Module authoring

Module authoring 

Source
Expand description

Everything a model is written against: the model traits, their types, the helpers and the primitives.

Re-exports§

pub use bytemuck;

Modules§

prelude
Items a model’s source file imports whole.
primitives
Primitives that a kernel calls, each module named after its WGSL twin’s import path.

Structs§

BindingDecl
One @group(0) @binding(n) declaration. Its position in a pass’s slice is n.
BufferSpec
One storage buffer of the model’s state.
CaField
Double-buffered u8 cells stepped by M’s neighbourhood rule.
ComponentStats
Summary of a component labelling.
Deposits
Deposit lanes, with one cell per agent and one value per agent and field.
DisplaySpec
The pass that turns state into the display texture, for a model that draws a grid layer.
Extent
The world rectangle every display layer stretches to.
Geometry
World that the parameters describe, resolved once at construction.
GpuAgentAction
A one-off pass the user can trigger.
GpuGridAction
A one-off compute pass the user can trigger.
Grid2D
A double-buffered 2D grid of cells, stored row-major.
HashGrid
Cell geometry on its own, for a caller that needs the grid without the buckets. A GPU model mirrors it into its step uniform so its query walks the same grid as the CPU sort.
Network
A network of nodes and edges.
NoField
The empty grid slot, for a model that is agents only.
NoIndex
An index that holds nothing, for a model whose agents never look at one another.
NodeCtx
The graph, hot parameters and extent, shared by every node kernel.
Nodes
Mutable access to the lanes, the graph and the model’s own state.
PassCtx
Values that a pass’s uniform block can need, besides the parameters.
PassSpec
One compute pass of a step, run in declaration order.
ReduceSpec
The leaf of the stat reduction, which folds the population down to one value per lane.
ScalarField
S::FIELDS double buffered f32 grids over one shared scatter scratch.
ScalarRead
The field as an agent kernel sees it.
SpatialHash
Flat counting-sort grid over agent positions, rebuilt every tick.
SpringParams
Constants for the spring layout, in units of the mean spacing between nodes.
StepCtx
Context an agent kernel reads besides its own lanes.

Enums§

BindingKind
Kind of resource a binding declares, as the engine needs it for a layout entry.
Combine
Rule for combining deposits that land in the same cell.
Domain
A pass’s invocation domain.
NeighborhoodKind
Neighbourhood a grid rule reads.
PassId
Pass for which GpuAgentModel::pass_params_bytes returns the uniform block.

Constants§

AGENT_INIT_SEED
State an agent model’s random number generator (RNG) starts from when a run has no seed.
AGENT_PARAM_BASE
Number of params the engine prepends, and the index of a model’s first own param.
GRID_INIT_SEED
State a grid model’s random number generator (RNG) starts from when a run has no seed.
GRID_PARAM_BASE
Number of params the engine prepends, and the index of a model’s first own param.
NETWORK_INIT_SEED
State a network model’s random number generator (RNG) starts from when a run has no seed.
NETWORK_PARAM_BASE
Number of params that the engine prepends.
NUM_AGENTS
Index of the population.
NUM_NODES
Index of the node count. Its id stays num_agents, which the benchmark scripts look up.
STATS_CHUNK
Cells or agents per chunk in a stats reduction.
WORLD_HEIGHT
Index of the world’s height.
WORLD_WIDTH
Index of the world’s width.

Traits§

AgentLanes
Struct-of-arrays agent storage.
AgentModel
A population of agents, optionally over a field.
ChunkTally
A per chunk reduction, merged in chunk order.
FieldLayer
A layer of cells stepped once per tick.
GpuAgentModel
A population of agents stepped by compute shaders, with its state resident in GPU buffers.
GpuGridModel
A grid model stepped by a compute shader, with its state resident in GPU storage buffers.
GridModel
A cellular automaton over u8 cells.
NeighborIndex
Neighbour lookup rebuilt from agent positions each tick.
NetworkModel
A population of nodes joined by edges.
ScalarFieldSpec
Rules of a scalar field that only the model can supply.

Functions§

agent_init_rng
Returns the state an agent model’s RNG starts from: seed mixed, or AGENT_INIT_SEED when it is None.
agent_model_param_descriptors
Returns the full descriptor list: num_agents, world_width and world_height, then the model’s own params, then its field layer’s params.
bool_param
Returns a descriptor for a live switch.
choice_param
Returns a descriptor for a choice among options, starting at option default.
extract_bool
Returns the bool at index, or default when the index is missing or holds another kind.
extract_choice
Returns the index of the chosen option, or default if the value is not a choice.
extract_f32
Returns the f32 at index, or default when the index is missing or holds another kind.
extract_u32
Returns the u32 at index, or default when the index is missing or holds another kind.
f32_param
Returns a descriptor for a live f32 parameter, with step as its slider step.
grid_init_rng
Returns the state a grid model’s RNG starts from: seed mixed, or GRID_INIT_SEED when it is None.
label_components
Labels every node with the lowest node index in its component.
network_model_param_descriptors
Returns the full descriptor list: num_agents, world_width and world_height, then the model’s own params.
reduce_chunks
Maps each chunk of 0..len then folds the results in chunk order.
register_agent_model
Returns an entry for the CPU agent model A.
register_gpu_agent_model
Returns an entry for the GPU agent model M.
register_gpu_grid_model
Returns an entry for the GPU grid model M.
register_grid_model
Returns an entry for the CPU grid model M.
register_network_model
Returns an entry for the CPU network model N.
split_params
Splits a composed parameter list into the model’s own parameters and its field layer’s parameters.
stat
Returns an entry holding a scalar.
stat_histogram
Returns an entry holding a histogram, in which counts[i] counts the values in [edges[i], edges[i + 1]).
stat_vec2
Returns an entry holding a 2D vector.
u32_param
Returns a descriptor for a live u32 parameter.