Skip to content

Commit

Permalink
Separate renderpass arc resolve & renderpass consume on end (#5794)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf authored Jun 25, 2024
1 parent 29e3b98 commit b4c7987
Show file tree
Hide file tree
Showing 9 changed files with 1,557 additions and 667 deletions.
102 changes: 52 additions & 50 deletions deno_webgpu/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use deno_core::ResourceId;
use serde::Deserialize;
use std::borrow::Cow;
use std::cell::RefCell;
use wgpu_core::global::Global;

use super::error::WebGpuResult;

Expand Down Expand Up @@ -41,15 +42,15 @@ pub fn op_webgpu_render_pass_set_viewport(
.resource_table
.get::<WebGpuRenderPass>(args.render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_set_viewport(
state.borrow::<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,
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -68,13 +69,13 @@ pub fn op_webgpu_render_pass_set_scissor_rect(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_set_scissor_rect(
state.borrow::<Global>().render_pass_set_scissor_rect(
&mut render_pass_resource.0.borrow_mut(),
x,
y,
width,
height,
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -90,10 +91,9 @@ pub fn op_webgpu_render_pass_set_blend_constant(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_set_blend_constant(
&mut render_pass_resource.0.borrow_mut(),
&color,
);
state
.borrow::<Global>()
.render_pass_set_blend_constant(&mut render_pass_resource.0.borrow_mut(), &color)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -109,10 +109,9 @@ pub fn op_webgpu_render_pass_set_stencil_reference(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_set_stencil_reference(
&mut render_pass_resource.0.borrow_mut(),
reference,
);
state
.borrow::<Global>()
.render_pass_set_stencil_reference(&mut render_pass_resource.0.borrow_mut(), reference)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -128,10 +127,9 @@ pub fn op_webgpu_render_pass_begin_occlusion_query(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_begin_occlusion_query(
&mut render_pass_resource.0.borrow_mut(),
query_index,
);
state
.borrow::<Global>()
.render_pass_begin_occlusion_query(&mut render_pass_resource.0.borrow_mut(), query_index)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -146,9 +144,9 @@ pub fn op_webgpu_render_pass_end_occlusion_query(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_end_occlusion_query(
&mut render_pass_resource.0.borrow_mut(),
);
state
.borrow::<Global>()
.render_pass_end_occlusion_query(&mut render_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
}
Expand All @@ -174,10 +172,9 @@ pub fn op_webgpu_render_pass_execute_bundles(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_execute_bundles(
&mut render_pass_resource.0.borrow_mut(),
&bundles,
);
state
.borrow::<Global>()
.render_pass_execute_bundles(&mut render_pass_resource.0.borrow_mut(), &bundles)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -191,11 +188,15 @@ pub fn op_webgpu_render_pass_end(
let render_pass_resource = state
.resource_table
.take::<WebGpuRenderPass>(render_pass_rid)?;
let render_pass = &render_pass_resource.0.borrow();
let command_encoder = render_pass.parent_id();
let instance = state.borrow::<super::Instance>();

gfx_ok!(command_encoder => instance.render_pass_end(render_pass))
// TODO: Just like parent_id ComputePass, there's going to be DynComputePass soon which will eliminate the need of doing gfx_select here.
let instance = state.borrow::<Global>();
let parent_id = render_pass_resource.0.borrow().parent_id();
gfx_select!(parent_id => instance.render_pass_end(
&mut render_pass_resource.0.borrow_mut()
))?;

Ok(WebGpuResult::empty())
}

#[op2]
Expand Down Expand Up @@ -225,12 +226,12 @@ pub fn op_webgpu_render_pass_set_bind_group(

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

wgpu_core::command::render_commands::wgpu_render_pass_set_bind_group(
state.borrow::<Global>().render_pass_set_bind_group(
&mut render_pass_resource.0.borrow_mut(),
index,
bind_group_resource.1,
dynamic_offsets_data,
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -246,11 +247,11 @@ pub fn op_webgpu_render_pass_push_debug_group(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_push_debug_group(
state.borrow::<Global>().render_pass_push_debug_group(
&mut render_pass_resource.0.borrow_mut(),
group_label,
0, // wgpu#975
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -265,9 +266,9 @@ pub fn op_webgpu_render_pass_pop_debug_group(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_pop_debug_group(
&mut render_pass_resource.0.borrow_mut(),
);
state
.borrow::<Global>()
.render_pass_pop_debug_group(&mut render_pass_resource.0.borrow_mut())?;

Ok(WebGpuResult::empty())
}
Expand All @@ -283,11 +284,11 @@ pub fn op_webgpu_render_pass_insert_debug_marker(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_insert_debug_marker(
state.borrow::<Global>().render_pass_insert_debug_marker(
&mut render_pass_resource.0.borrow_mut(),
marker_label,
0, // wgpu#975
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -306,10 +307,10 @@ pub fn op_webgpu_render_pass_set_pipeline(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_set_pipeline(
state.borrow::<Global>().render_pass_set_pipeline(
&mut render_pass_resource.0.borrow_mut(),
render_pipeline_resource.1,
);
)?;

Ok(WebGpuResult::empty())
}
Expand Down Expand Up @@ -340,12 +341,13 @@ pub fn op_webgpu_render_pass_set_index_buffer(
None
};

render_pass_resource.0.borrow_mut().set_index_buffer(
state.borrow::<Global>().render_pass_set_index_buffer(
&mut render_pass_resource.0.borrow_mut(),
buffer_resource.1,
index_format,
offset,
size,
);
)?;

Ok(WebGpuResult::empty())
}
Expand Down Expand Up @@ -376,13 +378,13 @@ pub fn op_webgpu_render_pass_set_vertex_buffer(
None
};

wgpu_core::command::render_commands::wgpu_render_pass_set_vertex_buffer(
state.borrow::<Global>().render_pass_set_vertex_buffer(
&mut render_pass_resource.0.borrow_mut(),
slot,
buffer_resource.1,
offset,
size,
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -401,13 +403,13 @@ pub fn op_webgpu_render_pass_draw(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_draw(
state.borrow::<Global>().render_pass_draw(
&mut render_pass_resource.0.borrow_mut(),
vertex_count,
instance_count,
first_vertex,
first_instance,
);
)?;

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

wgpu_core::command::render_commands::wgpu_render_pass_draw_indexed(
state.borrow::<Global>().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 @@ -454,11 +456,11 @@ pub fn op_webgpu_render_pass_draw_indirect(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_draw_indirect(
state.borrow::<Global>().render_pass_draw_indirect(
&mut render_pass_resource.0.borrow_mut(),
buffer_resource.1,
indirect_offset,
);
)?;

Ok(WebGpuResult::empty())
}
Expand All @@ -478,11 +480,11 @@ pub fn op_webgpu_render_pass_draw_indexed_indirect(
.resource_table
.get::<WebGpuRenderPass>(render_pass_rid)?;

wgpu_core::command::render_commands::wgpu_render_pass_draw_indexed_indirect(
state.borrow::<Global>().render_pass_draw_indexed_indirect(
&mut render_pass_resource.0.borrow_mut(),
buffer_resource.1,
indirect_offset,
);
)?;

Ok(WebGpuResult::empty())
}
4 changes: 2 additions & 2 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl GlobalPlay for wgc::global::Global {
timestamp_writes,
occlusion_query_set_id,
} => {
self.render_pass_end_impl::<A>(
self.render_pass_end_with_unresolved_commands::<A>(
encoder,
base.as_ref(),
base,
&target_colors,
target_depth_stencil.as_ref(),
timestamp_writes.as_ref(),
Expand Down
Loading

0 comments on commit b4c7987

Please sign in to comment.