Skip to main content

RenderGraph

Struct RenderGraph 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn push_cpu(self, node: impl RenderNodeCpu + 'static) -> Self

Append a CPU-only node (available regardless of the wgpu feature).

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,