use std::borrow::Borrow;
use std::ops::Range;
use super::{CommandBuffer, Level, RawCommandBuffer, Shot};
use crate::memory::{Barrier, Dependencies};
use crate::pso::PipelineStage;
use crate::queue::capability::{Supports, Transfer};
use crate::range::RangeArg;
use crate::Backend;
use crate::{buffer, image};
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BufferCopy {
pub src: buffer::Offset,
pub dst: buffer::Offset,
pub size: buffer::Offset,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ImageCopy {
pub src_subresource: image::SubresourceLayers,
pub src_offset: image::Offset,
pub dst_subresource: image::SubresourceLayers,
pub dst_offset: image::Offset,
pub extent: image::Extent,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BufferImageCopy {
pub buffer_offset: buffer::Offset,
pub buffer_width: u32,
pub buffer_height: u32,
pub image_layers: image::SubresourceLayers,
pub image_offset: image::Offset,
pub image_extent: image::Extent,
}
impl<B: Backend, C: Supports<Transfer>, S: Shot, L: Level> CommandBuffer<B, C, S, L> {
pub unsafe fn pipeline_barrier<'i, T>(
&mut self,
stages: Range<PipelineStage>,
dependencies: Dependencies,
barriers: T,
) where
T: IntoIterator,
T::Item: Borrow<Barrier<'i, B>>,
{
self.raw.pipeline_barrier(stages, dependencies, barriers)
}
pub unsafe fn fill_buffer<R>(&mut self, buffer: &B::Buffer, range: R, data: u32)
where
R: RangeArg<buffer::Offset>,
{
self.raw.fill_buffer(buffer, range, data)
}
pub unsafe fn copy_buffer<T>(&mut self, src: &B::Buffer, dst: &B::Buffer, regions: T)
where
T: IntoIterator,
T::Item: Borrow<BufferCopy>,
{
self.raw.copy_buffer(src, dst, regions)
}
pub unsafe fn update_buffer(
&mut self,
buffer: &B::Buffer,
offset: buffer::Offset,
data: &[u8],
) {
self.raw.update_buffer(buffer, offset, data)
}
pub unsafe fn copy_image<T>(
&mut self,
src: &B::Image,
src_layout: image::Layout,
dst: &B::Image,
dst_layout: image::Layout,
regions: T,
) where
T: IntoIterator,
T::Item: Borrow<ImageCopy>,
{
self.raw
.copy_image(src, src_layout, dst, dst_layout, regions)
}
pub unsafe fn copy_buffer_to_image<T>(
&mut self,
src: &B::Buffer,
dst: &B::Image,
dst_layout: image::Layout,
regions: T,
) where
T: IntoIterator,
T::Item: Borrow<BufferImageCopy>,
{
self.raw.copy_buffer_to_image(src, dst, dst_layout, regions)
}
pub unsafe fn copy_image_to_buffer<T>(
&mut self,
src: &B::Image,
src_layout: image::Layout,
dst: &B::Buffer,
regions: T,
) where
T: IntoIterator,
T::Item: Borrow<BufferImageCopy>,
{
self.raw.copy_image_to_buffer(src, src_layout, dst, regions)
}
}