Skip to content

Commit

Permalink
remove dyn render & compute pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Aug 14, 2024
1 parent 0287eaf commit 0fb772b
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 898 deletions.
4 changes: 2 additions & 2 deletions deno_webgpu/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
};

let (render_pass, error) =
instance.command_encoder_create_render_pass_dyn(*command_encoder, &descriptor);
instance.command_encoder_create_render_pass(*command_encoder, &descriptor);
let rid = state
.resource_table
.add(super::render_pass::WebGpuRenderPass(RefCell::new(
Expand Down Expand Up @@ -264,7 +264,7 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
};

let (compute_pass, error) =
instance.command_encoder_create_compute_pass_dyn(*command_encoder, &descriptor);
instance.command_encoder_create_compute_pass(*command_encoder, &descriptor);
let rid = state
.resource_table
.add(super::compute_pass::WebGpuComputePass(RefCell::new(
Expand Down
81 changes: 45 additions & 36 deletions deno_webgpu/compute_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use std::cell::RefCell;

use super::error::WebGpuResult;

pub(crate) struct WebGpuComputePass(
pub(crate) RefCell<Box<dyn wgpu_core::command::DynComputePass>>,
);
pub(crate) struct WebGpuComputePass(pub(crate) RefCell<wgpu_core::command::ComputePass>);
impl Resource for WebGpuComputePass {
fn name(&self) -> Cow<str> {
"webGPUComputePass".into()
Expand All @@ -33,10 +31,12 @@ pub fn op_webgpu_compute_pass_set_pipeline(
.resource_table
.get::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource
.0
.borrow_mut()
.set_pipeline(state.borrow(), compute_pipeline_resource.1)?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_set_pipeline(
&mut compute_pass_resource.0.borrow_mut(),
compute_pipeline_resource.1,
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -54,10 +54,9 @@ pub fn op_webgpu_compute_pass_dispatch_workgroups(
.resource_table
.get::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource
.0
.borrow_mut()
.dispatch_workgroups(state.borrow(), x, y, z)?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_dispatch_workgroups(&mut compute_pass_resource.0.borrow_mut(), x, y, z)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -77,10 +76,13 @@ pub fn op_webgpu_compute_pass_dispatch_workgroups_indirect(
.resource_table
.get::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource
.0
.borrow_mut()
.dispatch_workgroups_indirect(state.borrow(), buffer_resource.1, indirect_offset)?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_dispatch_workgroups_indirect(
&mut compute_pass_resource.0.borrow_mut(),
buffer_resource.1,
indirect_offset,
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -95,7 +97,9 @@ pub fn op_webgpu_compute_pass_end(
.resource_table
.take::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource.0.borrow_mut().end(state.borrow())?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_end(&mut compute_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
}
Expand Down Expand Up @@ -127,12 +131,14 @@ pub fn op_webgpu_compute_pass_set_bind_group(

let dynamic_offsets_data: &[u32] = &dynamic_offsets_data[start..start + len];

compute_pass_resource.0.borrow_mut().set_bind_group(
state.borrow(),
index,
bind_group_resource.1,
dynamic_offsets_data,
)?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_set_bind_group(
&mut compute_pass_resource.0.borrow_mut(),
index,
bind_group_resource.1,
dynamic_offsets_data,
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -148,11 +154,13 @@ pub fn op_webgpu_compute_pass_push_debug_group(
.resource_table
.get::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource.0.borrow_mut().push_debug_group(
state.borrow(),
group_label,
0, // wgpu#975
)?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_push_debug_group(
&mut compute_pass_resource.0.borrow_mut(),
group_label,
0, // wgpu#975
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -167,10 +175,9 @@ pub fn op_webgpu_compute_pass_pop_debug_group(
.resource_table
.get::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource
.0
.borrow_mut()
.pop_debug_group(state.borrow())?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_pop_debug_group(&mut compute_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
}
Expand All @@ -186,11 +193,13 @@ pub fn op_webgpu_compute_pass_insert_debug_marker(
.resource_table
.get::<WebGpuComputePass>(compute_pass_rid)?;

compute_pass_resource.0.borrow_mut().insert_debug_marker(
state.borrow(),
marker_label,
0, // wgpu#975
)?;
state
.borrow::<wgpu_core::global::Global>()
.compute_pass_insert_debug_marker(
&mut compute_pass_resource.0.borrow_mut(),
marker_label,
0, // wgpu#975
)?;

Ok(WebGpuResult::empty())
}
Loading

0 comments on commit 0fb772b

Please sign in to comment.