From aaeafd3641c73726b86be928aa5704eea19e5f54 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Tue, 1 Aug 2023 23:37:08 +0200 Subject: [PATCH] Flag to force GLES31 on ANGLE Fixes #3978 --- deno_webgpu/lib.rs | 1 + examples/capture/src/main.rs | 1 + examples/common/src/framework.rs | 1 + player/tests/test.rs | 1 + tests/src/lib.rs | 1 + tests/tests/instance.rs | 2 ++ wgpu-core/src/instance.rs | 1 + wgpu-hal/examples/halmark/main.rs | 1 + wgpu-hal/src/gles/egl.rs | 13 ++++++++++--- wgpu-hal/src/lib.rs | 1 + wgpu-types/src/lib.rs | 3 +++ 11 files changed, 23 insertions(+), 3 deletions(-) diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index f475723682..925890c62c 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -406,6 +406,7 @@ pub async fn op_webgpu_request_adapter( wgpu_types::InstanceDescriptor { backends, dx12_shader_compiler: wgpu_types::Dx12Compiler::Fxc, + force_angle_gles31: false }, ))); state.borrow::() diff --git a/examples/capture/src/main.rs b/examples/capture/src/main.rs index d36c3033ea..2039b47108 100644 --- a/examples/capture/src/main.rs +++ b/examples/capture/src/main.rs @@ -40,6 +40,7 @@ async fn create_red_image_with_dimensions( let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends, dx12_shader_compiler: wgpu::Dx12Compiler::default(), + force_angle_gles31: false, }); let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions::default()) diff --git a/examples/common/src/framework.rs b/examples/common/src/framework.rs index f26e136d81..4b1c134794 100644 --- a/examples/common/src/framework.rs +++ b/examples/common/src/framework.rs @@ -159,6 +159,7 @@ async fn setup(title: &str) -> Setup { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends, dx12_shader_compiler, + force_angle_gles31: false, }); let (size, surface) = unsafe { let size = window.inner_size(); diff --git a/player/tests/test.rs b/player/tests/test.rs index bbaa66cc4e..8b3ab29e08 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -185,6 +185,7 @@ impl Corpus { wgt::InstanceDescriptor { backends: corpus.backends, dx12_shader_compiler: wgt::Dx12Compiler::Fxc, + force_angle_gles31: false, }, ); for &backend in BACKENDS { diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 949afb48a0..d3f4f19d43 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -351,6 +351,7 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) { let instance = Instance::new(wgpu::InstanceDescriptor { backends, dx12_shader_compiler, + force_angle_gles31: true, }); let surface_guard; let compatible_surface; diff --git a/tests/tests/instance.rs b/tests/tests/instance.rs index e9ff6afff0..170c8bc86a 100644 --- a/tests/tests/instance.rs +++ b/tests/tests/instance.rs @@ -6,6 +6,7 @@ fn initialize() { let _ = wgpu::Instance::new(wgpu::InstanceDescriptor { backends: wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all), dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(), + force_angle_gles31: false, }); } @@ -13,6 +14,7 @@ fn request_adapter_inner(power: wgt::PowerPreference) { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends: wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all), dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(), + force_angle_gles31: false, }); let _adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 45f01824b7..b033667a99 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -82,6 +82,7 @@ impl Instance { name: "wgpu", flags, dx12_shader_compiler: instance_desc.dx12_shader_compiler.clone(), + force_angle_gles31: instance_desc.force_angle_gles31, }; unsafe { hal::Instance::init(&hal_desc).ok() } } else { diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 61c1584a25..2c76a99db8 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -96,6 +96,7 @@ impl Example { }, // Can't rely on having DXC available, so use FXC instead dx12_shader_compiler: wgt::Dx12Compiler::Fxc, + force_angle_gles31: false, }; let instance = unsafe { A::Instance::init(&instance_desc)? }; let mut surface = unsafe { diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 0c8e754971..42599ab8e8 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -491,6 +491,7 @@ impl Inner { flags: crate::InstanceFlags, egl: Arc, display: khronos_egl::Display, + angle_force_gles31: bool, ) -> Result { let version = egl.initialize(display).map_err(|_| crate::InstanceError)?; let vendor = egl @@ -542,9 +543,15 @@ impl Inner { //TODO: make it so `Device` == EGL Context let mut context_attributes = vec![ - khronos_egl::CONTEXT_CLIENT_VERSION, + khronos_egl::CONTEXT_MAJOR_VERSION, 3, // Request GLES 3.0 or higher ]; + + if angle_force_gles31 { + context_attributes.push(khronos_egl::CONTEXT_MINOR_VERSION); + context_attributes.push(1); + } + if flags.contains(crate::InstanceFlags::DEBUG) { if version >= (1, 5) { log::info!("\tEGL context: +debug"); @@ -836,7 +843,7 @@ impl crate::Instance for Instance { unsafe { (function)(Some(egl_debug_proc), attributes.as_ptr()) }; } - let inner = Inner::create(desc.flags, egl, display)?; + let inner = Inner::create(desc.flags, egl, display, desc.force_angle_gles31)?; Ok(Instance { wsi: WindowSystemInterface { @@ -919,7 +926,7 @@ impl crate::Instance for Instance { .unwrap(); let new_inner = - Inner::create(self.flags, Arc::clone(&inner.egl.instance), display) + Inner::create(self.flags, Arc::clone(&inner.egl.instance), display, false) .map_err(|_| crate::InstanceError)?; let old_inner = std::mem::replace(inner.deref_mut(), new_inner); diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 436553b29e..38df269da8 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -777,6 +777,7 @@ pub struct InstanceDescriptor<'a> { pub name: &'a str, pub flags: InstanceFlags, pub dx12_shader_compiler: wgt::Dx12Compiler, + pub force_angle_gles31: bool, } #[derive(Clone, Debug)] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 29619210e1..0f0e273060 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -6322,6 +6322,8 @@ pub struct InstanceDescriptor { pub backends: Backends, /// Which DX12 shader compiler to use. pub dx12_shader_compiler: Dx12Compiler, + /// Force ANGLE to support GLES 3.1, even on nonconformant implementations like D3D11. + pub force_angle_gles31: bool, } impl Default for InstanceDescriptor { @@ -6329,6 +6331,7 @@ impl Default for InstanceDescriptor { Self { backends: Backends::all(), dx12_shader_compiler: Dx12Compiler::default(), + force_angle_gles31: false, } } }