From b413f09b2a8f0b382f366d476374c01be329523f Mon Sep 17 00:00:00 2001 From: jprochazk Date: Tue, 27 Aug 2024 18:59:19 +0200 Subject: [PATCH 1/4] add `VideoFrame` to `ExternalImageSource` enum --- wgpu-hal/src/gles/queue.rs | 28 ++++++++++++++++++++++++++++ wgpu-types/Cargo.toml | 1 + wgpu-types/src/lib.rs | 5 +++++ 3 files changed, 34 insertions(+) diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index e1c08d6bd6..43ee74dc4f 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -502,6 +502,21 @@ impl super::Queue { v, ); }, + wgt::ExternalImageSource::VideoFrame(ref v) => unsafe { + gl.tex_sub_image_3d_with_video_frame( + dst_target, + copy.dst_base.mip_level as i32, + copy.dst_base.origin.x as i32, + copy.dst_base.origin.y as i32, + z_offset as i32, + copy.size.width as i32, + copy.size.height as i32, + copy.size.depth as i32, + format_desc.external, + format_desc.data_type, + v, + ) + }, wgt::ExternalImageSource::ImageData(ref i) => unsafe { gl.tex_sub_image_3d_with_image_data( dst_target, @@ -577,6 +592,19 @@ impl super::Queue { v, ) }, + wgt::ExternalImageSource::VideoFrame(ref v) => unsafe { + gl.tex_sub_image_2d_with_video_frame_and_width_and_height( + dst_target, + copy.dst_base.mip_level as i32, + copy.dst_base.origin.x as i32, + copy.dst_base.origin.y as i32, + copy.size.width as i32, + copy.size.height as i32, + format_desc.external, + format_desc.data_type, + v, + ) + }, wgt::ExternalImageSource::ImageData(ref i) => unsafe { gl.tex_sub_image_2d_with_image_data_and_width_and_height( dst_target, diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index e79b301342..6946ad6a0f 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -46,6 +46,7 @@ web-sys = { workspace = true, features = [ "HtmlVideoElement", "HtmlCanvasElement", "OffscreenCanvas", + "VideoFrame", ] } [dev-dependencies] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 4f15e68a17..826623ce44 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -6855,6 +6855,8 @@ pub enum ExternalImageSource { /// /// Requires [`DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES`] OffscreenCanvas(web_sys::OffscreenCanvas), + /// Copy from a video frame. + VideoFrame(web_sys::VideoFrame), } #[cfg(target_arch = "wasm32")] @@ -6868,6 +6870,7 @@ impl ExternalImageSource { ExternalImageSource::ImageData(i) => i.width(), ExternalImageSource::HTMLCanvasElement(c) => c.width(), ExternalImageSource::OffscreenCanvas(c) => c.width(), + ExternalImageSource::VideoFrame(v) => v.display_width(), } } @@ -6880,6 +6883,7 @@ impl ExternalImageSource { ExternalImageSource::ImageData(i) => i.height(), ExternalImageSource::HTMLCanvasElement(c) => c.height(), ExternalImageSource::OffscreenCanvas(c) => c.height(), + ExternalImageSource::VideoFrame(v) => v.display_height(), } } } @@ -6896,6 +6900,7 @@ impl std::ops::Deref for ExternalImageSource { Self::ImageData(i) => i, Self::HTMLCanvasElement(c) => c, Self::OffscreenCanvas(c) => c, + Self::VideoFrame(v) => v, } } } From ca479f28ecadfb36c593c121581b441d807b6126 Mon Sep 17 00:00:00 2001 From: jprochazk Date: Tue, 27 Aug 2024 19:26:14 +0200 Subject: [PATCH 2/4] add missing `HtmlImageElement` feature --- wgpu-types/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 6946ad6a0f..38bda98bc2 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -43,6 +43,7 @@ js-sys.workspace = true web-sys = { workspace = true, features = [ "ImageBitmap", "ImageData", + "HtmlImageElement", "HtmlVideoElement", "HtmlCanvasElement", "OffscreenCanvas", From 73ee33c60f7f028b3ddcc1ec3d7a3491930d579c Mon Sep 17 00:00:00 2001 From: jprochazk Date: Tue, 27 Aug 2024 19:32:02 +0200 Subject: [PATCH 3/4] gate `VideoFrame` behind `web_sys_unstable_apis` --- wgpu-hal/src/gles/queue.rs | 2 ++ wgpu-types/src/lib.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 43ee74dc4f..39315f72b7 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -502,6 +502,7 @@ impl super::Queue { v, ); }, + #[cfg(web_sys_unstable_apis)] wgt::ExternalImageSource::VideoFrame(ref v) => unsafe { gl.tex_sub_image_3d_with_video_frame( dst_target, @@ -592,6 +593,7 @@ impl super::Queue { v, ) }, + #[cfg(web_sys_unstable_apis)] wgt::ExternalImageSource::VideoFrame(ref v) => unsafe { gl.tex_sub_image_2d_with_video_frame_and_width_and_height( dst_target, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 826623ce44..410e0d8645 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -6856,6 +6856,7 @@ pub enum ExternalImageSource { /// Requires [`DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES`] OffscreenCanvas(web_sys::OffscreenCanvas), /// Copy from a video frame. + #[cfg(web_sys_unstable_apis)] VideoFrame(web_sys::VideoFrame), } @@ -6870,6 +6871,7 @@ impl ExternalImageSource { ExternalImageSource::ImageData(i) => i.width(), ExternalImageSource::HTMLCanvasElement(c) => c.width(), ExternalImageSource::OffscreenCanvas(c) => c.width(), + #[cfg(web_sys_unstable_apis)] ExternalImageSource::VideoFrame(v) => v.display_width(), } } @@ -6883,6 +6885,7 @@ impl ExternalImageSource { ExternalImageSource::ImageData(i) => i.height(), ExternalImageSource::HTMLCanvasElement(c) => c.height(), ExternalImageSource::OffscreenCanvas(c) => c.height(), + #[cfg(web_sys_unstable_apis)] ExternalImageSource::VideoFrame(v) => v.display_height(), } } @@ -6900,6 +6903,7 @@ impl std::ops::Deref for ExternalImageSource { Self::ImageData(i) => i, Self::HTMLCanvasElement(c) => c, Self::OffscreenCanvas(c) => c, + #[cfg(web_sys_unstable_apis)] Self::VideoFrame(v) => v, } } From eb2302254bc65d04c5c435aebc3171974aafc368 Mon Sep 17 00:00:00 2001 From: jprochazk Date: Tue, 27 Aug 2024 19:37:23 +0200 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d04c3c1e4..4625d97f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ By @teoxoy [#6134](https://github.com/gfx-rs/wgpu/pull/6134). - Deduplicate bind group layouts that are created from pipelines with "auto" layouts. By @teoxoy [#6049](https://github.com/gfx-rs/wgpu/pull/6049) - Fix crash when dropping the surface after the device. By @wumpf in [#6052](https://github.com/gfx-rs/wgpu/pull/6052) - Fix error message that is thrown in create_render_pass to no longer say `compute_pass`. By @matthew-wong1 [#6041](https://github.com/gfx-rs/wgpu/pull/6041) +- Add `VideoFrame` to `ExternalImageSource` enum. By @jprochazk in [#6170](https://github.com/gfx-rs/wgpu/pull/6170) #### GLES / OpenGL