pub struct RenderGraph { /* private fields */ }Expand description
Linear chain of render nodes executed in insertion order.
The CPU fallback path (process_cpu) is always
available and does not require the wgpu feature. When the wgpu feature
is enabled, process_gpu runs every node on the GPU.
§Construction
// GPU+CPU graph (wgpu feature):
let ctx = Arc::new(RenderContext::init().await?);
let graph = RenderGraph::new(Arc::clone(&ctx))
.push(ColorGradeNode { brightness: 0.1, ..Default::default() });
// CPU-only graph (no wgpu feature needed):
let graph = RenderGraph::new_cpu()
.push_cpu(ColorGradeNode { brightness: 0.1, ..Default::default() });Implementations§
Source§impl RenderGraph
impl RenderGraph
Sourcepub fn new(ctx: Arc<RenderContext>) -> Self
pub fn new(ctx: Arc<RenderContext>) -> Self
Create a GPU+CPU graph.
Nodes added via push run on the GPU and expose a CPU
fallback via RenderNodeCpu. Nodes added via
push_cpu run on the CPU path only.
Sourcepub fn new_cpu() -> Self
pub fn new_cpu() -> Self
Create a CPU-only graph (no GPU context required).
process_gpu returns RenderError::Composite
when called on a CPU-only graph. Use process_cpu
instead.
Sourcepub fn with_pixel_format(self, pf: PixelFormat) -> Self
pub fn with_pixel_format(self, pf: PixelFormat) -> Self
Set the source pixel format so the GPU pipeline runs at the matching
working precision: high-bit-depth (10/12-bit) input promotes every
internal texture to Rgba16Float; 8-bit input stays Rgba8Unorm.
The chosen format flows through the texture-pool key and every
intermediate target. For Rgba16Float, drive the graph with a
high-bit-depth source node (e.g. YuvUploadNode::new_high_bit_depth);
process_gpu then returns raw Rgba16Float texels
(8 bytes/pixel) rather than 8-bit RGBA.
Sourcepub fn internal_format(&self) -> TextureFormat
pub fn internal_format(&self) -> TextureFormat
The working GPU texture format (Rgba8Unorm by default,
Rgba16Float after with_pixel_format with a
high-bit-depth format). Lets a caller interpret the byte layout of the
buffer process_gpu returns.
Sourcepub fn push(self, node: impl RenderNode + 'static) -> Self
pub fn push(self, node: impl RenderNode + 'static) -> Self
Append a GPU+CPU node to the chain.
The node must implement both RenderNode (GPU, wgpu feature only)
and RenderNodeCpu (CPU, always available) — the RenderNode
supertrait bound guarantees this.
Sourcepub fn push_cpu(self, node: impl RenderNodeCpu + 'static) -> Self
pub fn push_cpu(self, node: impl RenderNodeCpu + 'static) -> Self
Append a CPU-only node (available regardless of the wgpu feature).
Sourcepub fn process_gpu(
&self,
rgba: &[u8],
w: u32,
h: u32,
) -> Result<Vec<u8>, RenderError>
pub fn process_gpu( &self, rgba: &[u8], w: u32, h: u32, ) -> Result<Vec<u8>, RenderError>
Run the GPU pipeline: upload rgba → execute all GPU nodes → download result.
Requires the wgpu feature and a GPU context (created via new).
Returns RenderError::Composite if called on a CPU-only graph.
rgba is the 8-bit source frame and the returned buffer is 8-bit RGBA by
default. After with_pixel_format selects an
Rgba16Float working format, rgba is ignored (the graph is driven by a
high-bit-depth source node) and the returned buffer is raw Rgba16Float
texels (8 bytes/pixel); see internal_format.
§Errors
Returns an error on GPU device failure or staging-buffer readback failure.
Sourcepub fn process_gpu_to_texture(
&self,
rgba: &[u8],
w: u32,
h: u32,
) -> Result<TextureHandle, RenderError>
pub fn process_gpu_to_texture( &self, rgba: &[u8], w: u32, h: u32, ) -> Result<TextureHandle, RenderError>
Run the GPU pipeline and return the composited frame as a GPU
TextureHandle, without a GPU-to-CPU
readback. Use this for zero-copy display; use process_gpu
when the caller needs the pixels in system memory.
The returned texture is owned by the caller (taken out of the pool) and stays valid until dropped.
§Errors
Returns RenderError::Composite if called on a CPU-only graph, or on
GPU device failure.
Sourcepub fn process_cpu(&self, rgba: &[u8], w: u32, h: u32) -> Vec<u8> ⓘ
pub fn process_cpu(&self, rgba: &[u8], w: u32, h: u32) -> Vec<u8> ⓘ
Run the CPU fallback pipeline: apply each node’s process_cpu in order.
Both CPU-only nodes (push_cpu) and GPU nodes (push, wgpu feature)
participate — GPU nodes expose a CPU path via the RenderNodeCpu
supertrait.
Sourcepub fn set_param(&self, param: NodeParam) -> usize
pub fn set_param(&self, param: NodeParam) -> usize
Applies param to every GPU node that takes it, returning how many did.
The point is a stateful node: rebuilding the graph to change one parameter
would discard the state the node exists to carry (see
NodeParam). A return of 0 means nothing in this graph
names that parameter, which is how a caller tells a reuse from a no-op.