Skip to main content

RenderGraph

Struct RenderGraph 

Source
pub struct RenderGraph<'a> { /* private fields */ }
Expand description

A frame’s worth of passes, before compilation.

Built fresh every frame. The lifetime is the passes’ closures’: they borrow whatever persistent state the renderer holds, and the graph never outlives a frame, so nothing has to be cloned into them.

Implementations§

Source§

impl<'a> RenderGraph<'a>

Source

pub fn new(queue: Handle<Queue>) -> RenderGraph<'a>

An empty graph whose passes default to queue.

Source

pub fn create_image( &mut self, label: impl Into<String>, desc: TransientImageDesc, ) -> ImageId

Declares an image the graph owns for the duration of the frame.

Backed by the TransientPool, and aliased with any other transient of the same description whose lifetime does not overlap this one.

Source

pub fn create_buffer( &mut self, label: impl Into<String>, desc: TransientBufferDesc, ) -> BufferId

Declares a buffer the graph owns for the duration of the frame.

Source

pub fn import_image( &mut self, label: impl Into<String>, imported: ImportedImage, ) -> ImageId

Brings an externally owned image into the graph.

One handle is one node. Importing an image this graph already has returns the id already issued for it rather than a second one, and that is what makes two subsystems importing the same target — the base-colour page a monitor feeds and a forward pass binds, an offscreen target two renderers both draw into — the ordinary case it looks like. Two ids on one image would carry independent state trackers, each starting from its own declared initial, so the graph would see nothing to order between a write through one and a read through the other and emit no barrier at all.

The node keeps the first label. A later import naming it differently is not an error — subsystems name the same image for their own reasons — but every barrier record and CompiledGraph::dump line already names it, and a label that depended on which subsystem imported last would make the dump move under a caller reordering two unrelated imports.

A repeat import whose declaration disagrees with the first is refused: see GraphError::ImportDeclarationConflict, which compile returns.

Source

pub fn import_buffer( &mut self, label: impl Into<String>, imported: ImportedBuffer, ) -> BufferId

Brings an externally owned buffer into the graph.

One handle is one node, exactly as import_image describes and for the same reason — a second id would be a second state tracker, and a buffer written through one id and read through the other would be a read-after-write the graph never barriered. The first label wins, and a repeat import that disagrees is GraphError::BufferImportDeclarationConflict.

Source

pub fn add_render_pass( &mut self, label: impl Into<String>, ) -> PassBuilder<'_, 'a>

Starts declaring a render pass. Add it with PassBuilder::execute.

Source

pub fn add_compute_pass( &mut self, label: impl Into<String>, ) -> PassBuilder<'_, 'a>

Starts declaring a compute pass. Add it with PassBuilder::execute.

Source

pub fn add_copy_pass(&mut self, label: impl Into<String>) -> PassBuilder<'_, 'a>

Starts declaring a copy. Add it with PassBuilder::execute.

The one way a copy happens inside a frame. The seam only allows a copy outside a pass scope, so a body that calls copy_buffer_to_buffer from a render or compute pass is a scope violation the null backend records — which is why this is a kind of its own rather than a convention about what a compute body may do.

It is otherwise an ordinary pass: it declares what it reads in ResourceState::TransferSrc and what it writes in ResourceState::TransferDst, and the graph emits the transitions around it.

Declare the destination too, even when it is a MemoryLocation::HostReadback staging buffer no pass can bind and nothing else in the frame touches. A destination the graph does not know about gets no barrier, and the access it needs ordering against is not in this frame at all: it is the previous write to the same buffer, one turn of a ring ago, in another submission. That is a write-after-write with write_barriers: 0, and it is the bug crcbl_render::cull_stats shipped and this sentence exists to stop repeating — import it with what the last frame left it in, exactly as every other cross-frame resource here is imported.

Source

pub fn pass_count(&self) -> usize

How many passes have been declared.

Source

pub fn image_facts( &self, image: ImageId, ) -> Option<(Format, (u32, u32), Option<ImageUsage>)>

What this graph knows about image before anything is realised: its format, its extent, and — for a transient only — the usage it will be created with. None for an id this graph never issued.

For a pass that has to refuse a source when it is declared rather than let the device refuse the copy at execution: crcbl_render::sprite_pass’s atlas copies check a rendered image against the slot it is copied into here. An import carries no usage, so the second half of the answer is the importer’s to have got right.

Source

pub fn compile( self, pool: &TransientPool, ) -> Result<CompiledGraph<'a>, GraphError>

Turns declarations into an ordered pass list with exact barriers.

Pure: no device, no allocation of GPU memory, no side effects. See the module docs for why that split exists.

pool is read, never touched: it is the same TransientPool CompiledGraph::execute will realise against, and the only thing asked of it is what it left each physical transient in last frame. That is what lets the first barrier of a frame carry a source scope covering the previous frame’s writes rather than Undefined, which covers nothing — see the module docs. Passing a pool the graph will not execute against is the one way to get this wrong, which is why the parameter is the pool itself rather than a detachable snapshot of it.

§Errors

GraphError for a graph that cannot be executed as written — conflicting accesses within one pass, a render pass with no attachments or with attachments of different sizes, a transient nothing uses, or two imports of one handle that disagree about what they imported.

Trait Implementations§

Source§

impl Debug for RenderGraph<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for RenderGraph<'a>

§

impl<'a> !Send for RenderGraph<'a>

§

impl<'a> !Sync for RenderGraph<'a>

§

impl<'a> !UnwindSafe for RenderGraph<'a>

§

impl<'a> Forget for RenderGraph<'a>

§

impl<'a> Freeze for RenderGraph<'a>

§

impl<'a> Move for RenderGraph<'a>

§

impl<'a> Unpin for RenderGraph<'a>

§

impl<'a> UnsafeUnpin for RenderGraph<'a>

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<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, 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.