Expand description
GPU views: a view’s box drawn every frame by a renderer the app writes
with wgpu, composited by the platform under the view’s children.
A GpuRenderer is the app’s own Rust code: it builds its pipelines and
buffers once (GpuRenderer::prepare), takes the view’s props
(GpuRenderer::set_prop, GpuRenderer::set_animated_number) and
encodes a frame whenever the view needs one (GpuRenderer::render).
NSH runs it on a render thread of the surface’s, never on the main
thread and never in JS: the main thread only asks for frames on the
display’s clock and shows the ones that are done, so a frame the GPU or
the renderer is late with is skipped rather than waited for.
An app’s crate registers a renderer by name for TSX, from its
#[native_module] function (GpuRegistry::gpu_renderer):
#[native_module("gallery/scenes")]
fn scenes(registry: &mut Registry) {
registry.gpu_renderer("gallery/gears", Gears::new);
}and TSX makes a component of it with gpuView of nsh:
const Gears = gpuView<{ exposure: number }>("gallery/gears", { props: ["exposure"] });
<Gears exposure={exposure} style={{ height: 320 }} />A Rust element gives the view its renderer itself
(GpuViewExt::renderer): gpu_view().renderer(Gears::new).
§Frames
The renderer draws into GpuFrame::target, GpuFrame::width ×
GpuFrame::height pixels of GpuFrame::format (8-bit unsigned
normalized, RGBA or BGRA by platform; rebuild what depends on it if it
changes), clearing it first. Colors are what the view shows: sRGB-encoded
with premultiplied alpha, as CSS colors (a renderer lighting in linear
space encodes its result to sRGB itself). A frame is rendered when one of
the view’s props, its size or its scale changed, and on every display
frame while GpuRenderer::animating says so.
The device is shared by the views of a surface: a high-performance
adapter, with all of its features and limits (read them from
GpuContext::device). Where no GPU answers, GPU views draw nothing of
their own.
Re-exports§
pub use wgpu;
Structs§
- GpuContext
- The device a renderer prepares with (
GpuRenderer::prepare). - GpuEvent
- An event a renderer emitted (
GpuFrame::emit): its view’son<Name>handler getsdata. - GpuFrame
- One frame of a GPU view, as its renderer encodes it.
- GpuFrame
Parts - What a frame is made of (
GpuFrame::new).
Traits§
- GpuRegistry
- GPU renderers on a UI set’s registry: what an app’s crate calls from
its
#[native_module]function. - GpuRenderer
- What a GPU view draws: the app’s own wgpu code, run on the surface’s render thread.
- GpuView
Ext - A GPU view’s renderer, given by a Rust element.
Functions§
- make_
renderer - A renderer of
source(renderer_source);Nonefor a source of something else. - renderer_
source - The source of renderers
makemakes: a view mounted with it makes one.