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

wgpu-hal dynamic dispatch, towards fewer generics in wgpu-core #6002

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a97688b
introduce DynResource & DynBuffer as first user
Wumpf Jul 10, 2024
a6c9ea9
Introduce DynDevice, only for destroying buffer so far
Wumpf Jul 10, 2024
aabd26c
Use `DynBuffer` inside of wgpu-core's `Buffer` & `DestroyedBuffer`
Wumpf Jul 10, 2024
3bb9486
Buffer bindings no longer depend on hal api struct, but directly on b…
Wumpf Jul 14, 2024
0d22b4e
Introduce DynCommandEncoder and use it for setting index & vertex buffer
Wumpf Jul 14, 2024
c703bf4
BufferBarrier no longer depend on hal api struct, but directly on buf…
Wumpf Jul 14, 2024
de9724d
introduce casting utilities to wgpu-hal dynamic
Wumpf Jul 15, 2024
13218cc
separate DynCommandEncoder into its own module and implement everythi…
Wumpf Jul 15, 2024
213b68b
introduce DynQuerySet and implement Dyn query methods
Wumpf Jul 15, 2024
ec96b83
all raw encoder pointers in core's query.rs are now DynCommandEncoder
Wumpf Jul 15, 2024
cb092a9
Introduce DynPipelineLayout & DynBindGroup
Wumpf Jul 15, 2024
83bd87b
Introduce DynComputePipeline & DynRenderPipeline
Wumpf Jul 15, 2024
fd38bd3
fold ComputePassTimestampWrites & RenderPassTimestampWrites and make …
Wumpf Jul 15, 2024
e1707fd
implement `DynResource` with a macro instead
Wumpf Jul 16, 2024
df1e9da
add unboxing to DynResource
Wumpf Aug 4, 2024
dfd8186
introduce DynTexture & DynTextureView
Wumpf Jul 17, 2024
7c9cd05
render/compute pass descriptors work now with dyn types
Wumpf Jul 17, 2024
043a83d
implement begin/end render/computepass for dyncommandencoder
Wumpf Jul 20, 2024
308eceb
bundle execute now takes a dyncommandencoder
Wumpf Jul 20, 2024
6448da4
render pass state now uses a DynCommandEncoder
Wumpf Jul 20, 2024
d940203
implement transition_textures for DynCommandEncoder
Wumpf Jul 20, 2024
6e53bf1
buffer / texture copy operations for DynCommandEncoder
Wumpf Jul 20, 2024
b63485d
texture & buffer transitioning always uses DynCommandEncoder now
Wumpf Jul 20, 2024
a2ec32e
move DynDevice to its own module
Wumpf Jul 20, 2024
cddbe9a
add most remaining dyn type traits
Wumpf Jul 20, 2024
d669816
impl DynShaderModule for all backends
Wumpf Jul 20, 2024
a1ecd0c
impl DynCommandBuffer
Wumpf Jul 21, 2024
b8a40f5
Device now has to implement DynResource
Wumpf Jul 21, 2024
f183f4e
impl DynFence for all fences
Wumpf Jul 21, 2024
530eea3
impl DynSurfaceTexture for all surface textures
Wumpf Jul 21, 2024
58f0cf2
introduce DynSurface
Wumpf Jul 21, 2024
a3a2cbb
introduce DynQueue
Wumpf Jul 21, 2024
942ba2e
implement buffer operations on DynDevice
Wumpf Jul 21, 2024
5680717
implement texture/textureview/sampler create/destroy methods on DynDe…
Wumpf Jul 24, 2024
7b55528
DynDevice create/destroy command encoder
Wumpf Jul 27, 2024
811c00c
DynDevice create/destroy bind group layout
Wumpf Jul 27, 2024
1170175
DynDevice create/destroy pipeline layout
Wumpf Jul 27, 2024
0a85c0a
DynDevice create/destroy bind group
Wumpf Jul 27, 2024
fc7233b
DynDevice create/destroy ShaderModule
Wumpf Jul 27, 2024
a4b8d59
DynDevice create/destroy compute/render pipeline
Wumpf Jul 28, 2024
304b27f
DynDevice pipeline cache
Wumpf Jul 28, 2024
d9b1f0c
DynDevice create/destroy query set
Wumpf Jul 28, 2024
4f2434e
DynDevice fence
Wumpf Jul 28, 2024
a4c0671
DynDevice wait/capture/pipeline_cache_get_data
Wumpf Jul 28, 2024
eeb7341
DynDevice accelleration structure handling
Wumpf Jul 28, 2024
15bc817
DynDevice exit, counters, report
Wumpf Jul 28, 2024
0f1f2df
fix wgpu-hal examples
Wumpf Jul 28, 2024
28c5ab2
DynCommandencoder end_encoding, reset_all
Wumpf Jul 28, 2024
da7cc0b
DynCommandEncoder accelleration structure building
Wumpf Jul 28, 2024
9167372
remove unnecessary debug constraints from Api (handled by Dyn traits)
Wumpf Jul 28, 2024
e175bb3
fix hal dynamic queue surface texture passing
Wumpf Jul 29, 2024
53d61aa
metal fixup: texture borrow
Wumpf Aug 5, 2024
188e349
The big unraveling: core device now has a boxed `DynDevice`, ripple e…
Wumpf Jul 20, 2024
8fe3f05
fixup unbox buffer
Wumpf Aug 4, 2024
08987fa
introduce DynAdapter
Wumpf Aug 4, 2024
0666429
introduce DynInstance
Wumpf Aug 4, 2024
b1c09c4
Core's Surface, Instance and Adapter use now dynamic hal types, fix r…
Wumpf Aug 4, 2024
301c0b2
Core adapter no longer uses any generics
Wumpf Aug 4, 2024
b22724b
The second unraveling: hub and all types on it are generic free!
Wumpf Aug 4, 2024
1719368
Remove `gfx_select`.
Wumpf Aug 6, 2024
c605369
remove dyn render & compute pass
Wumpf Aug 6, 2024
99e4285
ignore 'arc instead of rc' warnings on wasm
Wumpf Aug 10, 2024
bef23ee
re-enable docs for wgpu-core
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
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