Skip to content

Commit

Permalink
fix cts_runner (#6840)
Browse files Browse the repository at this point in the history
* fix: unbreak compute_pass execution and state

* fix: cts_runner js_runtime needs Permissions struct

* fix: ColorWrites bitflags serde

---------

Co-authored-by: turbocrime <turbocrime@users.noreply.github.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
  • Loading branch information
3 people authored Jan 10, 2025
1 parent c655d52 commit 1aabf22
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 70 deletions.
5 changes: 3 additions & 2 deletions cts_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ mod native {
.unwrap();
}

js_runtime.op_state().borrow_mut().put(Permissions {});

let mod_id = js_runtime.load_main_es_module(&specifier).await?;
let result = js_runtime.mod_evaluate(mod_id);
js_runtime.run_event_loop(Default::default()).await?;
Expand All @@ -157,6 +155,9 @@ mod native {
ops = [op_exit, op_read_file_sync, op_write_file_sync],
esm_entry_point = "ext:cts_runner/src/bootstrap.js",
esm = ["src/bootstrap.js"],
state = |state| {
state.put(Permissions {});
}
);

#[op2(fast)]
Expand Down
17 changes: 9 additions & 8 deletions deno_webgpu/compute_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn op_webgpu_compute_pass_set_pipeline(
.get::<WebGpuComputePass>(compute_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.compute_pass_set_pipeline(
&mut compute_pass_resource.0.borrow_mut(),
compute_pipeline_resource.1,
Expand All @@ -55,7 +55,7 @@ pub fn op_webgpu_compute_pass_dispatch_workgroups(
.get::<WebGpuComputePass>(compute_pass_rid)?;

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

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

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.compute_pass_dispatch_workgroups_indirect(
&mut compute_pass_resource.0.borrow_mut(),
buffer_resource.1,
Expand All @@ -91,14 +91,15 @@ pub fn op_webgpu_compute_pass_dispatch_workgroups_indirect(
#[serde]
pub fn op_webgpu_compute_pass_end(
state: &mut OpState,
#[smi] _command_encoder_rid: ResourceId,
#[smi] compute_pass_rid: ResourceId,
) -> Result<WebGpuResult, AnyError> {
let compute_pass_resource = state
.resource_table
.take::<WebGpuComputePass>(compute_pass_rid)?;

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

Ok(WebGpuResult::empty())
Expand Down Expand Up @@ -132,7 +133,7 @@ pub fn op_webgpu_compute_pass_set_bind_group(
let dynamic_offsets_data: &[u32] = &dynamic_offsets_data[start..start + len];

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.compute_pass_set_bind_group(
&mut compute_pass_resource.0.borrow_mut(),
index,
Expand All @@ -155,7 +156,7 @@ pub fn op_webgpu_compute_pass_push_debug_group(
.get::<WebGpuComputePass>(compute_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.compute_pass_push_debug_group(
&mut compute_pass_resource.0.borrow_mut(),
group_label,
Expand All @@ -176,7 +177,7 @@ pub fn op_webgpu_compute_pass_pop_debug_group(
.get::<WebGpuComputePass>(compute_pass_rid)?;

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

Ok(WebGpuResult::empty())
Expand All @@ -194,7 +195,7 @@ pub fn op_webgpu_compute_pass_insert_debug_marker(
.get::<WebGpuComputePass>(compute_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.compute_pass_insert_debug_marker(
&mut compute_pass_resource.0.borrow_mut(),
marker_label,
Expand Down
95 changes: 44 additions & 51 deletions deno_webgpu/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ pub fn op_webgpu_render_pass_set_viewport(
.resource_table
.get::<WebGpuRenderPass>(args.render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.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,
)?;
state.borrow::<super::Instance>().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,
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -80,7 +78,7 @@ pub fn op_webgpu_render_pass_set_scissor_rect(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_set_scissor_rect(
&mut render_pass_resource.0.borrow_mut(),
x,
Expand All @@ -104,7 +102,7 @@ pub fn op_webgpu_render_pass_set_blend_constant(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_set_blend_constant(&mut render_pass_resource.0.borrow_mut(), color)?;

Ok(WebGpuResult::empty())
Expand All @@ -122,7 +120,7 @@ pub fn op_webgpu_render_pass_set_stencil_reference(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_set_stencil_reference(&mut render_pass_resource.0.borrow_mut(), reference)?;

Ok(WebGpuResult::empty())
Expand All @@ -140,7 +138,7 @@ pub fn op_webgpu_render_pass_begin_occlusion_query(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_begin_occlusion_query(&mut render_pass_resource.0.borrow_mut(), query_index)?;

Ok(WebGpuResult::empty())
Expand All @@ -157,7 +155,7 @@ pub fn op_webgpu_render_pass_end_occlusion_query(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_end_occlusion_query(&mut render_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
Expand Down Expand Up @@ -185,7 +183,7 @@ pub fn op_webgpu_render_pass_execute_bundles(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_execute_bundles(&mut render_pass_resource.0.borrow_mut(), &bundles)?;

Ok(WebGpuResult::empty())
Expand All @@ -195,14 +193,15 @@ pub fn op_webgpu_render_pass_execute_bundles(
#[serde]
pub fn op_webgpu_render_pass_end(
state: &mut OpState,
#[smi] _command_encoder_rid: ResourceId,
#[smi] render_pass_rid: ResourceId,
) -> Result<WebGpuResult, deno_core::error::AnyError> {
let render_pass_resource = state
.resource_table
.take::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_end(&mut render_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
Expand Down Expand Up @@ -236,7 +235,7 @@ pub fn op_webgpu_render_pass_set_bind_group(
let dynamic_offsets_data: &[u32] = &dynamic_offsets_data[start..start + len];

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_set_bind_group(
&mut render_pass_resource.0.borrow_mut(),
index,
Expand All @@ -259,7 +258,7 @@ pub fn op_webgpu_render_pass_push_debug_group(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_push_debug_group(
&mut render_pass_resource.0.borrow_mut(),
group_label,
Expand All @@ -280,7 +279,7 @@ pub fn op_webgpu_render_pass_pop_debug_group(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_pop_debug_group(&mut render_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
Expand All @@ -298,7 +297,7 @@ pub fn op_webgpu_render_pass_insert_debug_marker(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_insert_debug_marker(
&mut render_pass_resource.0.borrow_mut(),
marker_label,
Expand All @@ -322,12 +321,10 @@ pub fn op_webgpu_render_pass_set_pipeline(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.render_pass_set_pipeline(
&mut render_pass_resource.0.borrow_mut(),
render_pipeline_resource.1,
)?;
state.borrow::<super::Instance>().render_pass_set_pipeline(
&mut render_pass_resource.0.borrow_mut(),
render_pipeline_resource.1,
)?;

Ok(WebGpuResult::empty())
}
Expand Down Expand Up @@ -358,7 +355,7 @@ pub fn op_webgpu_render_pass_set_index_buffer(
};

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_set_index_buffer(
&mut render_pass_resource.0.borrow_mut(),
buffer_resource.1,
Expand Down Expand Up @@ -396,7 +393,7 @@ pub fn op_webgpu_render_pass_set_vertex_buffer(
};

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_set_vertex_buffer(
&mut render_pass_resource.0.borrow_mut(),
slot,
Expand All @@ -422,15 +419,13 @@ pub fn op_webgpu_render_pass_draw(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.render_pass_draw(
&mut render_pass_resource.0.borrow_mut(),
vertex_count,
instance_count,
first_vertex,
first_instance,
)?;
state.borrow::<super::Instance>().render_pass_draw(
&mut render_pass_resource.0.borrow_mut(),
vertex_count,
instance_count,
first_vertex,
first_instance,
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -450,16 +445,14 @@ pub fn op_webgpu_render_pass_draw_indexed(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.render_pass_draw_indexed(
&mut render_pass_resource.0.borrow_mut(),
index_count,
instance_count,
first_index,
base_vertex,
first_instance,
)?;
state.borrow::<super::Instance>().render_pass_draw_indexed(
&mut render_pass_resource.0.borrow_mut(),
index_count,
instance_count,
first_index,
base_vertex,
first_instance,
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -480,7 +473,7 @@ pub fn op_webgpu_render_pass_draw_indirect(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_draw_indirect(
&mut render_pass_resource.0.borrow_mut(),
buffer_resource.1,
Expand All @@ -506,7 +499,7 @@ pub fn op_webgpu_render_pass_draw_indexed_indirect(
.get::<WebGpuRenderPass>(render_pass_rid)?;

state
.borrow::<wgpu_core::global::Global>()
.borrow::<super::Instance>()
.render_pass_draw_indexed_indirect(
&mut render_pass_resource.0.borrow_mut(),
buffer_resource.1,
Expand Down
20 changes: 11 additions & 9 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4701,16 +4701,18 @@ fn texture_format_deserialize() {
);
}

/// Color write mask. Disabled color channels will not be written to.
///
/// Corresponds to [WebGPU `GPUColorWriteFlags`](
/// https://gpuweb.github.io/gpuweb/#typedefdef-gpucolorwriteflags).
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ColorWrites(u32);

bitflags::bitflags! {
/// Color write mask. Disabled color channels will not be written to.
///
/// Corresponds to [WebGPU `GPUColorWriteFlags`](
/// https://gpuweb.github.io/gpuweb/#typedefdef-gpucolorwriteflags).
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ColorWrites: u32 {
impl ColorWrites: u32 {
/// Enable red channel writes
const RED = 1 << 0;
/// Enable green channel writes
Expand Down

0 comments on commit 1aabf22

Please sign in to comment.