Skip to content

Commit

Permalink
Flag to force GLES31 on ANGLE
Browse files Browse the repository at this point in the history
Fixes #3978
  • Loading branch information
PJB3005 committed Aug 1, 2023
1 parent 09b010b commit fcae97d
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/capture/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ async fn setup<E: Example>(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();
Expand Down
1 change: 1 addition & 0 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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,
});
}

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 {
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl<A: hal::Api> Example<A> {
},
// 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 {
Expand Down
13 changes: 10 additions & 3 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ impl Inner {
flags: crate::InstanceFlags,
egl: Arc<EglInstance>,
display: khronos_egl::Display,
angle_force_gles31: bool,
) -> Result<Self, crate::InstanceError> {
let version = egl.initialize(display).map_err(|_| crate::InstanceError)?;
let vendor = egl
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -836,7 +843,7 @@ impl crate::Instance<super::Api> 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 {
Expand Down Expand Up @@ -919,7 +926,7 @@ impl crate::Instance<super::Api> 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);
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6322,13 +6322,16 @@ 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 {
fn default() -> Self {
Self {
backends: Backends::all(),
dx12_shader_compiler: Dx12Compiler::default(),
force_angle_gles31: false,
}
}
}
Expand Down

0 comments on commit fcae97d

Please sign in to comment.