diff --git a/crates/wasi-webgpu-wasmtime/src/lib.rs b/crates/wasi-webgpu-wasmtime/src/lib.rs index 669940c..b320685 100644 --- a/crates/wasi-webgpu-wasmtime/src/lib.rs +++ b/crates/wasi-webgpu-wasmtime/src/lib.rs @@ -886,7 +886,8 @@ impl webgpu::HostGpuDevice for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, device: Resource) -> wasmtime::Result<()> { + self.table().delete(device).unwrap(); Ok(()) } } @@ -896,7 +897,7 @@ impl webgpu::HostGpuTexture for WasiWebGpuImpl { &mut self, buffer: Resource, ) -> Resource { - let host_buffer = self.0.table().delete(buffer).unwrap(); + let host_buffer = self.table().delete(buffer).unwrap(); let host_buffer: wgpu_core::id::TextureId = host_buffer.inner_type(); self.0.table().push(host_buffer).unwrap() } @@ -920,11 +921,6 @@ impl webgpu::HostGpuTexture for WasiWebGpuImpl { self.0.table().push(texture_view).unwrap() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - // TODO: - Ok(()) - } - fn destroy(&mut self, _self_: Resource) { todo!() } @@ -974,13 +970,14 @@ impl webgpu::HostGpuTexture for WasiWebGpuImpl { fn set_label(&mut self, _self_: Resource, _label: String) { todo!() } -} -impl webgpu::HostGpuTextureView for WasiWebGpuImpl { - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, texture: Resource) -> wasmtime::Result<()> { + self.table().delete(texture).unwrap(); Ok(()) } +} +impl webgpu::HostGpuTextureView for WasiWebGpuImpl { fn label(&mut self, _self_: Resource) -> String { todo!() } @@ -988,6 +985,11 @@ impl webgpu::HostGpuTextureView for WasiWebGpuImpl { fn set_label(&mut self, _self_: Resource, _label: String) { todo!() } + + fn drop(&mut self, view: Resource) -> wasmtime::Result<()> { + self.table().delete(view).unwrap(); + Ok(()) + } } impl webgpu::HostGpuCommandBuffer for WasiWebGpuImpl { @@ -1000,7 +1002,7 @@ impl webgpu::HostGpuCommandBuffer for WasiWebGpuImpl { } fn drop(&mut self, command_buffer: Resource) -> wasmtime::Result<()> { - self.0.table().delete(command_buffer).unwrap(); + self.table().delete(command_buffer).unwrap(); Ok(()) } } @@ -1008,20 +1010,21 @@ impl webgpu::HostGpuCommandBuffer for WasiWebGpuImpl { impl webgpu::HostGpuShaderModule for WasiWebGpuImpl { fn get_compilation_info( &mut self, - _self_: Resource, + _self_: Resource, ) -> Resource { todo!() } - fn label(&mut self, _self_: Resource) -> String { + fn label(&mut self, _self_: Resource) -> String { todo!() } - fn set_label(&mut self, _self_: Resource, _label: String) { + fn set_label(&mut self, _self_: Resource, _label: String) { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, shader: Resource) -> wasmtime::Result<()> { + self.table().delete(shader).unwrap(); Ok(()) } } @@ -1043,7 +1046,8 @@ impl webgpu::HostGpuRenderPipeline for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, pipeline: Resource) -> wasmtime::Result<()> { + self.table().delete(pipeline).unwrap(); Ok(()) } } @@ -1082,10 +1086,6 @@ impl webgpu::HostGpuAdapter for WasiWebGpuImpl { device } - fn drop(&mut self, _adapter: Resource) -> wasmtime::Result<()> { - Ok(()) - } - fn features( &mut self, adapter: wasmtime::component::Resource, @@ -1124,13 +1124,17 @@ impl webgpu::HostGpuAdapter for WasiWebGpuImpl { ) -> Resource { let adapter_id = *self.0.table().get(&adapter).unwrap(); let info = self - .0 .instance() .adapter_get_info::(adapter_id) .unwrap(); let info = self.0.table().push(info).unwrap(); info } + + fn drop(&mut self, adapter: Resource) -> wasmtime::Result<()> { + self.table().delete(adapter).unwrap(); + Ok(()) + } } impl webgpu::HostGpuQueue for WasiWebGpuImpl { @@ -1210,7 +1214,7 @@ impl webgpu::HostGpuQueue for WasiWebGpuImpl { } fn drop(&mut self, queue: Resource) -> wasmtime::Result<()> { - self.0.table().delete(queue).unwrap(); + self.table().delete(queue).unwrap(); Ok(()) } } @@ -1272,14 +1276,6 @@ impl webgpu::HostGpuCommandEncoder for WasiWebGpuImpl { self.0.table().push(command_buffer).unwrap() } - fn drop( - &mut self, - command_encoder: Resource, - ) -> wasmtime::Result<()> { - self.0.table().delete(command_encoder).unwrap(); - Ok(()) - } - fn begin_compute_pass( &mut self, command_encoder: Resource, @@ -1432,6 +1428,14 @@ impl webgpu::HostGpuCommandEncoder for WasiWebGpuImpl { .command_encoder_insert_debug_marker::(command_encoder, &marker_label) .unwrap(); } + + fn drop( + &mut self, + command_encoder: Resource, + ) -> wasmtime::Result<()> { + self.table().delete(command_encoder).unwrap(); + Ok(()) + } } impl webgpu::HostGpuRenderPassEncoder for WasiWebGpuImpl { @@ -1477,14 +1481,6 @@ impl webgpu::HostGpuRenderPassEncoder for WasiWebGpuImpl { .unwrap(); } - fn drop( - &mut self, - render_pass: Resource>, - ) -> wasmtime::Result<()> { - self.0.table().delete(render_pass).unwrap(); - Ok(()) - } - fn set_viewport( &mut self, render_pass: Resource>, @@ -1707,6 +1703,14 @@ impl webgpu::HostGpuRenderPassEncoder for WasiWebGpuImpl { ) { todo!() } + + fn drop( + &mut self, + render_pass: Resource>, + ) -> wasmtime::Result<()> { + self.table().delete(render_pass).unwrap(); + Ok(()) + } } impl webgpu::HostGpuUncapturedErrorEvent for WasiWebGpuImpl { @@ -1725,8 +1729,9 @@ impl webgpu::HostGpuUncapturedErrorEvent for WasiWebGpuImpl) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, error: Resource) -> wasmtime::Result<()> { + self.table().delete(error).unwrap(); + Ok(()) } } impl webgpu::HostGpuInternalError for WasiWebGpuImpl { @@ -1738,8 +1743,9 @@ impl webgpu::HostGpuInternalError for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, error: Resource) -> wasmtime::Result<()> { + self.table().delete(error).unwrap(); + Ok(()) } } impl webgpu::HostGpuOutOfMemoryError for WasiWebGpuImpl { @@ -1751,8 +1757,9 @@ impl webgpu::HostGpuOutOfMemoryError for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, error: Resource) -> wasmtime::Result<()> { + self.table().delete(error).unwrap(); + Ok(()) } } impl webgpu::HostGpuValidationError for WasiWebGpuImpl { @@ -1764,8 +1771,9 @@ impl webgpu::HostGpuValidationError for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, error: Resource) -> wasmtime::Result<()> { + self.table().delete(error).unwrap(); + Ok(()) } } impl webgpu::HostGpuError for WasiWebGpuImpl { @@ -1773,8 +1781,9 @@ impl webgpu::HostGpuError for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, error: Resource) -> wasmtime::Result<()> { + self.table().delete(error).unwrap(); + Ok(()) } } impl webgpu::HostGpuDeviceLostInfo for WasiWebGpuImpl { @@ -1789,8 +1798,9 @@ impl webgpu::HostGpuDeviceLostInfo for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, info: Resource) -> wasmtime::Result<()> { + self.table().delete(info).unwrap(); + Ok(()) } } impl webgpu::HostGpuCanvasContext for WasiWebGpuImpl { @@ -1826,8 +1836,9 @@ impl webgpu::HostGpuRenderBundle for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, bundle: Resource) -> wasmtime::Result<()> { + self.table().delete(bundle).unwrap(); + Ok(()) } } impl webgpu::HostGpuComputePassEncoder for WasiWebGpuImpl { @@ -1932,8 +1943,8 @@ impl webgpu::HostGpuComputePassEncoder for WasiWebGpuImpl .unwrap() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - self.0.table().delete(_rep).unwrap(); + fn drop(&mut self, encoder: Resource) -> wasmtime::Result<()> { + self.table().delete(encoder).unwrap(); Ok(()) } } @@ -1953,8 +1964,9 @@ impl webgpu::HostGpuPipelineError for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, error: Resource) -> wasmtime::Result<()> { + self.table().delete(error).unwrap(); + Ok(()) } } impl webgpu::HostGpuCompilationMessage for WasiWebGpuImpl { @@ -1985,8 +1997,9 @@ impl webgpu::HostGpuCompilationMessage for WasiWebGpuImpl todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, cm: Resource) -> wasmtime::Result<()> { + self.table().delete(cm).unwrap(); + Ok(()) } } impl webgpu::HostGpuCompilationInfo for WasiWebGpuImpl { @@ -1997,8 +2010,9 @@ impl webgpu::HostGpuCompilationInfo for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, info: Resource) -> wasmtime::Result<()> { + self.table().delete(info).unwrap(); + Ok(()) } } impl webgpu::HostGpuQuerySet for WasiWebGpuImpl { @@ -2022,8 +2036,9 @@ impl webgpu::HostGpuQuerySet for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, query_set: Resource) -> wasmtime::Result<()> { + self.table().delete(query_set).unwrap(); + Ok(()) } } impl webgpu::HostGpuRenderBundleEncoder for WasiWebGpuImpl { @@ -2144,8 +2159,9 @@ impl webgpu::HostGpuRenderBundleEncoder for WasiWebGpuImpl todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, encoder: Resource) -> wasmtime::Result<()> { + self.table().push(encoder).unwrap(); + Ok(()) } } impl webgpu::HostGpuComputePipeline for WasiWebGpuImpl { @@ -2172,8 +2188,8 @@ impl webgpu::HostGpuComputePipeline for WasiWebGpuImpl { self.0.table().push(bind_group_layout).unwrap() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - // TODO: + fn drop(&mut self, pipeline: Resource) -> wasmtime::Result<()> { + self.table().push(pipeline).unwrap(); Ok(()) } } @@ -2186,7 +2202,8 @@ impl webgpu::HostGpuBindGroup for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, bind_group: Resource) -> wasmtime::Result<()> { + self.table().delete(bind_group).unwrap(); Ok(()) } } @@ -2199,7 +2216,8 @@ impl webgpu::HostGpuPipelineLayout for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, layout: Resource) -> wasmtime::Result<()> { + self.table().delete(layout).unwrap(); Ok(()) } } @@ -2212,8 +2230,8 @@ impl webgpu::HostGpuBindGroupLayout for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - // TODO: + fn drop(&mut self, layout: Resource) -> wasmtime::Result<()> { + self.table().delete(layout).unwrap(); Ok(()) } } @@ -2227,8 +2245,8 @@ impl webgpu::HostGpuSampler for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - // TODO: + fn drop(&mut self, sampler: Resource) -> wasmtime::Result<()> { + self.table().delete(sampler).unwrap(); Ok(()) } } @@ -2326,7 +2344,8 @@ impl webgpu::HostGpuBuffer for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, buffer: Resource) -> wasmtime::Result<()> { + self.table().delete(buffer).unwrap(); Ok(()) } } @@ -2365,7 +2384,8 @@ impl webgpu::HostGpu for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, _gpu: Resource) -> wasmtime::Result<()> { + // not actually a resource in the table Ok(()) } } @@ -2386,8 +2406,8 @@ impl webgpu::HostGpuAdapterInfo for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - // TODO: + fn drop(&mut self, info: Resource) -> wasmtime::Result<()> { + self.table().delete(info).unwrap(); Ok(()) } } @@ -2396,8 +2416,9 @@ impl webgpu::HostWgslLanguageFeatures for WasiWebGpuImpl { todo!() } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - todo!() + fn drop(&mut self, features: Resource) -> wasmtime::Result<()> { + self.table().delete(features).unwrap(); + Ok(()) } } impl webgpu::HostGpuSupportedFeatures for WasiWebGpuImpl { @@ -2431,7 +2452,8 @@ impl webgpu::HostGpuSupportedFeatures for WasiWebGpuImpl { } } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { + fn drop(&mut self, features: Resource) -> wasmtime::Result<()> { + self.table().delete(features).unwrap(); Ok(()) } } @@ -2650,8 +2672,8 @@ impl webgpu::HostGpuSupportedLimits for WasiWebGpuImpl { limits.max_compute_workgroups_per_dimension } - fn drop(&mut self, _rep: Resource) -> wasmtime::Result<()> { - // TODO: + fn drop(&mut self, limits: Resource) -> wasmtime::Result<()> { + self.table().delete(limits).unwrap(); Ok(()) } }