2024-04-02 18:36:04 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
use deno_core::error::type_error;
|
|
|
|
use deno_core::error::AnyError;
|
2023-10-04 04:25:56 +00:00
|
|
|
use deno_core::op2;
|
2022-03-19 05:31:10 +00:00
|
|
|
use deno_core::OpState;
|
|
|
|
use deno_core::Resource;
|
2021-09-03 17:23:35 +00:00
|
|
|
use deno_core::ResourceId;
|
|
|
|
use serde::Deserialize;
|
|
|
|
use std::borrow::Cow;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
use super::error::WebGpuResult;
|
|
|
|
|
|
|
|
pub(crate) struct WebGpuRenderPass(pub(crate) RefCell<wgpu_core::command::RenderPass>);
|
|
|
|
impl Resource for WebGpuRenderPass {
|
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPURenderPass".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RenderPassSetViewportArgs {
|
|
|
|
render_pass_rid: ResourceId,
|
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
width: f32,
|
|
|
|
height: f32,
|
|
|
|
min_depth: f32,
|
|
|
|
max_depth: f32,
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_viewport(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[serde] args: RenderPassSetViewportArgs,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
|
|
|
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_viewport(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
args.x,
|
|
|
|
args.y,
|
|
|
|
args.width,
|
|
|
|
args.height,
|
|
|
|
args.min_depth,
|
|
|
|
args.max_depth,
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_scissor_rect(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
x: u32,
|
|
|
|
y: u32,
|
|
|
|
width: u32,
|
|
|
|
height: u32,
|
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_scissor_rect(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2022-03-24 17:20:10 +00:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_blend_constant(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
|
|
|
#[serde] color: wgpu_types::Color,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_blend_constant(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2022-03-24 17:20:10 +00:00
|
|
|
&color,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_stencil_reference(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2022-03-24 17:20:10 +00:00
|
|
|
reference: u32,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_stencil_reference(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2022-03-24 17:20:10 +00:00
|
|
|
reference,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2023-08-02 19:05:59 +00:00
|
|
|
pub fn op_webgpu_render_pass_begin_occlusion_query(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2023-08-02 19:05:59 +00:00
|
|
|
query_index: u32,
|
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_begin_occlusion_query(
|
2023-08-02 19:05:59 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
query_index,
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2023-08-02 19:05:59 +00:00
|
|
|
pub fn op_webgpu_render_pass_end_occlusion_query(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2023-08-02 19:05:59 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_end_occlusion_query(
|
2023-08-02 19:05:59 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_execute_bundles(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
|
|
|
#[serde] bundles: Vec<u32>,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2022-03-24 17:20:10 +00:00
|
|
|
let bundles = bundles
|
|
|
|
.iter()
|
|
|
|
.map(|rid| {
|
|
|
|
let render_bundle_resource = state
|
|
|
|
.resource_table
|
|
|
|
.get::<super::bundle::WebGpuRenderBundle>(*rid)?;
|
2023-03-03 17:18:01 +00:00
|
|
|
Ok(render_bundle_resource.1)
|
2022-03-24 17:20:10 +00:00
|
|
|
})
|
|
|
|
.collect::<Result<Vec<_>, AnyError>>()?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_execute_bundles(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
&bundles,
|
|
|
|
);
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-19 05:31:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_end(
|
2021-09-03 17:23:35 +00:00
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] command_encoder_rid: ResourceId,
|
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let command_encoder_resource =
|
|
|
|
state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::command_encoder::WebGpuCommandEncoder>(command_encoder_rid)?;
|
2023-03-03 17:18:01 +00:00
|
|
|
let command_encoder = command_encoder_resource.1;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.take::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass = &render_pass_resource.0.borrow();
|
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
|
|
|
|
gfx_ok!(command_encoder => instance.command_encoder_run_render_pass(command_encoder, render_pass))
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_bind_group(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
index: u32,
|
|
|
|
bind_group: u32,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[buffer] dynamic_offsets_data: &[u32],
|
|
|
|
#[number] dynamic_offsets_data_start: usize,
|
|
|
|
#[number] dynamic_offsets_data_length: usize,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let bind_group_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::binding::WebGpuBindGroup>(bind_group)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2022-03-24 17:20:10 +00:00
|
|
|
let start = dynamic_offsets_data_start;
|
|
|
|
let len = dynamic_offsets_data_length;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
// Assert that length and start are both in bounds
|
|
|
|
assert!(start <= dynamic_offsets_data.len());
|
|
|
|
assert!(len <= dynamic_offsets_data.len() - start);
|
|
|
|
|
|
|
|
let dynamic_offsets_data: &[u32] = &dynamic_offsets_data[start..start + len];
|
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_bind_group(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
index,
|
|
|
|
bind_group_resource.1,
|
|
|
|
dynamic_offsets_data,
|
|
|
|
);
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_push_debug_group(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
|
|
|
#[string] group_label: &str,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_push_debug_group(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
group_label,
|
|
|
|
0, // wgpu#975
|
|
|
|
);
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_pop_debug_group(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_pop_debug_group(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_insert_debug_marker(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
|
|
|
#[string] marker_label: &str,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_insert_debug_marker(
|
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
|
|
|
marker_label,
|
|
|
|
0, // wgpu#975
|
|
|
|
);
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_pipeline(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2022-03-24 17:20:10 +00:00
|
|
|
pipeline: u32,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pipeline_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::pipeline::WebGpuRenderPipeline>(pipeline)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_pipeline(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2023-03-03 17:18:01 +00:00
|
|
|
render_pipeline_resource.1,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_index_buffer(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
buffer: u32,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[serde] index_format: wgpu_types::IndexFormat,
|
|
|
|
#[number] offset: u64,
|
|
|
|
#[number] size: Option<u64>,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let buffer_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(buffer)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2022-03-24 17:20:10 +00:00
|
|
|
let size = if let Some(size) = size {
|
2021-09-03 17:23:35 +00:00
|
|
|
Some(
|
|
|
|
std::num::NonZeroU64::new(size)
|
|
|
|
.ok_or_else(|| type_error("size must be larger than 0"))?,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
render_pass_resource.0.borrow_mut().set_index_buffer(
|
2023-03-03 17:18:01 +00:00
|
|
|
buffer_resource.1,
|
2022-03-24 17:20:10 +00:00
|
|
|
index_format,
|
|
|
|
offset,
|
2021-09-03 17:23:35 +00:00
|
|
|
size,
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_set_vertex_buffer(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
slot: u32,
|
|
|
|
buffer: u32,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[number] offset: u64,
|
|
|
|
#[number] size: Option<u64>,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let buffer_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(buffer)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2022-03-24 17:20:10 +00:00
|
|
|
let size = if let Some(size) = size {
|
2021-09-03 17:23:35 +00:00
|
|
|
Some(
|
|
|
|
std::num::NonZeroU64::new(size)
|
|
|
|
.ok_or_else(|| type_error("size must be larger than 0"))?,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_set_vertex_buffer(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2022-03-24 17:20:10 +00:00
|
|
|
slot,
|
2023-03-03 17:18:01 +00:00
|
|
|
buffer_resource.1,
|
2022-03-24 17:20:10 +00:00
|
|
|
offset,
|
2021-09-03 17:23:35 +00:00
|
|
|
size,
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_draw(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
vertex_count: u32,
|
|
|
|
instance_count: u32,
|
|
|
|
first_vertex: u32,
|
|
|
|
first_instance: u32,
|
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_draw(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2022-03-24 17:20:10 +00:00
|
|
|
vertex_count,
|
|
|
|
instance_count,
|
|
|
|
first_vertex,
|
|
|
|
first_instance,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_render_pass_draw_indexed(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2021-09-03 17:23:35 +00:00
|
|
|
index_count: u32,
|
|
|
|
instance_count: u32,
|
|
|
|
first_index: u32,
|
|
|
|
base_vertex: i32,
|
|
|
|
first_instance: u32,
|
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_draw_indexed(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2022-03-24 17:20:10 +00:00
|
|
|
index_count,
|
|
|
|
instance_count,
|
|
|
|
first_index,
|
|
|
|
base_vertex,
|
|
|
|
first_instance,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_draw_indirect(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2022-03-24 17:20:10 +00:00
|
|
|
indirect_buffer: u32,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[number] indirect_offset: u64,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let buffer_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(indirect_buffer)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_draw_indirect(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2023-03-03 17:18:01 +00:00
|
|
|
buffer_resource.1,
|
2022-03-24 17:20:10 +00:00
|
|
|
indirect_offset,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2021-09-03 17:23:35 +00:00
|
|
|
pub fn op_webgpu_render_pass_draw_indexed_indirect(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] render_pass_rid: ResourceId,
|
2022-03-24 17:20:10 +00:00
|
|
|
indirect_buffer: u32,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[number] indirect_offset: u64,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let buffer_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::buffer::WebGpuBuffer>(indirect_buffer)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
let render_pass_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<WebGpuRenderPass>(render_pass_rid)?;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2024-04-17 20:48:45 +00:00
|
|
|
wgpu_core::command::render_commands::wgpu_render_pass_draw_indexed_indirect(
|
2021-09-03 17:23:35 +00:00
|
|
|
&mut render_pass_resource.0.borrow_mut(),
|
2023-03-03 17:18:01 +00:00
|
|
|
buffer_resource.1,
|
2022-03-24 17:20:10 +00:00
|
|
|
indirect_offset,
|
2021-09-03 17:23:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(WebGpuResult::empty())
|
|
|
|
}
|