2021-03-01 05:31:13 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
use deno_core::error::bad_resource_id;
|
|
|
|
use deno_core::error::AnyError;
|
2021-03-19 13:25:37 -04:00
|
|
|
use deno_core::ResourceId;
|
2021-03-01 05:31:13 -05:00
|
|
|
use deno_core::ZeroCopyBuf;
|
|
|
|
use deno_core::{OpState, Resource};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use std::borrow::Cow;
|
|
|
|
use std::cell::RefCell;
|
2021-05-06 10:48:45 -04:00
|
|
|
use std::num::NonZeroU32;
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
use super::error::WebGpuResult;
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2021-03-25 14:17:37 -04:00
|
|
|
pub(crate) struct WebGpuCommandEncoder(
|
2021-03-01 05:31:13 -05:00
|
|
|
pub(crate) wgpu_core::id::CommandEncoderId,
|
|
|
|
);
|
2021-03-25 14:17:37 -04:00
|
|
|
impl Resource for WebGpuCommandEncoder {
|
2021-03-01 05:31:13 -05:00
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPUCommandEncoder".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-25 14:17:37 -04:00
|
|
|
pub(crate) struct WebGpuCommandBuffer(
|
2021-03-01 05:31:13 -05:00
|
|
|
pub(crate) wgpu_core::id::CommandBufferId,
|
|
|
|
);
|
2021-03-25 14:17:37 -04:00
|
|
|
impl Resource for WebGpuCommandBuffer {
|
2021-03-01 05:31:13 -05:00
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPUCommandBuffer".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn serialize_store_op(store_op: String) -> wgpu_core::command::StoreOp {
|
|
|
|
match store_op.as_str() {
|
|
|
|
"store" => wgpu_core::command::StoreOp::Store,
|
|
|
|
"clear" => wgpu_core::command::StoreOp::Clear,
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CreateCommandEncoderArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
device_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
label: Option<String>,
|
|
|
|
_measure_execution_time: Option<bool>, // not yet implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_create_command_encoder(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CreateCommandEncoderArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let device_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::WebGpuDevice>(args.device_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let device = device_resource.0;
|
|
|
|
|
|
|
|
let descriptor = wgpu_types::CommandEncoderDescriptor {
|
|
|
|
label: args.label.map(Cow::from),
|
|
|
|
};
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_put!(device => instance.device_create_command_encoder(
|
2021-03-01 05:31:13 -05:00
|
|
|
device,
|
|
|
|
&descriptor,
|
|
|
|
std::marker::PhantomData
|
2021-05-03 10:42:59 -04:00
|
|
|
) => state, WebGpuCommandEncoder)
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-03-25 14:17:37 -04:00
|
|
|
pub struct GpuRenderPassColorAttachment {
|
2021-03-01 05:31:13 -05:00
|
|
|
view: u32,
|
|
|
|
resolve_target: Option<u32>,
|
|
|
|
load_op: String,
|
2021-03-25 14:17:37 -04:00
|
|
|
load_value: Option<super::render_pass::GpuColor>,
|
2021-03-01 05:31:13 -05:00
|
|
|
store_op: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-03-25 14:17:37 -04:00
|
|
|
struct GpuRenderPassDepthStencilAttachment {
|
2021-03-01 05:31:13 -05:00
|
|
|
view: u32,
|
|
|
|
depth_load_op: String,
|
|
|
|
depth_load_value: Option<f32>,
|
|
|
|
depth_store_op: String,
|
|
|
|
depth_read_only: Option<bool>,
|
|
|
|
stencil_load_op: String,
|
|
|
|
stencil_load_value: Option<u32>,
|
|
|
|
stencil_store_op: String,
|
|
|
|
stencil_read_only: Option<bool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderBeginRenderPassArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
label: Option<String>,
|
2021-03-25 14:17:37 -04:00
|
|
|
color_attachments: Vec<GpuRenderPassColorAttachment>,
|
|
|
|
depth_stencil_attachment: Option<GpuRenderPassDepthStencilAttachment>,
|
2021-03-01 05:31:13 -05:00
|
|
|
_occlusion_query_set: Option<u32>, // not yet implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_begin_render_pass(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderBeginRenderPassArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
let mut color_attachments = vec![];
|
|
|
|
|
|
|
|
for color_attachment in args.color_attachments {
|
|
|
|
let texture_view_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTextureView>(color_attachment.view)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-06 10:48:45 -04:00
|
|
|
let attachment = wgpu_core::command::RenderPassColorAttachment {
|
|
|
|
view: texture_view_resource.0,
|
2021-03-01 05:31:13 -05:00
|
|
|
resolve_target: color_attachment
|
|
|
|
.resolve_target
|
|
|
|
.map(|rid| {
|
|
|
|
state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTextureView>(rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)
|
|
|
|
})
|
|
|
|
.transpose()?
|
|
|
|
.map(|texture| texture.0),
|
|
|
|
channel: match color_attachment.load_op.as_str() {
|
|
|
|
"load" => wgpu_core::command::PassChannel {
|
|
|
|
load_op: wgpu_core::command::LoadOp::Load,
|
|
|
|
store_op: color_attachment
|
|
|
|
.store_op
|
|
|
|
.map_or(wgpu_core::command::StoreOp::Store, serialize_store_op),
|
|
|
|
clear_value: Default::default(),
|
|
|
|
read_only: false,
|
|
|
|
},
|
|
|
|
"clear" => {
|
|
|
|
let color = color_attachment.load_value.unwrap();
|
|
|
|
wgpu_core::command::PassChannel {
|
|
|
|
load_op: wgpu_core::command::LoadOp::Clear,
|
|
|
|
store_op: color_attachment
|
|
|
|
.store_op
|
|
|
|
.map_or(wgpu_core::command::StoreOp::Store, serialize_store_op),
|
|
|
|
clear_value: wgpu_types::Color {
|
|
|
|
r: color.r,
|
|
|
|
g: color.g,
|
|
|
|
b: color.b,
|
|
|
|
a: color.a,
|
|
|
|
},
|
|
|
|
read_only: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
color_attachments.push(attachment)
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut depth_stencil_attachment = None;
|
|
|
|
|
|
|
|
if let Some(attachment) = args.depth_stencil_attachment {
|
|
|
|
let texture_view_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTextureView>(attachment.view)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
depth_stencil_attachment =
|
2021-05-06 10:48:45 -04:00
|
|
|
Some(wgpu_core::command::RenderPassDepthStencilAttachment {
|
|
|
|
view: texture_view_resource.0,
|
2021-03-01 05:31:13 -05:00
|
|
|
depth: match attachment.depth_load_op.as_str() {
|
|
|
|
"load" => wgpu_core::command::PassChannel {
|
|
|
|
load_op: wgpu_core::command::LoadOp::Load,
|
|
|
|
store_op: serialize_store_op(attachment.depth_store_op),
|
|
|
|
clear_value: 0.0,
|
|
|
|
read_only: attachment.depth_read_only.unwrap_or(false),
|
|
|
|
},
|
|
|
|
"clear" => wgpu_core::command::PassChannel {
|
|
|
|
load_op: wgpu_core::command::LoadOp::Clear,
|
|
|
|
store_op: serialize_store_op(attachment.depth_store_op),
|
|
|
|
clear_value: attachment.depth_load_value.unwrap(),
|
|
|
|
read_only: attachment.depth_read_only.unwrap_or(false),
|
|
|
|
},
|
|
|
|
_ => unreachable!(),
|
|
|
|
},
|
|
|
|
stencil: match attachment.stencil_load_op.as_str() {
|
|
|
|
"load" => wgpu_core::command::PassChannel {
|
|
|
|
load_op: wgpu_core::command::LoadOp::Load,
|
|
|
|
store_op: serialize_store_op(attachment.stencil_store_op),
|
|
|
|
clear_value: 0,
|
|
|
|
read_only: attachment.stencil_read_only.unwrap_or(false),
|
|
|
|
},
|
|
|
|
"clear" => wgpu_core::command::PassChannel {
|
|
|
|
load_op: wgpu_core::command::LoadOp::Clear,
|
|
|
|
store_op: serialize_store_op(attachment.stencil_store_op),
|
|
|
|
clear_value: attachment.stencil_load_value.unwrap(),
|
|
|
|
read_only: attachment.stencil_read_only.unwrap_or(false),
|
|
|
|
},
|
|
|
|
_ => unreachable!(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let descriptor = wgpu_core::command::RenderPassDescriptor {
|
|
|
|
label: args.label.map(Cow::from),
|
|
|
|
color_attachments: Cow::from(color_attachments),
|
|
|
|
depth_stencil_attachment: depth_stencil_attachment.as_ref(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let render_pass = wgpu_core::command::RenderPass::new(
|
|
|
|
command_encoder_resource.0,
|
|
|
|
&descriptor,
|
|
|
|
);
|
|
|
|
|
|
|
|
let rid = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.add(super::render_pass::WebGpuRenderPass(RefCell::new(
|
2021-03-01 05:31:13 -05:00
|
|
|
render_pass,
|
|
|
|
)));
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::rid(rid))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderBeginComputePassArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
label: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_begin_compute_pass(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderBeginComputePassArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
let descriptor = wgpu_core::command::ComputePassDescriptor {
|
|
|
|
label: args.label.map(Cow::from),
|
|
|
|
};
|
|
|
|
|
|
|
|
let compute_pass = wgpu_core::command::ComputePass::new(
|
|
|
|
command_encoder_resource.0,
|
|
|
|
&descriptor,
|
|
|
|
);
|
|
|
|
|
|
|
|
let rid = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.add(super::compute_pass::WebGpuComputePass(RefCell::new(
|
2021-03-01 05:31:13 -05:00
|
|
|
compute_pass,
|
|
|
|
)));
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::rid(rid))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderCopyBufferToBufferArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
source: u32,
|
|
|
|
source_offset: u64,
|
|
|
|
destination: u32,
|
|
|
|
destination_offset: u64,
|
|
|
|
size: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderCopyBufferToBufferArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let source_buffer_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(args.source)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let source_buffer = source_buffer_resource.0;
|
|
|
|
let destination_buffer_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(args.destination)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let destination_buffer = destination_buffer_resource.0;
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_buffer(
|
2021-03-01 05:31:13 -05:00
|
|
|
command_encoder,
|
|
|
|
source_buffer,
|
|
|
|
args.source_offset,
|
|
|
|
destination_buffer,
|
|
|
|
args.destination_offset,
|
|
|
|
args.size
|
2021-05-03 10:42:59 -04:00
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-03-25 14:17:37 -04:00
|
|
|
pub struct GpuImageCopyBuffer {
|
2021-03-01 05:31:13 -05:00
|
|
|
buffer: u32,
|
|
|
|
offset: Option<u64>,
|
|
|
|
bytes_per_row: Option<u32>,
|
|
|
|
rows_per_image: Option<u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-03-25 14:17:37 -04:00
|
|
|
pub struct GpuOrigin3D {
|
2021-03-01 05:31:13 -05:00
|
|
|
pub x: Option<u32>,
|
|
|
|
pub y: Option<u32>,
|
|
|
|
pub z: Option<u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-03-25 14:17:37 -04:00
|
|
|
pub struct GpuImageCopyTexture {
|
2021-03-01 05:31:13 -05:00
|
|
|
pub texture: u32,
|
|
|
|
pub mip_level: Option<u32>,
|
2021-03-25 14:17:37 -04:00
|
|
|
pub origin: Option<GpuOrigin3D>,
|
2021-03-01 05:31:13 -05:00
|
|
|
pub _aspect: Option<String>, // not yet implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderCopyBufferToTextureArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-25 14:17:37 -04:00
|
|
|
source: GpuImageCopyBuffer,
|
|
|
|
destination: GpuImageCopyTexture,
|
|
|
|
copy_size: super::texture::GpuExtent3D,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderCopyBufferToTextureArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let source_buffer_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(args.source.buffer)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let destination_texture_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-06 10:48:45 -04:00
|
|
|
let source = wgpu_core::command::ImageCopyBuffer {
|
2021-03-01 05:31:13 -05:00
|
|
|
buffer: source_buffer_resource.0,
|
2021-05-06 10:48:45 -04:00
|
|
|
layout: wgpu_types::ImageDataLayout {
|
2021-03-01 05:31:13 -05:00
|
|
|
offset: args.source.offset.unwrap_or(0),
|
2021-05-06 10:48:45 -04:00
|
|
|
bytes_per_row: NonZeroU32::new(args.source.bytes_per_row.unwrap_or(0)),
|
|
|
|
rows_per_image: NonZeroU32::new(args.source.rows_per_image.unwrap_or(0)),
|
2021-03-01 05:31:13 -05:00
|
|
|
},
|
|
|
|
};
|
2021-05-06 10:48:45 -04:00
|
|
|
let destination = wgpu_core::command::ImageCopyTexture {
|
2021-03-01 05:31:13 -05:00
|
|
|
texture: destination_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),
|
|
|
|
}),
|
|
|
|
};
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_texture(
|
2021-03-01 05:31:13 -05:00
|
|
|
command_encoder,
|
|
|
|
&source,
|
|
|
|
&destination,
|
|
|
|
&wgpu_types::Extent3d {
|
|
|
|
width: args.copy_size.width.unwrap_or(1),
|
|
|
|
height: args.copy_size.height.unwrap_or(1),
|
2021-05-06 10:48:45 -04:00
|
|
|
depth_or_array_layers: args.copy_size.depth_or_array_layers.unwrap_or(1),
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
2021-05-03 10:42:59 -04:00
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderCopyTextureToBufferArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-25 14:17:37 -04:00
|
|
|
source: GpuImageCopyTexture,
|
|
|
|
destination: GpuImageCopyBuffer,
|
|
|
|
copy_size: super::texture::GpuExtent3D,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderCopyTextureToBufferArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let source_texture_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTexture>(args.source.texture)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let destination_buffer_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(args.destination.buffer)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-06 10:48:45 -04:00
|
|
|
let source = wgpu_core::command::ImageCopyTexture {
|
2021-03-01 05:31:13 -05:00
|
|
|
texture: source_texture_resource.0,
|
|
|
|
mip_level: args.source.mip_level.unwrap_or(0),
|
|
|
|
origin: args.source.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),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
};
|
2021-05-06 10:48:45 -04:00
|
|
|
let destination = wgpu_core::command::ImageCopyBuffer {
|
2021-03-01 05:31:13 -05:00
|
|
|
buffer: destination_buffer_resource.0,
|
2021-05-06 10:48:45 -04:00
|
|
|
layout: wgpu_types::ImageDataLayout {
|
2021-03-01 05:31:13 -05:00
|
|
|
offset: args.destination.offset.unwrap_or(0),
|
2021-05-06 10:48:45 -04:00
|
|
|
bytes_per_row: NonZeroU32::new(
|
|
|
|
args.destination.bytes_per_row.unwrap_or(0),
|
|
|
|
),
|
|
|
|
rows_per_image: NonZeroU32::new(
|
|
|
|
args.destination.rows_per_image.unwrap_or(0),
|
|
|
|
),
|
2021-03-01 05:31:13 -05:00
|
|
|
},
|
|
|
|
};
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_buffer(
|
2021-03-01 05:31:13 -05:00
|
|
|
command_encoder,
|
|
|
|
&source,
|
|
|
|
&destination,
|
|
|
|
&wgpu_types::Extent3d {
|
|
|
|
width: args.copy_size.width.unwrap_or(1),
|
|
|
|
height: args.copy_size.height.unwrap_or(1),
|
2021-05-06 10:48:45 -04:00
|
|
|
depth_or_array_layers: args.copy_size.depth_or_array_layers.unwrap_or(1),
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
2021-05-03 10:42:59 -04:00
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderCopyTextureToTextureArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-25 14:17:37 -04:00
|
|
|
source: GpuImageCopyTexture,
|
|
|
|
destination: GpuImageCopyTexture,
|
|
|
|
copy_size: super::texture::GpuExtent3D,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_copy_texture_to_texture(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderCopyTextureToTextureArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let source_texture_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTexture>(args.source.texture)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let destination_texture_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-06 10:48:45 -04:00
|
|
|
let source = wgpu_core::command::ImageCopyTexture {
|
2021-03-01 05:31:13 -05:00
|
|
|
texture: source_texture_resource.0,
|
|
|
|
mip_level: args.source.mip_level.unwrap_or(0),
|
|
|
|
origin: args.source.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),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
};
|
2021-05-06 10:48:45 -04:00
|
|
|
let destination = wgpu_core::command::ImageCopyTexture {
|
2021-03-01 05:31:13 -05:00
|
|
|
texture: destination_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),
|
|
|
|
}),
|
|
|
|
};
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_texture(
|
2021-03-01 05:31:13 -05:00
|
|
|
command_encoder,
|
|
|
|
&source,
|
|
|
|
&destination,
|
|
|
|
&wgpu_types::Extent3d {
|
|
|
|
width: args.copy_size.width.unwrap_or(1),
|
|
|
|
height: args.copy_size.height.unwrap_or(1),
|
2021-05-06 10:48:45 -04:00
|
|
|
depth_or_array_layers: args.copy_size.depth_or_array_layers.unwrap_or(1),
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
2021-05-03 10:42:59 -04:00
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderPushDebugGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
group_label: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_push_debug_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderPushDebugGroupArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance
|
2021-03-01 05:31:13 -05:00
|
|
|
.command_encoder_push_debug_group(command_encoder, &args.group_label))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderPopDebugGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_pop_debug_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderPopDebugGroupArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderInsertDebugMarkerArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
marker_label: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_insert_debug_marker(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderInsertDebugMarkerArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_insert_debug_marker(
|
2021-03-01 05:31:13 -05:00
|
|
|
command_encoder,
|
|
|
|
&args.marker_label
|
2021-05-03 10:42:59 -04:00
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderWriteTimestampArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
query_set: u32,
|
|
|
|
query_index: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_write_timestamp(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderWriteTimestampArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let query_set_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::WebGpuQuerySet>(args.query_set)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_write_timestamp(
|
|
|
|
command_encoder,
|
|
|
|
query_set_resource.0,
|
|
|
|
args.query_index
|
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderResolveQuerySetArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
query_set: u32,
|
|
|
|
first_query: u32,
|
|
|
|
query_count: u32,
|
|
|
|
destination: u32,
|
|
|
|
destination_offset: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_resolve_query_set(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderResolveQuerySetArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let query_set_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::WebGpuQuerySet>(args.query_set)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let destination_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(args.destination)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_resolve_query_set(
|
|
|
|
command_encoder,
|
|
|
|
query_set_resource.0,
|
|
|
|
args.first_query,
|
|
|
|
args.query_count,
|
|
|
|
destination_resource.0,
|
|
|
|
args.destination_offset
|
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommandEncoderFinishArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
label: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_command_encoder_finish(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CommandEncoderFinishArgs,
|
2021-04-02 09:47:57 -04:00
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let command_encoder_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.take::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
|
|
|
|
let descriptor = wgpu_types::CommandBufferDescriptor {
|
|
|
|
label: args.label.map(Cow::from),
|
|
|
|
};
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_put!(command_encoder => instance.command_encoder_finish(
|
2021-03-01 05:31:13 -05:00
|
|
|
command_encoder,
|
|
|
|
&descriptor
|
2021-05-03 10:42:59 -04:00
|
|
|
) => state, WebGpuCommandBuffer)
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|