diff options
author | Luca Casonato <hello@lcas.dev> | 2021-08-24 20:32:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-24 20:32:25 +0200 |
commit | 4853be20f2d649842ebc97124d8479c7aad7cc9b (patch) | |
tree | 1be4dcc96c72166b3e1e4f19ee70eb791e1304aa /ext/webgpu/queue.rs | |
parent | e10d30c8eaf41ad68b48f21c8d563d192b82afe8 (diff) |
refactor(webgpu): use op interface idiomatically (#11835)
Diffstat (limited to 'ext/webgpu/queue.rs')
-rw-r--r-- | ext/webgpu/queue.rs | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/ext/webgpu/queue.rs b/ext/webgpu/queue.rs index da1f7a1ad..ddb653fca 100644 --- a/ext/webgpu/queue.rs +++ b/ext/webgpu/queue.rs @@ -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() )) } |