RHI - GPU Rendering Hardware Interface#
The RHI is YUP’s backend-agnostic, low-level GPU layer, provided by the
yup_rhi module. It sits below the 2D Graphics API and above Rive’s GPU
abstraction, giving you direct control over pipelines, render passes, buffers,
and textures while remaining portable across Metal, Direct3D, OpenGL / OpenGL ES,
WebGL2, WebGPU, and Vulkan (in progress).
Use the RHI when you need custom GPU work that the 2D Graphics API does not
express - 3D geometry, post-process effects, compute passes for DSP or simulation,
or offscreen render-to-texture pipelines. For GPU compute without any window or
graphics (e.g. audio DSP on the GPU), use GpuDevice directly — no
GraphicsContext or yup_graphics dependency needed.
When to use the RHI#
You want to… |
Use |
|---|---|
Draw 2D vector content (paths, text, images) |
|
Render custom geometry with your own shaders |
|
Apply a fullscreen post-process effect |
|
Run GPU compute (DSP, simulation) |
|
Render offscreen and sample the result as a texture |
|
Mix 2D drawing and custom passes on one surface |
|
Classes at a glance#
GpuDevice- a reference-counted GPU device abstraction. Owns the native device and command queue. Factories for all RHI resources start here.GpuFrame- RAII scope for one frame’s GPU work. Begin, encode passes, submit.GpuRenderPass- records draw commands (pipeline, bindings, draws) into a render target within a frame.GpuComputePass- records compute dispatch commands (pipeline, storage buffers, uniforms) directly against the backend-native API.GpuPipeline- an immutable, compiled vertex + fragment pipeline plus fixed state.GpuComputePipeline- an immutable, compiled compute pipeline (single compute stage, native backend API, no ore dependency).GpuPipelineCache- thread-safe compile-or-fetch cache for pipelines.GpuBuffer- an immutable vertex, index, uniform, or storage buffer.GpuTexture- an opaque GPU texture, the currency between passes,Image, andGraphics::drawTexture.GpuTarget- a minimal offscreen render surface for render-pass-only work.GpuCanvas- an offscreen surface that adds 2DGraphicsdrawing on top of a target.
In this area#
Concepts & lifecycle - the GPU bridge, GPU capability probing, and the frame/pass model.
Frames & render passes -
GpuFrame,GpuRenderPass, andGpuRenderOptions.Pipelines & shaders - compiling pipelines, pipeline options, shader sources, binding maps, and the pipeline cache.
Offline shader compilation - build
.yslshader bundles ahead of time withyup_add_shader_bundleand theyup_shader_bundlertool.Shader bundle binary format - the RIFF
YSLBcontainer specification (FourCCs, chunk layout, reflection blob, versioning).Buffers & textures -
GpuBufferandGpuTexture.Offscreen targets & canvases -
GpuTarget,GpuCanvas, and CPU readback.Walkthrough: the spinning cube - an end-to-end custom 3D render with a post-process blur.