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

WebGL2 multiview support via OVR_multiview2 #3121

Merged
merged 4 commits into from
Oct 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::num::NonZeroU32>,
}

impl CompilationContext<'_> {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -269,6 +270,7 @@ impl super::Device {
shaders: I,
layout: &super::PipelineLayout,
#[cfg_attr(target_arch = "wasm32", allow(unused))] label: Option<&str>,
multiview: Option<std::num::NonZeroU32>,
) -> Result<super::PipelineInner, crate::PipelineError> {
let program = gl.create_program().unwrap();
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -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)?;
Expand Down Expand Up @@ -1032,7 +1035,7 @@ impl crate::Device<super::Api> 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();
Expand Down Expand Up @@ -1100,7 +1103,7 @@ impl crate::Device<super::Api> for super::Device {
) -> Result<super::ComputePipeline, crate::PipelineError> {
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 })
}
Expand Down
13 changes: 12 additions & 1 deletion wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(all(target_arch = "wasm32", target_os = "unknown"))]
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,
Expand Down
1 change: 1 addition & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ bitflags::bitflags! {
///
/// Supported platforms:
/// - Vulkan
/// - OpenGL (web only)
///
/// This is a native only feature.
const MULTIVIEW = 1 << 37;
Expand Down