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-07-08 05:07:49 -04:00
|
|
|
use deno_core::error::type_error;
|
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 WebGpuRenderPass(
|
2021-03-01 05:31:13 -05:00
|
|
|
pub(crate) RefCell<wgpu_core::command::RenderPass>,
|
|
|
|
);
|
2021-03-25 14:17:37 -04:00
|
|
|
impl Resource for WebGpuRenderPass {
|
2021-03-01 05:31:13 -05:00
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPURenderPass".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RenderPassSetViewportArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
width: f32,
|
|
|
|
height: f32,
|
|
|
|
min_depth: f32,
|
|
|
|
max_depth: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_set_viewport(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetViewportArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_viewport(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.x,
|
|
|
|
args.y,
|
|
|
|
args.width,
|
|
|
|
args.height,
|
|
|
|
args.min_depth,
|
|
|
|
args.max_depth,
|
|
|
|
);
|
|
|
|
|
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 RenderPassSetScissorRectArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
x: u32,
|
|
|
|
y: u32,
|
|
|
|
width: u32,
|
|
|
|
height: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_set_scissor_rect(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetScissorRectArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_scissor_rect(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.x,
|
|
|
|
args.y,
|
|
|
|
args.width,
|
|
|
|
args.height,
|
|
|
|
);
|
|
|
|
|
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")]
|
2021-03-25 14:17:37 -04:00
|
|
|
pub struct GpuColor {
|
2021-03-01 05:31:13 -05:00
|
|
|
pub r: f64,
|
|
|
|
pub g: f64,
|
|
|
|
pub b: f64,
|
|
|
|
pub a: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-05-06 10:48:45 -04:00
|
|
|
pub struct RenderPassSetBlendConstantArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-25 14:17:37 -04:00
|
|
|
color: GpuColor,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
2021-05-06 10:48:45 -04:00
|
|
|
pub fn op_webgpu_render_pass_set_blend_constant(
|
2021-03-01 05:31:13 -05:00
|
|
|
state: &mut OpState,
|
2021-05-06 10:48:45 -04:00
|
|
|
args: RenderPassSetBlendConstantArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_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::render_ffi::wgpu_render_pass_set_blend_constant(
|
2021-03-01 05:31:13 -05:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
&wgpu_types::Color {
|
|
|
|
r: args.color.r,
|
|
|
|
g: args.color.g,
|
|
|
|
b: args.color.b,
|
|
|
|
a: args.color.a,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
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 RenderPassSetStencilReferenceArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
reference: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_set_stencil_reference(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetStencilReferenceArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_stencil_reference(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.reference,
|
|
|
|
);
|
|
|
|
|
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 RenderPassBeginPipelineStatisticsQueryArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
query_set: u32,
|
|
|
|
query_index: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_begin_pipeline_statistics_query(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassBeginPipelineStatisticsQueryArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_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::render_ffi::wgpu_render_pass_begin_pipeline_statistics_query(
|
|
|
|
&mut render_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 RenderPassEndPipelineStatisticsQueryArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_end_pipeline_statistics_query(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassEndPipelineStatisticsQueryArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_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::render_ffi::wgpu_render_pass_end_pipeline_statistics_query(
|
|
|
|
&mut render_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 RenderPassWriteTimestampArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
query_set: u32,
|
|
|
|
query_index: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_write_timestamp(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassWriteTimestampArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_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::render_ffi::wgpu_render_pass_write_timestamp(
|
|
|
|
&mut render_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 RenderPassExecuteBundlesArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
bundles: Vec<u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_execute_bundles(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassExecuteBundlesArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let mut render_bundle_ids = vec![];
|
|
|
|
|
|
|
|
for rid in &args.bundles {
|
|
|
|
let render_bundle_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::bundle::WebGpuRenderBundle>(*rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
render_bundle_ids.push(render_bundle_resource.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_execute_bundles(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
render_bundle_ids.as_ptr(),
|
|
|
|
args.bundles.len(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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 RenderPassEndPassArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
command_encoder_rid: ResourceId,
|
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_end_pass(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassEndPassArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
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 render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.take::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let render_pass = &render_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_render_pass(command_encoder, render_pass))
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RenderPassSetBindGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_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_render_pass_set_bind_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetBindGroupArgs,
|
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 render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
// I know this might look like it can be easily deduplicated, but it can not
|
|
|
|
// be due to the lifetime of the args.dynamic_offsets_data slice. Because we
|
|
|
|
// need to use a raw pointer here the slice can be freed before the pointer
|
|
|
|
// is used in wgpu_render_pass_set_bind_group. See
|
|
|
|
// https://matrix.to/#/!XFRnMvAfptAHthwBCx:matrix.org/$HgrlhD-Me1DwsGb8UdMu2Hqubgks8s7ILwWRwigOUAg
|
|
|
|
match args.dynamic_offsets_data {
|
|
|
|
Some(data) => unsafe {
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_bind_group(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.index,
|
|
|
|
bind_group_resource.0,
|
|
|
|
data.as_slice().as_ptr(),
|
|
|
|
args.dynamic_offsets_data_length,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
None => {
|
2021-04-23 05:18:32 -04:00
|
|
|
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
2021-04-02 09:47:57 -04:00
|
|
|
let (prefix, data, suffix) = unsafe { zero_copy.align_to::<u32>() };
|
2021-03-01 05:31:13 -05:00
|
|
|
assert!(prefix.is_empty());
|
|
|
|
assert!(suffix.is_empty());
|
|
|
|
unsafe {
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_bind_group(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.index,
|
|
|
|
bind_group_resource.0,
|
|
|
|
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 RenderPassPushDebugGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
group_label: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_push_debug_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassPushDebugGroupArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_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::render_ffi::wgpu_render_pass_push_debug_group(
|
|
|
|
&mut render_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 RenderPassPopDebugGroupArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_pop_debug_group(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassPopDebugGroupArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_pop_debug_group(
|
|
|
|
&mut render_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 RenderPassInsertDebugMarkerArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
marker_label: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_insert_debug_marker(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassInsertDebugMarkerArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_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::render_ffi::wgpu_render_pass_insert_debug_marker(
|
|
|
|
&mut render_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 RenderPassSetPipelineArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
pipeline: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_set_pipeline(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetPipelineArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pipeline_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_pipeline(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
render_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 RenderPassSetIndexBufferArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
buffer: u32,
|
|
|
|
index_format: String,
|
|
|
|
offset: u64,
|
2021-07-08 05:07:49 -04:00
|
|
|
size: Option<u64>,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_set_index_buffer(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetIndexBufferArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
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.buffer)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-07-08 05:07:49 -04:00
|
|
|
let size = if let Some(size) = args.size {
|
|
|
|
Some(
|
|
|
|
std::num::NonZeroU64::new(size)
|
|
|
|
.ok_or_else(|| type_error("size must be larger than 0"))?,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2021-03-01 05:31:13 -05:00
|
|
|
render_pass_resource.0.borrow_mut().set_index_buffer(
|
|
|
|
buffer_resource.0,
|
|
|
|
super::pipeline::serialize_index_format(args.index_format),
|
|
|
|
args.offset,
|
2021-07-08 05:07:49 -04:00
|
|
|
size,
|
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 RenderPassSetVertexBufferArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
slot: u32,
|
|
|
|
buffer: u32,
|
|
|
|
offset: u64,
|
2021-07-08 05:07:49 -04:00
|
|
|
size: Option<u64>,
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_set_vertex_buffer(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassSetVertexBufferArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
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.buffer)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
2021-07-08 05:07:49 -04:00
|
|
|
let size = if let Some(size) = args.size {
|
|
|
|
Some(
|
|
|
|
std::num::NonZeroU64::new(size)
|
|
|
|
.ok_or_else(|| type_error("size must be larger than 0"))?,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2021-03-01 05:31:13 -05:00
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_set_vertex_buffer(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.slot,
|
|
|
|
buffer_resource.0,
|
|
|
|
args.offset,
|
2021-07-08 05:07:49 -04:00
|
|
|
size,
|
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 RenderPassDrawArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
vertex_count: u32,
|
|
|
|
instance_count: u32,
|
|
|
|
first_vertex: u32,
|
|
|
|
first_instance: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_draw(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassDrawArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_draw(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.vertex_count,
|
|
|
|
args.instance_count,
|
|
|
|
args.first_vertex,
|
|
|
|
args.first_instance,
|
|
|
|
);
|
|
|
|
|
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 RenderPassDrawIndexedArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
index_count: u32,
|
|
|
|
instance_count: u32,
|
|
|
|
first_index: u32,
|
|
|
|
base_vertex: i32,
|
|
|
|
first_instance: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_draw_indexed(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassDrawIndexedArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.index_count,
|
|
|
|
args.instance_count,
|
|
|
|
args.first_index,
|
|
|
|
args.base_vertex,
|
|
|
|
args.first_instance,
|
|
|
|
);
|
|
|
|
|
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 RenderPassDrawIndirectArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
indirect_buffer: u32,
|
|
|
|
indirect_offset: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_draw_indirect(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassDrawIndirectArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
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 render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indirect(
|
|
|
|
&mut render_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 RenderPassDrawIndexedIndirectArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
render_pass_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
indirect_buffer: u32,
|
|
|
|
indirect_offset: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_render_pass_draw_indexed_indirect(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: RenderPassDrawIndexedIndirectArgs,
|
2021-05-08 08:37:42 -04:00
|
|
|
_: (),
|
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 render_pass_resource = state
|
|
|
|
.resource_table
|
2021-03-25 14:17:37 -04:00
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
2021-03-01 05:31:13 -05:00
|
|
|
.ok_or_else(bad_resource_id)?;
|
|
|
|
|
|
|
|
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed_indirect(
|
|
|
|
&mut render_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
|
|
|
}
|