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;
|
2021-04-02 09:47:57 -04:00
|
|
|
use deno_core::error::null_opbuf;
|
2021-03-01 05:31:13 -05:00
|
|
|
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-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 WebGpuComputePass(
|
2021-03-01 05:31:13 -05:00
|
|
|
pub(crate) RefCell<wgpu_core::command::ComputePass>,
|
|
|
|
);
|
2021-03-25 14:17:37 -04:00
|
|
|
impl Resource for WebGpuComputePass {
|
2021-03-01 05:31:13 -05:00
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPUComputePass".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassSetPipelineArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
pipeline: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_set_pipeline(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassSetPipelineArgs,
|
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 compute_pipeline_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::pipeline::WebGpuComputePipeline>(args.pipeline)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_set_pipeline(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
compute_pipeline_resource.0,
|
|
|
|
);
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassDispatchArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
x: u32,
|
|
|
|
y: u32,
|
|
|
|
z: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_dispatch(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassDispatchArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
args.x,
|
|
|
|
args.y,
|
|
|
|
args.z,
|
|
|
|
);
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassDispatchIndirectArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
indirect_buffer: u32,
|
|
|
|
indirect_offset: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_dispatch_indirect(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassDispatchIndirectArgs,
|
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 buffer_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch_indirect(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
buffer_resource.0,
|
|
|
|
args.indirect_offset,
|
|
|
|
);
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassBeginPipelineStatisticsQueryArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
query_set: u32,
|
|
|
|
query_index: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassBeginPipelineStatisticsQueryArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
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-06 10:48:45 -04:00
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_begin_pipeline_statistics_query(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
query_set_resource.0,
|
|
|
|
args.query_index,
|
|
|
|
);
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassEndPipelineStatisticsQueryArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_end_pipeline_statistics_query(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassEndPipelineStatisticsQueryArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-05-06 10:48:45 -04:00
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_end_pipeline_statistics_query(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
);
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassWriteTimestampArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
query_set: u32,
|
|
|
|
query_index: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_write_timestamp(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassWriteTimestampArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
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-06 10:48:45 -04:00
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_write_timestamp(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
query_set_resource.0,
|
|
|
|
args.query_index,
|
|
|
|
);
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassEndPassArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_end_pass(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassEndPassArgs,
|
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::<super::command_encoder::WebGpuCommandEncoder>(
|
2021-03-01 05:31:13 -05:00
|
|
|
args.command_encoder_rid,
|
|
|
|
)
|
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let command_encoder = command_encoder_resource.0;
|
|
|
|
let compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.take::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let compute_pass = &compute_pass_resource.0.borrow();
|
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_run_compute_pass(
|
|
|
|
command_encoder,
|
|
|
|
compute_pass
|
|
|
|
))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassSetBindGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
index: u32,
|
|
|
|
bind_group: u32,
|
|
|
|
dynamic_offsets_data: Option<Vec<u32>>,
|
|
|
|
dynamic_offsets_data_start: usize,
|
|
|
|
dynamic_offsets_data_length: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_set_bind_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassSetBindGroupArgs,
|
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 bind_group_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_set_bind_group(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
args.index,
|
|
|
|
bind_group_resource.0,
|
|
|
|
match args.dynamic_offsets_data {
|
|
|
|
Some(data) => data.as_ptr(),
|
|
|
|
None => {
|
2021-04-02 09:47:57 -04:00
|
|
|
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
|
|
let (prefix, data, suffix) = zero_copy.align_to::<u32>();
|
2021-03-01 05:31:13 -05:00
|
|
|
assert!(prefix.is_empty());
|
|
|
|
assert!(suffix.is_empty());
|
|
|
|
data[args.dynamic_offsets_data_start..].as_ptr()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
args.dynamic_offsets_data_length,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassPushDebugGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
group_label: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_push_debug_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassPushDebugGroupArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let label = std::ffi::CString::new(args.group_label).unwrap();
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_push_debug_group(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
label.as_ptr(),
|
|
|
|
0, // wgpu#975
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassPopDebugGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_pop_debug_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassPopDebugGroupArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_pop_debug_group(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
);
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ComputePassInsertDebugMarkerArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
compute_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
marker_label: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_compute_pass_insert_debug_marker(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: ComputePassInsertDebugMarkerArgs,
|
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 compute_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let label = std::ffi::CString::new(args.marker_label).unwrap();
|
|
|
|
wgpu_core::command::compute_ffi::wgpu_compute_pass_insert_debug_marker(
|
|
|
|
&mut compute_pass_resource.0.borrow_mut(),
|
|
|
|
label.as_ptr(),
|
|
|
|
0, // wgpu#975
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
Ok(WebGpuResult::empty())
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|