Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Degenerification part 3/3: remove gfx_select, remove compute/render pass indirections #6100

Merged
merged 53 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7f4cf4f
introduce DynResource & DynBuffer as first user
Wumpf Jul 10, 2024
eddab98
Buffer bindings no longer depend on hal api struct, but directly on b…
Wumpf Jul 14, 2024
f9d47ec
BufferBarrier no longer depend on hal api struct, but directly on buf…
Wumpf Jul 14, 2024
880e5a9
Introduce DynCommandEncoder, implement index & vertex buffer ops on it
Wumpf Jul 14, 2024
6f8ef5c
DynCommandEncoder implement begin/end encoding, debug markers, variou…
Wumpf Jul 15, 2024
debe041
introduce DynQuerySet, associated DynCommandEncoder methods
Wumpf Jul 15, 2024
233d2ba
Introduce DynPipelineLayout & DynBindGroup
Wumpf Jul 15, 2024
6576838
Introduce DynComputePipeline & DynRenderPipeline
Wumpf Jul 15, 2024
7548973
fold ComputePassTimestampWrites & RenderPassTimestampWrites and make …
Wumpf Jul 15, 2024
ff49edc
introduce DynTexture & DynTextureView
Wumpf Jul 17, 2024
15748cb
render/compute pass descriptors work now with dyn types
Wumpf Jul 17, 2024
c19659b
implement begin/end render/computepass for dyncommandencoder
Wumpf Jul 20, 2024
1ee9d4b
implement transition_textures for DynCommandEncoder
Wumpf Jul 20, 2024
8bb009e
buffer / texture copy operations for DynCommandEncoder
Wumpf Jul 20, 2024
5719e38
texture & buffer transitioning always uses DynCommandEncoder now
Wumpf Jul 20, 2024
2502283
Introduce DynDevice
Wumpf Jul 20, 2024
7b25389
add most remaining dyn type traits
Wumpf Jul 20, 2024
b662e71
impl DynShaderModule for all backends
Wumpf Jul 20, 2024
e9860f7
impl DynCommandBuffer
Wumpf Jul 21, 2024
8595a1c
Device now has to implement DynResource
Wumpf Jul 21, 2024
e4744df
impl DynFence for all fences
Wumpf Jul 21, 2024
d94e465
impl DynSurfaceTexture for all surface textures
Wumpf Jul 21, 2024
39b214a
introduce DynSurface
Wumpf Jul 21, 2024
24bd6e0
introduce DynQueue
Wumpf Jul 21, 2024
d685660
DynDevice buffer operations
Wumpf Jul 21, 2024
9dd24e0
DynDevice create/destroy for texture/textureview/sampler
Wumpf Jul 24, 2024
3217d43
DynDevice create/destroy command encoder
Wumpf Jul 27, 2024
38c9031
DynDevice create/destroy bind group layout
Wumpf Jul 27, 2024
ba06be2
DynDevice create/destroy pipeline layout
Wumpf Jul 27, 2024
f37a871
DynDevice create/destroy bind group
Wumpf Jul 27, 2024
533def2
DynDevice create/destroy ShaderModule
Wumpf Jul 27, 2024
bf1bf41
DynDevice create/destroy compute/render pipeline
Wumpf Jul 28, 2024
7d8f753
DynDevice pipeline cache
Wumpf Jul 28, 2024
af35846
DynDevice create/destroy query set
Wumpf Jul 28, 2024
96914ea
DynDevice fence
Wumpf Jul 28, 2024
3bf21ab
DynDevice wait/capture/pipeline_cache_get_data
Wumpf Jul 28, 2024
afd32e0
DynDevice acceleration structure handling
Wumpf Jul 28, 2024
666d2fa
DynDevice exit, counters, report
Wumpf Jul 28, 2024
4c30ef5
DynCommandencoder end_encoding, reset_all
Wumpf Jul 28, 2024
7981855
DynCommandEncoder acceleration structure building
Wumpf Jul 28, 2024
34fe670
remove unnecessary debug constraints from Api (handled by Dyn traits)
Wumpf Jul 28, 2024
2eb9c73
introduce DynAdapter
Wumpf Aug 4, 2024
75aaa13
introduce DynInstance
Wumpf Aug 4, 2024
6e10de7
The big unraveling: core device now has a boxed `DynDevice`, ripple e…
Wumpf Jul 10, 2024
4a688cb
Core's Surface, Instance and Adapter use now dynamic hal types
Wumpf Aug 4, 2024
e24f48a
Core adapter no longer uses any generics
Wumpf Aug 4, 2024
e7deb0c
The second unraveling: hub and all types on it are generic free!
Wumpf Aug 4, 2024
ed1387d
ignore 'arc instead of rc' warnings on wasm
Wumpf Aug 10, 2024
0fd56eb
Handle webgl's `queue_copy_external_image_to_texture`
Wumpf Aug 10, 2024
844918a
Remove `gfx_select`.
Wumpf Aug 6, 2024
688c693
remove dyn render & compute pass
Wumpf Aug 6, 2024
dc38de7
re-enable docs for wgpu-core
Wumpf Aug 10, 2024
eb02613
changelog entry
Wumpf Aug 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ Bottom level categories:

## Unreleased

### Major Changes

#### `wgpu-core` is no longer generic over `wgpu-hal` backends
Dynamic dispatch between different backends has been moved from the user facing `wgpu` crate,
to a new dynamic dispatch mechanism inside the backend abstraction layer `wgpu-hal`.

Whenever targeting more than a single backend (default on Windows & Linux) this leads to faster compile times and smaller binaries!
This also solves a long standing issue with `cargo doc` failing to run for `wgpu-core`.

Benchmarking indicated that compute pass recording is slower as a consequence,
whereas on render passes speed improvements have been observed.
However, this effort simplifies many of the internals of the wgpu family of crates
which we're hoping to build performance improvements upon in the future.

By @wumpf in [#6069](https://github.com/gfx-rs/wgpu/pull/6069), [#6099](https://github.com/gfx-rs/wgpu/pull/6099), [#6100](https://github.com/gfx-rs/wgpu/pull/6100).

### New Features

#### Naga
Expand Down
10 changes: 5 additions & 5 deletions deno_webgpu/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Resource for WebGpuBindGroupLayout {
}

fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.bind_group_layout_drop(self.1));
self.0.bind_group_layout_drop(self.1);
}
}

Expand All @@ -35,7 +35,7 @@ impl Resource for WebGpuBindGroup {
}

fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.bind_group_drop(self.1));
self.0.bind_group_drop(self.1);
}
}

Expand Down Expand Up @@ -191,7 +191,7 @@ pub fn op_webgpu_create_bind_group_layout(
entries: Cow::from(entries),
};

gfx_put!(device => instance.device_create_bind_group_layout(
gfx_put!(instance.device_create_bind_group_layout(
device,
&descriptor,
None
Expand Down Expand Up @@ -226,7 +226,7 @@ pub fn op_webgpu_create_pipeline_layout(
push_constant_ranges: Default::default(),
};

gfx_put!(device => instance.device_create_pipeline_layout(
gfx_put!(instance.device_create_pipeline_layout(
device,
&descriptor,
None
Expand Down Expand Up @@ -305,7 +305,7 @@ pub fn op_webgpu_create_bind_group(
entries: Cow::from(entries),
};

gfx_put!(device => instance.device_create_bind_group(
gfx_put!(instance.device_create_bind_group(
device,
&descriptor,
None
Expand Down
45 changes: 22 additions & 23 deletions deno_webgpu/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Resource for WebGpuBuffer {
}

fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.buffer_drop(self.1));
self.0.buffer_drop(self.1);
}
}

Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn op_webgpu_create_buffer(
mapped_at_creation,
};

gfx_put!(device => instance.device_create_buffer(
gfx_put!(instance.device_create_buffer(
device,
&descriptor,
None
Expand Down Expand Up @@ -97,20 +97,21 @@ pub async fn op_webgpu_buffer_get_map_async(
});

// TODO(lucacasonato): error handling
let maybe_err = gfx_select!(buffer => instance.buffer_map_async(
buffer,
offset,
Some(size),
wgpu_core::resource::BufferMapOperation {
host: match mode {
1 => wgpu_core::device::HostMap::Read,
2 => wgpu_core::device::HostMap::Write,
_ => unreachable!(),
let maybe_err = instance
.buffer_map_async(
buffer,
offset,
Some(size),
wgpu_core::resource::BufferMapOperation {
host: match mode {
1 => wgpu_core::device::HostMap::Read,
2 => wgpu_core::device::HostMap::Write,
_ => unreachable!(),
},
callback: Some(wgpu_core::resource::BufferMapCallback::from_rust(callback)),
},
callback: Some(wgpu_core::resource::BufferMapCallback::from_rust(callback)),
}
))
.err();
)
.err();

if maybe_err.is_some() {
return Ok(WebGpuResult::maybe_err(maybe_err));
Expand All @@ -124,7 +125,8 @@ pub async fn op_webgpu_buffer_get_map_async(
{
let state = state.borrow();
let instance = state.borrow::<super::Instance>();
gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::wait()))
instance
.device_poll(device, wgpu_types::Maintain::wait())
.unwrap();
}
tokio::time::sleep(Duration::from_millis(10)).await;
Expand Down Expand Up @@ -157,12 +159,9 @@ pub fn op_webgpu_buffer_get_mapped_range(
let buffer_resource = state.resource_table.get::<WebGpuBuffer>(buffer_rid)?;
let buffer = buffer_resource.1;

let (slice_pointer, range_size) = gfx_select!(buffer => instance.buffer_get_mapped_range(
buffer,
offset,
size
))
.map_err(|e| DomExceptionOperationError::new(&e.to_string()))?;
let (slice_pointer, range_size) = instance
.buffer_get_mapped_range(buffer, offset, size)
.map_err(|e| DomExceptionOperationError::new(&e.to_string()))?;

// SAFETY: guarantee to be safe from wgpu
let slice =
Expand Down Expand Up @@ -199,5 +198,5 @@ pub fn op_webgpu_buffer_unmap(
slice.copy_from_slice(buf);
}

gfx_ok!(buffer => instance.buffer_unmap(buffer))
gfx_ok!(instance.buffer_unmap(buffer))
}
4 changes: 2 additions & 2 deletions deno_webgpu/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Resource for WebGpuRenderBundle {
}

fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.render_bundle_drop(self.1));
self.0.render_bundle_drop(self.1);
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn op_webgpu_render_bundle_encoder_finish(
.into_inner();
let instance = state.borrow::<super::Instance>();

gfx_put!(render_bundle_encoder.parent() => instance.render_bundle_encoder_finish(
gfx_put!(instance.render_bundle_encoder_finish(
render_bundle_encoder,
&wgpu_core::command::RenderBundleDescriptor {
label: Some(label),
Expand Down
102 changes: 49 additions & 53 deletions deno_webgpu/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Resource for WebGpuCommandEncoder {
}

fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.command_encoder_drop(self.1));
self.0.command_encoder_drop(self.1);
}
}

Expand All @@ -38,7 +38,7 @@ impl Resource for WebGpuCommandBuffer {

fn close(self: Rc<Self>) {
if let Some(id) = *self.1.borrow() {
gfx_select!(id => self.0.command_buffer_drop(id));
self.0.command_buffer_drop(id);
}
}
}
Expand All @@ -58,7 +58,7 @@ pub fn op_webgpu_create_command_encoder(

let descriptor = wgpu_types::CommandEncoderDescriptor { label: Some(label) };

gfx_put!(device => instance.device_create_command_encoder(
gfx_put!(instance.device_create_command_encoder(
device,
&descriptor,
None
Expand Down Expand Up @@ -210,7 +210,8 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
occlusion_query_set: occlusion_query_set_resource,
};

let (render_pass, error) = gfx_select!(command_encoder => instance.command_encoder_create_render_pass_dyn(*command_encoder, &descriptor));
let (render_pass, error) =
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 @@ -262,7 +263,8 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
timestamp_writes: timestamp_writes.as_ref(),
};

let (compute_pass, error) = gfx_select!(command_encoder => instance.command_encoder_create_compute_pass_dyn(*command_encoder, &descriptor));
let (compute_pass, error) =
instance.command_encoder_create_compute_pass(*command_encoder, &descriptor);
let rid = state
.resource_table
.add(super::compute_pass::WebGpuComputePass(RefCell::new(
Expand Down Expand Up @@ -297,13 +299,13 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
.get::<super::buffer::WebGpuBuffer>(destination)?;
let destination_buffer = destination_buffer_resource.1;

gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_buffer(
command_encoder,
source_buffer,
source_offset,
destination_buffer,
destination_offset,
size
gfx_ok!(instance.command_encoder_copy_buffer_to_buffer(
command_encoder,
source_buffer,
source_offset,
destination_buffer,
destination_offset,
size
))
}

Expand Down Expand Up @@ -360,11 +362,11 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
origin: destination.origin,
aspect: destination.aspect,
};
gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_texture(
command_encoder,
&source,
&destination,
&copy_size
gfx_ok!(instance.command_encoder_copy_buffer_to_texture(
command_encoder,
&source,
&destination,
&copy_size
))
}

Expand Down Expand Up @@ -403,11 +405,11 @@ pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
rows_per_image: destination.rows_per_image,
},
};
gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_buffer(
command_encoder,
&source,
&destination,
&copy_size
gfx_ok!(instance.command_encoder_copy_texture_to_buffer(
command_encoder,
&source,
&destination,
&copy_size
))
}

Expand Down Expand Up @@ -444,11 +446,11 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture(
origin: destination.origin,
aspect: destination.aspect,
};
gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_texture(
command_encoder,
&source,
&destination,
&copy_size
gfx_ok!(instance.command_encoder_copy_texture_to_texture(
command_encoder,
&source,
&destination,
&copy_size
))
}

Expand All @@ -470,11 +472,11 @@ pub fn op_webgpu_command_encoder_clear_buffer(
.resource_table
.get::<super::buffer::WebGpuBuffer>(buffer_rid)?;

gfx_ok!(command_encoder => instance.command_encoder_clear_buffer(
command_encoder,
destination_resource.1,
offset,
Some(size)
gfx_ok!(instance.command_encoder_clear_buffer(
command_encoder,
destination_resource.1,
offset,
Some(size)
))
}

Expand All @@ -491,7 +493,7 @@ pub fn op_webgpu_command_encoder_push_debug_group(
.get::<WebGpuCommandEncoder>(command_encoder_rid)?;
let command_encoder = command_encoder_resource.1;

gfx_ok!(command_encoder => instance.command_encoder_push_debug_group(command_encoder, group_label))
gfx_ok!(instance.command_encoder_push_debug_group(command_encoder, group_label))
}

#[op2]
Expand All @@ -506,7 +508,7 @@ pub fn op_webgpu_command_encoder_pop_debug_group(
.get::<WebGpuCommandEncoder>(command_encoder_rid)?;
let command_encoder = command_encoder_resource.1;

gfx_ok!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder))
gfx_ok!(instance.command_encoder_pop_debug_group(command_encoder))
}

#[op2]
Expand All @@ -522,10 +524,7 @@ pub fn op_webgpu_command_encoder_insert_debug_marker(
.get::<WebGpuCommandEncoder>(command_encoder_rid)?;
let command_encoder = command_encoder_resource.1;

gfx_ok!(command_encoder => instance.command_encoder_insert_debug_marker(
command_encoder,
marker_label
))
gfx_ok!(instance.command_encoder_insert_debug_marker(command_encoder, marker_label))
}

#[op2]
Expand All @@ -545,10 +544,10 @@ pub fn op_webgpu_command_encoder_write_timestamp(
.resource_table
.get::<super::WebGpuQuerySet>(query_set)?;

gfx_ok!(command_encoder => instance.command_encoder_write_timestamp(
command_encoder,
query_set_resource.1,
query_index
gfx_ok!(instance.command_encoder_write_timestamp(
command_encoder,
query_set_resource.1,
query_index
))
}

Expand All @@ -575,13 +574,13 @@ pub fn op_webgpu_command_encoder_resolve_query_set(
.resource_table
.get::<super::buffer::WebGpuBuffer>(destination)?;

gfx_ok!(command_encoder => instance.command_encoder_resolve_query_set(
command_encoder,
query_set_resource.1,
first_query,
query_count,
destination_resource.1,
destination_offset
gfx_ok!(instance.command_encoder_resolve_query_set(
command_encoder,
query_set_resource.1,
first_query,
query_count,
destination_resource.1,
destination_offset
))
}

Expand All @@ -600,10 +599,7 @@ pub fn op_webgpu_command_encoder_finish(

let descriptor = wgpu_types::CommandBufferDescriptor { label: Some(label) };

let (val, maybe_err) = gfx_select!(command_encoder => instance.command_encoder_finish(
command_encoder,
&descriptor
));
let (val, maybe_err) = instance.command_encoder_finish(command_encoder, &descriptor);

let rid = state.resource_table.add(WebGpuCommandBuffer(
instance.clone(),
Expand Down
Loading
Loading