/// Schedule a GPU copy from one image to another. If dst_image is None, create a copy of the
/// src_image.
Schedule a GPU copy from one image to another. If dst_image is None, create a copy of the
src_image.
Schedule a GPU copy from one image to another . If dst_image is None create a copy of the src_image .
pub fn copy_image_to_image(
        &mut self,
        name: RenderGraphNodeName,
        queue: RenderGraphQueue,
        src_image: RenderGraphImageUsageId,
        dst_image: Option<RenderGraphImageUsageId>,
        params: Option<RafxCmdCopyTextureToTextureParams>,
    ) -> RenderGraphImageUsageId {
        let node = self.add_node(name, queue);
        let array_slices = params.as_ref().map(|x| x.array_slices).flatten();
        let src_image = self.read_copy_src_image(
            node,
            src_image,
            Default::default(),
            RenderGraphImageViewOptions {
                texture_bind_type: None,
                array_slice: array_slices.map(|x| x[0]),
                mip_slice: Some(params.as_ref().map(|x| x.src_mip_level).unwrap_or(0)),
            },
        );
        let dst_image_view_options = RenderGraphImageViewOptions {
            texture_bind_type: None,
            array_slice: array_slices.map(|x| x[1]),
            mip_slice: Some(params.as_ref().map(|x| x.dst_mip_level).unwrap_or(0)),
        };
        let dst_image = if let Some(dst_image) = dst_image {
            self.write_copy_dst_image(node, dst_image, Default::default(), dst_image_view_options)
        } else {
            // This is a combination of create_storage_image() and write_copy_dst_image()
            let dst_image = self.add_image_create(node, Default::default(), dst_image_view_options);
            self.node_mut(node).copy_dst_image_writes.push(dst_image);
            dst_image
        };
        self.nodes[node.0].image_copies.push(RenderGraphImageCopy {
            input: src_image,
            output: dst_image,
            constraint: Default::default(),
        });
        self.set_callback(node, move |args| {
            let src = args.graph_context.image_view(src_image).unwrap();
            let dst = args.graph_context.image_view(dst_image).unwrap();
            let params = params.clone().unwrap_or_else(|| {
                let src_size = src.get_raw().image.get_raw().image.texture_def().extents;
                let dst_size = dst.get_raw().image.get_raw().image.texture_def().extents;
                assert_eq!(src_size, dst_size);
                RafxCmdCopyTextureToTextureParams {
                    src_offset: Default::default(),
                    dst_offset: Default::default(),
                    extents: src_size,
                    src_mip_level: 0,
                    dst_mip_level: 0,
                    array_slices: None,
                }
            });
            args.command_buffer.cmd_copy_texture_to_texture(
                &src.get_raw().image.get_raw().image,
                &dst.get_raw().image.get_raw().image,
                &params,
            )?;
            Ok(())
        });
        dst_image
    }
pub fn copy_image_to_image ( & mut self , name : RenderGraphNodeName , queue : RenderGraphQueue , src_image : RenderGraphImageUsageId , dst_image : Option < RenderGraphImageUsageId > , params : Option < RafxCmdCopyTextureToTextureParams > , ) -> RenderGraphImageUsageId { let node = self . add_node ( name , queue ) ; let array_slices = params . as_ref ( ) . map ( | x | x . array_slices ) . flatten ( ) ; let src_image = self . read_copy_src_image ( node , src_image , Default :: default ( ) , RenderGraphImageViewOptions { texture_bind_type : None , array_slice : array_slices . map ( | x | x [ 0 ] ) , mip_slice : Some ( params . as_ref ( ) . map ( | x | x . src_mip_level ) . unwrap_or ( 0 ) ) , } , ) ; let dst_image_view_options = RenderGraphImageViewOptions { texture_bind_type : None , array_slice : array_slices . map ( | x | x [ 1 ] ) , mip_slice : Some ( params . as_ref ( ) . map ( | x | x . dst_mip_level ) . unwrap_or ( 0 ) ) , } ; let dst_image = if let Some ( dst_image ) = dst_image { self . write_copy_dst_image ( node , dst_image , Default :: default ( ) , dst_image_view_options ) } else { // This is a combination of create_storage_image() and write_copy_dst_image() let dst_image = self . add_image_create ( node , Default :: default ( ) , dst_image_view_options ) ; self . node_mut ( node ) . copy_dst_image_writes . push ( dst_image ) ; dst_image } ; self . nodes [ node . 0 ] . image_copies . push ( RenderGraphImageCopy { input : src_image , output : dst_image , constraint : Default :: default ( ) , } ) ; self . set_callback ( node , move | args | { let src = args . graph_context . image_view ( src_image ) . unwrap ( ) ; let dst = args . graph_context . image_view ( dst_image ) . unwrap ( ) ; let params = params . clone ( ) . unwrap_or_else ( | | { let src_size = src . get_raw ( ) . image . get_raw ( ) . image . texture_def ( ) . extents ; let dst_size = dst . get_raw ( ) . image . get_raw ( ) . image . texture_def ( ) . extents ; assert_eq ! ( src_size dst_size ) ; RafxCmdCopyTextureToTextureParams { src_offset : Default :: default ( ) , dst_offset : Default :: default ( ) , extents : src_size , src_mip_level : 0 , dst_mip_level : 0 , array_slices : None , } } ) ; args . command_buffer . cmd_copy_texture_to_texture ( & src . get_raw ( ) . image . get_raw ( ) . image , & dst . get_raw ( ) . image . get_raw ( ) . image , & params , ) ? ; Ok ( ( ) ) } ) ; dst_image }
Schedule a GPU copy from one image to another.
Schedule a GPU copy from one image to another .
&mut self
name
RenderGraphNodeName
queue
RenderGraphQueue
src_image
RenderGraphImageUsageId
dst_image
Option<RenderGraphImageUsageId>
params
Option<RafxCmdCopyTextureToTextureParams>