Skip to content

Commit

Permalink
Flag to force GLES31 on ANGLE
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Aug 1, 2023
1 parent 09b010b commit 1d76410
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
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
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
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 1d76410

Please sign in to comment.