refactor(webgpu): use op interface idiomatically (#11835)

This commit is contained in:
Luca Casonato 2021-08-24 20:32:25 +02:00 committed by GitHub
parent e10d30c8ea
commit 4853be20f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1425 additions and 1118 deletions

View file

@ -17,7 +17,7 @@ type WebGpuQueue = super::WebGpuDevice;
#[serde(rename_all = "camelCase")]
pub struct QueueSubmitArgs {
queue_rid: ResourceId,
command_buffers: Vec<u32>,
command_buffers: Vec<ResourceId>,
}
pub fn op_webgpu_queue_submit(
@ -49,16 +49,26 @@ pub fn op_webgpu_queue_submit(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct GpuImageDataLayout {
offset: Option<u64>,
offset: u64,
bytes_per_row: Option<u32>,
rows_per_image: Option<u32>,
}
impl From<GpuImageDataLayout> for wgpu_types::ImageDataLayout {
fn from(layout: GpuImageDataLayout) -> Self {
wgpu_types::ImageDataLayout {
offset: layout.offset,
bytes_per_row: NonZeroU32::new(layout.bytes_per_row.unwrap_or(0)),
rows_per_image: NonZeroU32::new(layout.rows_per_image.unwrap_or(0)),
}
}
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueueWriteBufferArgs {
queue_rid: ResourceId,
buffer: u32,
buffer: ResourceId,
buffer_offset: u64,
data_offset: usize,
size: Option<usize>,
@ -119,39 +129,17 @@ pub fn op_webgpu_write_texture(
let destination = wgpu_core::command::ImageCopyTexture {
texture: texture_resource.0,
mip_level: args.destination.mip_level.unwrap_or(0),
origin: args
.destination
.origin
.map_or(Default::default(), |origin| wgpu_types::Origin3d {
x: origin.x.unwrap_or(0),
y: origin.y.unwrap_or(0),
z: origin.z.unwrap_or(0),
}),
aspect: match args.destination.aspect.as_str() {
"all" => wgpu_types::TextureAspect::All,
"stencil-only" => wgpu_types::TextureAspect::StencilOnly,
"depth-only" => wgpu_types::TextureAspect::DepthOnly,
_ => unreachable!(),
},
};
let data_layout = wgpu_types::ImageDataLayout {
offset: args.data_layout.offset.unwrap_or(0),
bytes_per_row: NonZeroU32::new(args.data_layout.bytes_per_row.unwrap_or(0)),
rows_per_image: NonZeroU32::new(
args.data_layout.rows_per_image.unwrap_or(0),
),
mip_level: args.destination.mip_level,
origin: args.destination.origin.into(),
aspect: args.destination.aspect.into(),
};
let data_layout = args.data_layout.into();
gfx_ok!(queue => instance.queue_write_texture(
queue,
&destination,
&*zero_copy,
&data_layout,
&wgpu_types::Extent3d {
width: args.size.width.unwrap_or(1),
height: args.size.height.unwrap_or(1),
depth_or_array_layers: args.size.depth_or_array_layers.unwrap_or(1),
}
&args.size.into()
))
}