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 1 commit
Commits
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
3 changes: 3 additions & 0 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ web-sys = { version = "0.3.57", features = [
"GpuFragmentState",
"GpuFrontFace",
"GpuImageCopyBuffer",
"GpuImageCopyExternalImage",
"GpuImageCopyTexture",
"GpuImageCopyTextureTagged",
"GpuImageDataLayout",
"GpuIndexFormat",
"GpuLoadOp",
Expand Down Expand Up @@ -280,6 +282,7 @@ web-sys = { version = "0.3.57", features = [
"GpuVertexState",
"GpuVertexStepMode",
"HtmlCanvasElement",
"ImageBitmap",
"OffscreenCanvas",
"Window"
] }
Expand Down
23 changes: 23 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,13 @@ 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 @@ -969,6 +976,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),
);
}
}

impl crate::Context for Context {
Expand Down
11 changes: 11 additions & 0 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3373,6 +3373,17 @@ 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