From 34f2b3934cd67270e86c1181ced71ca0ef0ec63b Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 17 Oct 2022 11:51:39 +0200 Subject: [PATCH 1/4] Add OVR_multiview2 support --- wgpu-hal/src/gles/adapter.rs | 4 ++++ wgpu-hal/src/gles/device.rs | 9 ++++++--- wgpu-hal/src/gles/queue.rs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 8e2eda06f9..53b11029d0 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -330,6 +330,10 @@ impl super::Adapter { downlevel_flags.contains(wgt::DownlevelFlags::VERTEX_STORAGE) && vertex_shader_storage_textures != 0, ); + features.set( + wgt::Features::MULTIVIEW, + extensions.contains("OVR_multiview2"), + ); let gles_bcn_exts = [ "GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_rgtc", diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 6756d1884c..96be1f569b 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -20,6 +20,7 @@ struct CompilationContext<'a> { layout: &'a super::PipelineLayout, sampler_map: &'a mut super::SamplerBindMap, name_binding_map: &'a mut NameBindingMap, + multiview: Option, } impl CompilationContext<'_> { @@ -205,7 +206,7 @@ impl super::Device { let pipeline_options = glsl::PipelineOptions { shader_stage: naga_stage, entry_point: stage.entry_point.to_string(), - multiview: None, + multiview: context.multiview, }; let shader = &stage.module.naga; @@ -269,6 +270,7 @@ impl super::Device { shaders: I, layout: &super::PipelineLayout, #[cfg_attr(target_arch = "wasm32", allow(unused))] label: Option<&str>, + multiview: Option, ) -> Result { let program = gl.create_program().unwrap(); #[cfg(not(target_arch = "wasm32"))] @@ -289,6 +291,7 @@ impl super::Device { layout, sampler_map: &mut sampler_map, name_binding_map: &mut name_binding_map, + multiview, }; let shader = Self::create_shader(gl, naga_stage, stage, context)?; @@ -1032,7 +1035,7 @@ impl crate::Device for super::Device { .as_ref() .map(|fs| (naga::ShaderStage::Fragment, fs)), ); - let inner = self.create_pipeline(gl, shaders, desc.layout, desc.label)?; + let inner = self.create_pipeline(gl, shaders, desc.layout, desc.label, desc.multiview)?; let (vertex_buffers, vertex_attributes) = { let mut buffers = Vec::new(); @@ -1100,7 +1103,7 @@ impl crate::Device for super::Device { ) -> Result { let gl = &self.shared.context.lock(); let shaders = iter::once((naga::ShaderStage::Compute, &desc.stage)); - let inner = self.create_pipeline(gl, shaders, desc.layout, desc.label)?; + let inner = self.create_pipeline(gl, shaders, desc.layout, desc.label, None)?; Ok(super::ComputePipeline { inner }) } diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 6cdccd9141..8cab23d5e3 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -89,7 +89,18 @@ impl super::Queue { } super::TextureInner::DefaultRenderbuffer => panic!("Unexpected default RBO"), super::TextureInner::Texture { raw, target } => { - if is_layered_target(target) { + let num_layers = view.array_layers.end - view.array_layers.start; + if num_layers > 1 { + #[cfg(target_arch = "wasm32")] + gl.framebuffer_texture_multiview_ovr( + fbo_target, + attachment, + Some(raw), + view.mip_levels.start as i32, + view.array_layers.start as i32, + num_layers as i32, + ); + } else if is_layered_target(target) { gl.framebuffer_texture_layer( fbo_target, attachment, From 8e1cfde8931dc30ce6394b436c6807e8650ea2bd Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 17 Oct 2022 12:00:46 +0200 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b243a6c4e..e382edc101 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,10 @@ Bottom level categories: #### WebGPU - Implement `queue_validate_write_buffer` by @jinleili in [#3098](https://github.com/gfx-rs/wgpu/pull/3098) +#### GLES + +- Browsers that support `OVR_multiview2` now report the `MULTIVIEW` feature by @expenses in [#3121](https://github.com/gfx-rs/wgpu/pull/3121). + ### Added/New Features #### General From 13d066bfff616152f051e9179ab35daef6756a53 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 17 Oct 2022 12:35:06 +0200 Subject: [PATCH 3/4] Only use multiview on wasm32 + unknown --- wgpu-hal/src/gles/queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 8cab23d5e3..69edfd5c86 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -91,7 +91,7 @@ impl super::Queue { super::TextureInner::Texture { raw, target } => { let num_layers = view.array_layers.end - view.array_layers.start; if num_layers > 1 { - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] gl.framebuffer_texture_multiview_ovr( fbo_target, attachment, From a4cce3e7ecd3e796568cea7abae1f56b13822ed6 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Tue, 18 Oct 2022 17:10:02 +0200 Subject: [PATCH 4/4] Add note to Features::MULTIVIEW --- wgpu-types/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index ed82c00ded..9fce6ca524 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -586,6 +586,7 @@ bitflags::bitflags! { /// /// Supported platforms: /// - Vulkan + /// - OpenGL (web only) /// /// This is a native only feature. const MULTIVIEW = 1 << 37;