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

Implement copyExternalImageToTexture #2781

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions wgpu/Cargo.toml
Expand Up @@ -215,7 +215,9 @@ web-sys = { version = "0.3.60", features = [
"GpuFragmentState",
"GpuFrontFace",
"GpuImageCopyBuffer",
"GpuImageCopyExternalImage",
"GpuImageCopyTexture",
"GpuImageCopyTextureTagged",
"GpuImageDataLayout",
"GpuIndexFormat",
"GpuLoadOp",
Expand Down Expand Up @@ -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"
] }
25 changes: 25 additions & 0 deletions wgpu/src/backend/web.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -980,6 +989,22 @@ impl Context {
};
Sendable(context.into())
}

pub fn queue_copy_external_image_to_texture(
&self,
queue: &Sendable<web_sys::GpuQueue>,
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
Expand Down
12 changes: 12 additions & 0 deletions wgpu/src/lib.rs
Expand Up @@ -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")))]
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
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<I: IntoIterator<Item = CommandBuffer>>(
&self,
Expand Down