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>(
encoder, src, src_offset, dst, dst_offset, size,
),
trace::Command::CopyBufferToTexture {
src,
src_layout,
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::CopyBufferToTexture { src, dst, size } => {
self.command_encoder_copy_buffer_to_texture::<B>(encoder, &src, &dst, &size)
}
trace::Command::CopyTextureToBuffer { src, dst, size } => {
self.command_encoder_copy_texture_to_buffer::<B>(encoder, &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 {
commands,
@ -442,7 +424,7 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
size,
} => {
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) => {
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;
#[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)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[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>(
&self,
command_encoder_id: CommandEncoderId,
source: BufferId,
source_layout: &TextureDataLayout,
source: &BufferCopyView,
destination: &TextureCopyView,
copy_size: Extent3d,
copy_size: &Extent3d,
) {
let hub = B::hub(self);
let mut token = Token::root();
@ -161,18 +168,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
#[cfg(feature = "trace")]
match cmb.commands {
Some(ref mut list) => list.push(TraceCommand::CopyBufferToTexture {
src: source,
src_layout: source_layout.clone(),
src: source.clone(),
dst: destination.clone(),
size: copy_size,
size: *copy_size,
}),
None => (),
}
let (src_buffer, src_pending) =
cmb.trackers
.buffers
.use_replace(&*buffer_guard, source, (), BufferUse::COPY_SRC);
let (src_buffer, src_pending) = cmb.trackers.buffers.use_replace(
&*buffer_guard,
source.buffer,
(),
BufferUse::COPY_SRC,
);
assert!(src_buffer.usage.contains(BufferUsage::COPY_SRC));
let src_barriers = src_pending.map(|pending| pending.into_hal(src_buffer));
@ -189,18 +197,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.surface_desc()
.bits as u32
/ 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!(
source_layout.bytes_per_row % bytes_per_texel,
source.layout.bytes_per_row % bytes_per_texel,
0,
"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
);
let region = hal::command::BufferImageCopy {
buffer_offset: source_layout.offset,
buffer_offset: source.layout.offset,
buffer_width,
buffer_height: source_layout.rows_per_image,
buffer_height: source.layout.rows_per_image,
image_layers: dst_layers,
image_offset: dst_offset,
image_extent: conv::map_extent(copy_size, dst_texture.dimension),
@ -225,9 +233,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self,
command_encoder_id: CommandEncoderId,
source: &TextureCopyView,
destination: BufferId,
destination_layout: &TextureDataLayout,
copy_size: Extent3d,
destination: &BufferCopyView,
copy_size: &Extent3d,
) {
let hub = B::hub(self);
let mut token = Token::root();
@ -241,9 +248,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
match cmb.commands {
Some(ref mut list) => list.push(TraceCommand::CopyTextureToBuffer {
src: source.clone(),
dst: destination,
dst_layout: destination_layout.clone(),
size: copy_size,
dst: destination.clone(),
size: *copy_size,
}),
None => (),
}
@ -261,10 +267,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);
let src_barriers = src_pending.map(|pending| pending.into_hal(src_texture));
let (dst_buffer, dst_barriers) =
cmb.trackers
.buffers
.use_replace(&*buffer_guard, destination, (), BufferUse::COPY_DST);
let (dst_buffer, dst_barriers) = cmb.trackers.buffers.use_replace(
&*buffer_guard,
destination.buffer,
(),
BufferUse::COPY_DST,
);
assert!(
dst_buffer.usage.contains(BufferUsage::COPY_DST),
"Destination buffer usage {:?} must contain usage flag COPY_DST",
@ -276,18 +284,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.surface_desc()
.bits as u32
/ 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!(
destination_layout.bytes_per_row % bytes_per_texel,
destination.layout.bytes_per_row % bytes_per_texel,
0,
"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
);
let region = hal::command::BufferImageCopy {
buffer_offset: destination_layout.offset,
buffer_offset: destination.layout.offset,
buffer_width,
buffer_height: destination_layout.rows_per_image,
buffer_height: destination.layout.rows_per_image,
image_layers: src_layers,
image_offset: src_offset,
image_extent: conv::map_extent(copy_size, src_texture.dimension),
@ -313,7 +321,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
command_encoder_id: CommandEncoderId,
source: &TextureCopyView,
destination: &TextureCopyView,
copy_size: Extent3d,
copy_size: &Extent3d,
) {
let hub = B::hub(self);
let mut token = Token::root();
@ -334,7 +342,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Some(ref mut list) => list.push(TraceCommand::CopyTextureToTexture {
src: source.clone(),
dst: destination.clone(),
size: copy_size,
size: *copy_size,
}),
None => (),
}

View File

@ -129,7 +129,7 @@ pub fn map_shader_stage_flags(shader_stage_flags: wgt::ShaderStage) -> hal::pso:
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 {
width: extent.width,
height: extent.height,

View File

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

View File

@ -2,7 +2,10 @@
* 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/. */
use crate::{command::TextureCopyView, id};
use crate::{
command::{BufferCopyView, TextureCopyView},
id,
};
#[cfg(feature = "trace")]
use std::io::Write as _;
use std::ops::Range;
@ -186,15 +189,13 @@ pub enum Command {
size: wgt::BufferAddress,
},
CopyBufferToTexture {
src: id::BufferId,
src_layout: wgt::TextureDataLayout,
src: BufferCopyView,
dst: TextureCopyView,
size: wgt::Extent3d,
},
CopyTextureToBuffer {
src: TextureCopyView,
dst: id::BufferId,
dst_layout: wgt::TextureDataLayout,
dst: BufferCopyView,
size: wgt::Extent3d,
},
CopyTextureToTexture {