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>
impl<'a> RenderGraph<'a>
Sourcepub fn new(queue: Handle<Queue>) -> RenderGraph<'a>
pub fn new(queue: Handle<Queue>) -> RenderGraph<'a>
An empty graph whose passes default to queue.
Sourcepub fn create_image(
&mut self,
label: impl Into<String>,
desc: TransientImageDesc,
) -> ImageId
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.
Sourcepub fn create_buffer(
&mut self,
label: impl Into<String>,
desc: TransientBufferDesc,
) -> BufferId
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.
Sourcepub fn import_image(
&mut self,
label: impl Into<String>,
imported: ImportedImage,
) -> ImageId
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.
Sourcepub fn import_buffer(
&mut self,
label: impl Into<String>,
imported: ImportedBuffer,
) -> BufferId
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.
Sourcepub fn add_render_pass(
&mut self,
label: impl Into<String>,
) -> PassBuilder<'_, 'a>
pub fn add_render_pass( &mut self, label: impl Into<String>, ) -> PassBuilder<'_, 'a>
Starts declaring a render pass. Add it with
PassBuilder::execute.
Sourcepub fn add_compute_pass(
&mut self,
label: impl Into<String>,
) -> PassBuilder<'_, 'a>
pub fn add_compute_pass( &mut self, label: impl Into<String>, ) -> PassBuilder<'_, 'a>
Starts declaring a compute pass. Add it with
PassBuilder::execute.
Sourcepub fn add_copy_pass(&mut self, label: impl Into<String>) -> PassBuilder<'_, 'a>
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.
Sourcepub fn pass_count(&self) -> usize
pub fn pass_count(&self) -> usize
How many passes have been declared.
Sourcepub fn image_facts(
&self,
image: ImageId,
) -> Option<(Format, (u32, u32), Option<ImageUsage>)>
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.
Sourcepub fn compile(
self,
pool: &TransientPool,
) -> Result<CompiledGraph<'a>, GraphError>
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.