diff --git a/CHANGELOG.md b/CHANGELOG.md index e4603fc072..8b1a4c260e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ SurfaceConfiguration { - Split Blendability and Filterability into Two Different TextureFormatFeatureFlags; by @stakka in [#3012](https://github.com/gfx-rs/wgpu/pull/3012) - Expose `alpha_mode` on SurfaceConfiguration, by @jinleili in [#2836](https://github.com/gfx-rs/wgpu/pull/2836) - Introduce fields for driver name and info in `AdapterInfo`, by @i509VCB in [#3037](https://github.com/gfx-rs/wgpu/pull/3037) +- Implemented `copy_external_image_to_texture` on WebGPU, by @ybiletskyi in [#2781](https://github.com/gfx-rs/wgpu/pull/2781) ### Bug Fixes diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 78c5afdbd1..c524d654d5 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -215,7 +215,9 @@ web-sys = { version = "0.3.60", features = [ "GpuFragmentState", "GpuFrontFace", "GpuImageCopyBuffer", + "GpuImageCopyExternalImage", "GpuImageCopyTexture", + "GpuImageCopyTextureTagged", "GpuImageDataLayout", "GpuIndexFormat", "GpuLoadOp", @@ -294,5 +296,12 @@ parking_lot = ">=0.11,<0.13" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] console_error_panic_hook = "0.1.7" console_log = "0.2" -# We need the Location feature in the framework examples -web-sys = { version = "0.3.60", features = ["Location"] } +# We need these features in the framework examples +web-sys = { version = "0.3.60", features = [ + "Location", + "Blob", + "RequestInit", + "RequestMode", + "Request", + "Response" +] } diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index c366529756..ec3d3f322f 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -834,6 +834,15 @@ fn map_texture_copy_view(view: crate::ImageCopyTexture) -> web_sys::GpuImageCopy mapped } +fn map_tagged_texture_copy_view( + view: crate::ImageCopyTexture, +) -> web_sys::GpuImageCopyTextureTagged { + let mut mapped = web_sys::GpuImageCopyTextureTagged::new(&view.texture.id.0); + mapped.mip_level(view.mip_level); + mapped.origin(&map_origin_3d(view.origin)); + mapped +} + fn map_texture_aspect(aspect: wgt::TextureAspect) -> web_sys::GpuTextureAspect { match aspect { wgt::TextureAspect::All => web_sys::GpuTextureAspect::All, @@ -980,6 +989,22 @@ impl Context { }; Sendable(context.into()) } + + pub fn queue_copy_external_image_to_texture( + &self, + queue: &Sendable, + image: &web_sys::ImageBitmap, + texture: crate::ImageCopyTexture, + size: wgt::Extent3d, + ) { + queue + .0 + .copy_external_image_to_texture_with_gpu_extent_3d_dict( + &web_sys::GpuImageCopyExternalImage::new(image), + &map_tagged_texture_copy_view(texture), + &map_extent_3d(size), + ); + } } // The web doesn't provide any way to identify specific queue diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 52a77aba11..912989572f 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -3609,6 +3609,18 @@ impl Queue { Context::queue_write_texture(&*self.context, &self.id, texture, data, data_layout, size) } + /// Schedule a copy of data from `image` into `texture` + #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] + pub fn copy_external_image_to_texture( + &self, + image: &web_sys::ImageBitmap, + texture: ImageCopyTexture, + size: Extent3d, + ) { + self.context + .queue_copy_external_image_to_texture(&self.id, image, texture, size) + } + /// Submits a series of finished command buffers for execution. pub fn submit>( &self,