Bring back BufferCopyView

This commit is contained in:
Dzmitry Malyshau 2020-05-25 10:03:54 -04:00 committed by Dzmitry Malyshau
parent 679dba044b
commit e4659b6d05
5 changed files with 57 additions and 66 deletions

View File

@ -130,32 +130,14 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
} => self.command_encoder_copy_buffer_to_buffer::<B>( } => self.command_encoder_copy_buffer_to_buffer::<B>(
encoder, src, src_offset, dst, dst_offset, size, encoder, src, src_offset, dst, dst_offset, size,
), ),
trace::Command::CopyBufferToTexture { trace::Command::CopyBufferToTexture { src, dst, size } => {
src, self.command_encoder_copy_buffer_to_texture::<B>(encoder, &src, &dst, &size)
src_layout, }
dst, trace::Command::CopyTextureToBuffer { src, dst, size } => {
size, self.command_encoder_copy_texture_to_buffer::<B>(encoder, &src, &dst, &size)
} => self.command_encoder_copy_buffer_to_texture::<B>( }
encoder,
src,
&src_layout,
&dst,
size,
),
trace::Command::CopyTextureToBuffer {
src,
dst,
dst_layout,
size,
} => self.command_encoder_copy_texture_to_buffer::<B>(
encoder,
&src,
dst,
&dst_layout,
size,
),
trace::Command::CopyTextureToTexture { src, dst, size } => { trace::Command::CopyTextureToTexture { src, dst, size } => {
self.command_encoder_copy_texture_to_texture::<B>(encoder, &src, &dst, size) self.command_encoder_copy_texture_to_texture::<B>(encoder, &src, &dst, &size)
} }
trace::Command::RunComputePass { trace::Command::RunComputePass {
commands, commands,
@ -442,7 +424,7 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
size, size,
} => { } => {
let bin = std::fs::read(dir.join(data)).unwrap(); let bin = std::fs::read(dir.join(data)).unwrap();
self.queue_write_texture::<B>(device, &to, &bin, &layout, size); self.queue_write_texture::<B>(device, &to, &bin, &layout, &size);
} }
A::Submit(_index, commands) => { A::Submit(_index, commands) => {
let encoder = self.device_create_command_encoder::<B>( let encoder = self.device_create_command_encoder::<B>(

View File

@ -19,6 +19,14 @@ use std::iter;
pub(crate) const BITS_PER_BYTE: u32 = 8; pub(crate) const BITS_PER_BYTE: u32 = 8;
#[derive(Clone, Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct BufferCopyView {
pub buffer: BufferId,
pub layout: TextureDataLayout,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))] #[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))] #[cfg_attr(feature = "replay", derive(serde::Deserialize))]
@ -145,10 +153,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn command_encoder_copy_buffer_to_texture<B: GfxBackend>( pub fn command_encoder_copy_buffer_to_texture<B: GfxBackend>(
&self, &self,
command_encoder_id: CommandEncoderId, command_encoder_id: CommandEncoderId,
source: BufferId, source: &BufferCopyView,
source_layout: &TextureDataLayout,
destination: &TextureCopyView, destination: &TextureCopyView,
copy_size: Extent3d, copy_size: &Extent3d,
) { ) {
let hub = B::hub(self); let hub = B::hub(self);
let mut token = Token::root(); let mut token = Token::root();
@ -161,18 +168,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
match cmb.commands { match cmb.commands {
Some(ref mut list) => list.push(TraceCommand::CopyBufferToTexture { Some(ref mut list) => list.push(TraceCommand::CopyBufferToTexture {
src: source, src: source.clone(),
src_layout: source_layout.clone(),
dst: destination.clone(), dst: destination.clone(),
size: copy_size, size: *copy_size,
}), }),
None => (), None => (),
} }
let (src_buffer, src_pending) = let (src_buffer, src_pending) = cmb.trackers.buffers.use_replace(
cmb.trackers &*buffer_guard,
.buffers source.buffer,
.use_replace(&*buffer_guard, source, (), BufferUse::COPY_SRC); (),
BufferUse::COPY_SRC,
);
assert!(src_buffer.usage.contains(BufferUsage::COPY_SRC)); assert!(src_buffer.usage.contains(BufferUsage::COPY_SRC));
let src_barriers = src_pending.map(|pending| pending.into_hal(src_buffer)); let src_barriers = src_pending.map(|pending| pending.into_hal(src_buffer));
@ -189,18 +197,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.surface_desc() .surface_desc()
.bits as u32 .bits as u32
/ BITS_PER_BYTE; / BITS_PER_BYTE;
let buffer_width = source_layout.bytes_per_row / bytes_per_texel; let buffer_width = source.layout.bytes_per_row / bytes_per_texel;
assert_eq!( assert_eq!(
source_layout.bytes_per_row % bytes_per_texel, source.layout.bytes_per_row % bytes_per_texel,
0, 0,
"Source bytes per row ({}) must be a multiple of bytes per texel ({})", "Source bytes per row ({}) must be a multiple of bytes per texel ({})",
source_layout.bytes_per_row, source.layout.bytes_per_row,
bytes_per_texel bytes_per_texel
); );
let region = hal::command::BufferImageCopy { let region = hal::command::BufferImageCopy {
buffer_offset: source_layout.offset, buffer_offset: source.layout.offset,
buffer_width, buffer_width,
buffer_height: source_layout.rows_per_image, buffer_height: source.layout.rows_per_image,
image_layers: dst_layers, image_layers: dst_layers,
image_offset: dst_offset, image_offset: dst_offset,
image_extent: conv::map_extent(copy_size, dst_texture.dimension), image_extent: conv::map_extent(copy_size, dst_texture.dimension),
@ -225,9 +233,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
command_encoder_id: CommandEncoderId, command_encoder_id: CommandEncoderId,
source: &TextureCopyView, source: &TextureCopyView,
destination: BufferId, destination: &BufferCopyView,
destination_layout: &TextureDataLayout, copy_size: &Extent3d,
copy_size: Extent3d,
) { ) {
let hub = B::hub(self); let hub = B::hub(self);
let mut token = Token::root(); let mut token = Token::root();
@ -241,9 +248,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
match cmb.commands { match cmb.commands {
Some(ref mut list) => list.push(TraceCommand::CopyTextureToBuffer { Some(ref mut list) => list.push(TraceCommand::CopyTextureToBuffer {
src: source.clone(), src: source.clone(),
dst: destination, dst: destination.clone(),
dst_layout: destination_layout.clone(), size: *copy_size,
size: copy_size,
}), }),
None => (), None => (),
} }
@ -261,10 +267,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
); );
let src_barriers = src_pending.map(|pending| pending.into_hal(src_texture)); let src_barriers = src_pending.map(|pending| pending.into_hal(src_texture));
let (dst_buffer, dst_barriers) = let (dst_buffer, dst_barriers) = cmb.trackers.buffers.use_replace(
cmb.trackers &*buffer_guard,
.buffers destination.buffer,
.use_replace(&*buffer_guard, destination, (), BufferUse::COPY_DST); (),
BufferUse::COPY_DST,
);
assert!( assert!(
dst_buffer.usage.contains(BufferUsage::COPY_DST), dst_buffer.usage.contains(BufferUsage::COPY_DST),
"Destination buffer usage {:?} must contain usage flag COPY_DST", "Destination buffer usage {:?} must contain usage flag COPY_DST",
@ -276,18 +284,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.surface_desc() .surface_desc()
.bits as u32 .bits as u32
/ BITS_PER_BYTE; / BITS_PER_BYTE;
let buffer_width = destination_layout.bytes_per_row / bytes_per_texel; let buffer_width = destination.layout.bytes_per_row / bytes_per_texel;
assert_eq!( assert_eq!(
destination_layout.bytes_per_row % bytes_per_texel, destination.layout.bytes_per_row % bytes_per_texel,
0, 0,
"Destination bytes per row ({}) must be a multiple of bytes per texel ({})", "Destination bytes per row ({}) must be a multiple of bytes per texel ({})",
destination_layout.bytes_per_row, destination.layout.bytes_per_row,
bytes_per_texel bytes_per_texel
); );
let region = hal::command::BufferImageCopy { let region = hal::command::BufferImageCopy {
buffer_offset: destination_layout.offset, buffer_offset: destination.layout.offset,
buffer_width, buffer_width,
buffer_height: destination_layout.rows_per_image, buffer_height: destination.layout.rows_per_image,
image_layers: src_layers, image_layers: src_layers,
image_offset: src_offset, image_offset: src_offset,
image_extent: conv::map_extent(copy_size, src_texture.dimension), image_extent: conv::map_extent(copy_size, src_texture.dimension),
@ -313,7 +321,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
command_encoder_id: CommandEncoderId, command_encoder_id: CommandEncoderId,
source: &TextureCopyView, source: &TextureCopyView,
destination: &TextureCopyView, destination: &TextureCopyView,
copy_size: Extent3d, copy_size: &Extent3d,
) { ) {
let hub = B::hub(self); let hub = B::hub(self);
let mut token = Token::root(); let mut token = Token::root();
@ -334,7 +342,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Some(ref mut list) => list.push(TraceCommand::CopyTextureToTexture { Some(ref mut list) => list.push(TraceCommand::CopyTextureToTexture {
src: source.clone(), src: source.clone(),
dst: destination.clone(), dst: destination.clone(),
size: copy_size, size: *copy_size,
}), }),
None => (), None => (),
} }

View File

@ -129,7 +129,7 @@ pub fn map_shader_stage_flags(shader_stage_flags: wgt::ShaderStage) -> hal::pso:
value value
} }
pub fn map_extent(extent: wgt::Extent3d, dim: wgt::TextureDimension) -> hal::image::Extent { pub fn map_extent(extent: &wgt::Extent3d, dim: wgt::TextureDimension) -> hal::image::Extent {
hal::image::Extent { hal::image::Extent {
width: extent.width, width: extent.width,
height: extent.height, height: extent.height,

View File

@ -193,7 +193,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
destination: &TextureCopyView, destination: &TextureCopyView,
data: &[u8], data: &[u8],
data_layout: &wgt::TextureDataLayout, data_layout: &wgt::TextureDataLayout,
size: wgt::Extent3d, size: &wgt::Extent3d,
) { ) {
let hub = B::hub(self); let hub = B::hub(self);
let mut token = Token::root(); let mut token = Token::root();
@ -211,7 +211,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
to: destination.clone(), to: destination.clone(),
data: data_path, data: data_path,
layout: data_layout.clone(), layout: data_layout.clone(),
size, size: *size,
}); });
} }
None => {} None => {}

View File

@ -2,7 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use crate::{command::TextureCopyView, id}; use crate::{
command::{BufferCopyView, TextureCopyView},
id,
};
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
use std::io::Write as _; use std::io::Write as _;
use std::ops::Range; use std::ops::Range;
@ -186,15 +189,13 @@ pub enum Command {
size: wgt::BufferAddress, size: wgt::BufferAddress,
}, },
CopyBufferToTexture { CopyBufferToTexture {
src: id::BufferId, src: BufferCopyView,
src_layout: wgt::TextureDataLayout,
dst: TextureCopyView, dst: TextureCopyView,
size: wgt::Extent3d, size: wgt::Extent3d,
}, },
CopyTextureToBuffer { CopyTextureToBuffer {
src: TextureCopyView, src: TextureCopyView,
dst: id::BufferId, dst: BufferCopyView,
dst_layout: wgt::TextureDataLayout,
size: wgt::Extent3d, size: wgt::Extent3d,
}, },
CopyTextureToTexture { CopyTextureToTexture {