Skip to main content

Module device

Module device 

Source
Expand description

Device tiles (feature wgpu): a tile that already lives on the render device, handed to the viewport with no copy through the CPU.

Experimental: may change in any release (docs/stability.md).

A source that renders on the GPU (an engine running on the device eframe opened) answers a request with a DeviceTile through TileSink::deliver_device:

  • a texture (DeviceTile::texture): any 2D float-sampled format (Rgba16Float, Rgba32Float, Rgba8Unorm, Rgba8UnormSrgb…), with TEXTURE_BINDING usage, read texel by texel;
  • a storage buffer (DeviceTile::buffer): f32 values, one to four channels a pixel, rows row_floats apart (BufferLayout), with STORAGE usage, read in place (the GPU path binds the rows the tile covers, nothing is copied).

Its values are scene-referred (Encoding::Scene, as Pixels::Scene: the display stage runs on them in the shader, as for uploaded tiles) or display-ready (Encoding::Display, as Pixels::Display: sRGB-encoded, shown as they are). Alpha is not drawn: the image is opaque, as on the GPU path’s uploaded tiles.

The resource must have been created on the render state’s device (the one gpu::install was given), and the work writing it submitted to that device’s queue before the hand-over. A tile from another device, or one that does not fit, is refused with a DeviceTileError: the source’s fallback (DeviceTile::fallback), when it offers one, then gives CPU pixels that take the usual path. The fallback runs on the thread that delivers the tile, never on the interface thread: a tile refused when the interface takes it in (the render device changed in between) is dropped and asked for again.

What the producer needs alive while the tile is shown (its image, with the charge it carries in the producer’s memory accounting) rides with the tile (DeviceTile::keep): the viewport holds it exactly as long as it holds the tile, and drops it when the tile is replaced, evicted or refused, or the viewport’s state is dropped. The viewport’s upload counters (ViewportState::transfers) count device tiles as bound, with no byte copied.

Structs§

BufferLayout
Where a tile’s pixels are in a storage buffer of f32 values: pixel (x, y) of the image starts at float offset / 4 + y * row_floats + x * channels.
DeviceTile
A tile on the render device: the resource, the device it was created on, what its values are, and where the tile starts in it.
RenderDevice
The render device the GPU path draws with, as device tiles are checked against it.

Enums§

DeviceTileError
Why a device tile was refused.
Encoding
What a device tile’s values are, as Pixels says for CPU tiles.
Resource
The resource a device tile reads.