Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoskey committed Jun 3, 2024
1 parent 6fa17ec commit db9d2e7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
52 changes: 37 additions & 15 deletions crates/bevy_render_graph/src/std/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{

use super::SrcDst;

///Performs a copy operation between two textures which must be of the same size and format.
pub fn copy_texture_to_texture<'g>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Texture>,
Expand All @@ -37,6 +38,9 @@ pub fn copy_texture_to_texture<'g>(
);
}

///Performs a copy operation between a texture and a buffer. The copy must not overrun the
///destination buffer. If `layout` is `None` the graph will check if the buffer has an associated
///`ImageDataLayout` in its metadata. If not, the function will `panic!`
pub fn copy_texture_to_buffer<'g>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Texture, Buffer>,
Expand All @@ -48,7 +52,7 @@ pub fn copy_texture_to_buffer<'g>(
let size = graph.meta(src_dst.src).size;
let layout = layout
.or(graph.meta(src_dst.dst).layout)
.expect("ImageDataLayout not provided");
.expect("ImageDataLayout not provided for copy operation");

graph.add_node(
Some("copy_texture_to_buffer".into()),
Expand All @@ -66,6 +70,9 @@ pub fn copy_texture_to_buffer<'g>(
);
}

///Performs a copy operation between a texture and a buffer. The copy must not overrun the
///destination texture. If `layout` is `None` the graph will check if the buffer has an associated
///`ImageDataLayout` in its metadata. If not, the function will `panic!`
pub fn copy_buffer_to_texture<'g>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Buffer, Texture>,
Expand Down Expand Up @@ -95,6 +102,7 @@ pub fn copy_buffer_to_texture<'g>(
);
}

///Performs a copy operation between two buffers. The copy must not overrun the destination buffer.
pub fn copy_buffer_to_buffer<'g>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Buffer>,
Expand All @@ -120,48 +128,62 @@ pub fn copy_buffer_to_buffer<'g>(
);
}

pub trait CopyTo<Dst: UsagesRenderResource>: UsagesRenderResource {
fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Dst>);
///Denotes a resource whose data can be copied to others of type `Dst`
pub trait CopyResource<Dst: UsagesRenderResource>: UsagesRenderResource {
///Perfoms a copy from a resource of type `Self` to a resource of type `Dst` in the render

Check warning on line 133 in crates/bevy_render_graph/src/std/copy.rs

View workflow job for this annotation

GitHub Actions / typos

"Perfoms" should be "Performs".
///graph
fn copy_resource<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Dst>);
}

impl CopyTo<Texture> for Texture {
fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) {
impl CopyResource<Texture> for Texture {
fn copy_resource<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) {
copy_texture_to_texture(graph, src_dst);
}
}

impl CopyTo<Buffer> for Texture {
fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Buffer>) {
impl CopyResource<Buffer> for Texture {
fn copy_resource<'g>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Self, Buffer>,
) {
copy_texture_to_buffer(graph, src_dst, None);
}
}

impl CopyTo<Texture> for Buffer {
fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Texture>) {
impl CopyResource<Texture> for Buffer {
fn copy_resource<'g>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Self, Texture>,
) {
copy_buffer_to_texture(graph, src_dst, None);
}
}

impl CopyTo<Buffer> for Buffer {
fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) {
impl CopyResource<Buffer> for Buffer {
fn copy_resource<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) {
copy_buffer_to_buffer(graph, src_dst);
}
}

pub fn copy_to<'g, Src: CopyTo<Dst>, Dst: UsagesRenderResource>(
///Performs a copy operation between two resources. If copying between a texture and a buffer (or
///vice-versa) the buffer must have been created with an associated `ImageDataLayout` in its
///metadata.
pub fn copy<'g, Src: CopyResource<Dst>, Dst: UsagesRenderResource>(
graph: &mut RenderGraphBuilder<'_, 'g>,
src_dst: SrcDst<'g, Src, Dst>,
) {
CopyTo::copy_to(graph, src_dst);
CopyResource::copy_resource(graph, src_dst);
}

pub fn clone<'g, R: CopyTo<R>>(
///Clones a resource by creating a new resource from the original's metadata, and performing a copy
///from the original resource to the new one.
pub fn clone<'g, R: CopyResource<R>>(
graph: &mut RenderGraphBuilder<'_, 'g>,
resource: RenderHandle<'g, R>,
) -> RenderHandle<'g, R> {
let meta = graph.meta(resource).clone();
let new_resource = graph.new_resource(meta);
copy_to(
copy(
graph,
SrcDst {
src: resource,
Expand Down
11 changes: 11 additions & 0 deletions crates/bevy_render_graph/src/std/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use bevy_app::{PluginGroup, PluginGroupBuilder};

mod builder;
mod copy;
mod fullscreen;
Expand All @@ -9,3 +11,12 @@ pub use copy::*;
pub use fullscreen::*;
pub use misc::*;
pub use swap::*;

///A set of minimal plugins that setup assets and behavior for the graph standard library.
pub struct DefaultRenderGraphPlugins;

impl PluginGroup for DefaultRenderGraphPlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>().add(FullscreenPlugin)
}
}

0 comments on commit db9d2e7

Please sign in to comment.