pub trait GpuSimState: SimState {
// Required methods
fn encode_steps(
&mut self,
encoder: &mut CommandEncoder,
count: u32,
timestamps: Option<&QuerySet>,
);
fn encode_snapshot_passes(&mut self, encoder: &mut CommandEncoder);
fn begin_stats_readback(&mut self);
fn poll_stats_readback(&mut self, device: &Device, block: bool) -> StatsPoll;
fn stats_readback_pending(&self) -> bool;
fn view(&self) -> GpuSnapshot;
// Provided methods
fn encode_action(
&mut self,
_encoder: &mut CommandEncoder,
_index: usize,
) -> bool { ... }
fn encode_stats_passes(&mut self, encoder: &mut CommandEncoder) { ... }
}Expand description
Runner interface of a GPU state, driven by GpuSimThread on top of SimState.
A model implements an authoring trait, such as henad_core::authoring::model::gpu_grid_model::GpuGridModel,
instead of this trait. A GPU model’s state never leaves the GPU, so SimState::stats() reports whatever the last
completed Self::poll_stats_readback produced, a few milliseconds stale.
Required Methods§
Sourcefn encode_steps(
&mut self,
encoder: &mut CommandEncoder,
count: u32,
timestamps: Option<&QuerySet>,
)
fn encode_steps( &mut self, encoder: &mut CommandEncoder, count: u32, timestamps: Option<&QuerySet>, )
Records count steps into encoder, advancing the model’s own tick counter by count.
count must not exceed crate::gpu::MAX_STEPS_PER_SUBMISSION for one submission.
When timestamps is Some, the state stamps the beginning of the first step and the end of the last
into query indices 0 and 1, so the caller can measure GPU time over count steps.
Sourcefn encode_snapshot_passes(&mut self, encoder: &mut CommandEncoder)
fn encode_snapshot_passes(&mut self, encoder: &mut CommandEncoder)
Records the display pass (state -> display texture) and the stats-reduction pass (state -> a handful of numbers), at the snapshot cadence rather than every step.
Sourcefn begin_stats_readback(&mut self)
fn begin_stats_readback(&mut self)
Starts the async stats readback.
Call it immediately after the submission that Self::encode_snapshot_passes or Self::encode_stats_passes
was recorded into. Mapping earlier races the copy.
Sourcefn poll_stats_readback(&mut self, device: &Device, block: bool) -> StatsPoll
fn poll_stats_readback(&mut self, device: &Device, block: bool) -> StatsPoll
Completes an in-flight stats readback, updating what SimState::stats() returns.
With block = false this must not wait on the GPU. It runs every loop iteration, and the runner
exists to avoid a stall until the queue drains. block = true is for one-shot snapshots and samples, where a
real value in the stats panel beats a few ms of latency.
Returns the state of the readback after the poll.
Sourcefn stats_readback_pending(&self) -> bool
fn stats_readback_pending(&self) -> bool
Returns whether a readback started by Self::begin_stats_readback has not completed yet.
In a browser block = true above cannot block, so a one-shot snapshot publishes before its
readback arrives and the loop has to come back for it.
Sourcefn view(&self) -> GpuSnapshot
fn view(&self) -> GpuSnapshot
Returns the layers the UI draws.
The result is cloned into every snapshot. Keep it to Arc clones of things built once at construction.
Provided Methods§
Sourcefn encode_action(
&mut self,
_encoder: &mut CommandEncoder,
_index: usize,
) -> bool
fn encode_action( &mut self, _encoder: &mut CommandEncoder, _index: usize, ) -> bool
Records the model’s declared action at index, and returns whether the model declares one.
Nothing is recorded when it returns false, so the caller drops the encoder unsubmitted.
Note that the action’s seed is written through the queue, and the write takes effect when the next submission starts. Two presses of one action recorded into one encoder would both read the second seed, so each press needs its own submission.
Sourcefn encode_stats_passes(&mut self, encoder: &mut CommandEncoder)
fn encode_stats_passes(&mut self, encoder: &mut CommandEncoder)
Records the stats-reduction passes of Self::encode_snapshot_passes, without its display pass.
The default records the display pass too.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".