Skip to content

Commit

Permalink
Allow specifying minor GLES3 version (#3998)
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 authored Aug 16, 2023
1 parent e11526e commit e973a06
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ let render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {

By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402)

### Added/New Features

- Add `gles_minor_version` field to `wgpu::InstanceDescriptor`. By @PJB3005 in [#3998](https://github.com/gfx-rs/wgpu/pull/3998)

### Changes

- Omit texture store bound checks since they are no-ops if out of bounds on all APIs. By @teoxoy in [#3975](https://github.com/gfx-rs/wgpu/pull/3975)
Expand All @@ -74,6 +78,7 @@ By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402)

- Don't bother calling `vkFreeCommandBuffers` when `vkDestroyCommandPool` will take care of that for us. By @jimblandy in [#4059](https://github.com/gfx-rs/wgpu/pull/4059)


### Bug Fixes

#### General
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ All testing and example infrastructure shares the same set of environment variab
- `WGPU_BACKEND` with a comma separated list of the backends you want to use (`vulkan`, `metal`, `dx12`, `dx11`, or `gl`).
- `WGPU_POWER_PREF` with the power preference to choose when a specific adapter name isn't specified (`high` or `low`)
- `WGPU_DX12_COMPILER` with the DX12 shader compiler you wish to use (`dxc` or `fxc`, note that `dxc` requires `dxil.dll` and `dxcompiler.dll` to be in the working directory otherwise it will fall back to `fxc`)
- `WGPU_GLES_MINOR_VERSION` with the minor OpenGL ES 3 version number to request (`0`, `1`, `2` or `automatic`).

When running the CTS, use the variables `DENO_WEBGPU_ADAPTER_NAME`, `DENO_WEBGPU_BACKEND`, `DENO_WEBGPU_POWER_PREFERENCE`.

Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ pub async fn op_webgpu_request_adapter(
wgpu_types::InstanceDescriptor {
backends,
dx12_shader_compiler: wgpu_types::Dx12Compiler::Fxc,
gles_minor_version: wgpu_types::Gles3MinorVersion::default(),
},
)));
state.borrow::<Instance>()
Expand Down
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(),
gles_minor_version: wgpu::Gles3MinorVersion::default(),
});
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions::default())
Expand Down
2 changes: 2 additions & 0 deletions examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ async fn setup<E: Example>(title: &str) -> Setup {

let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default();
let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default();

let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
dx12_shader_compiler,
gles_minor_version,
});
let (size, surface) = unsafe {
let size = window.inner_size();
Expand Down
1 change: 1 addition & 0 deletions examples/timestamp-queries/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ async fn run() {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
dx12_shader_compiler: wgpu::Dx12Compiler::default(),
gles_minor_version: wgpu::Gles3MinorVersion::default(),
});

// `request_adapter` instantiates the general connection to the GPU
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,
gles_minor_version: wgt::Gles3MinorVersion::default(),
},
);
for &backend in BACKENDS {
Expand Down
2 changes: 2 additions & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,11 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te
fn initialize_adapter() -> (Adapter, SurfaceGuard) {
let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(Backends::all);
let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default();
let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default();
let instance = Instance::new(wgpu::InstanceDescriptor {
backends,
dx12_shader_compiler,
gles_minor_version,
});
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(),
gles_minor_version: wgpu::util::gles_minor_version_from_env().unwrap_or_default(),
});
}

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(),
gles_minor_version: wgpu::util::gles_minor_version_from_env().unwrap_or_default(),
});

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(),
gles_minor_version: instance_desc.gles_minor_version,
};
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,
gles_minor_version: wgt::Gles3MinorVersion::default(),
};
let instance = unsafe { A::Instance::init(&instance_desc)? };
let mut surface = unsafe {
Expand Down
29 changes: 24 additions & 5 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ struct Inner {
config: khronos_egl::Config,
#[cfg_attr(target_os = "emscripten", allow(dead_code))]
wl_display: Option<*mut raw::c_void>,
#[cfg_attr(target_os = "emscripten", allow(dead_code))]
force_gles_minor_version: wgt::Gles3MinorVersion,
/// Method by which the framebuffer should support srgb
srgb_kind: SrgbFrameBufferKind,
}
Expand All @@ -491,6 +493,7 @@ impl Inner {
flags: crate::InstanceFlags,
egl: Arc<EglInstance>,
display: khronos_egl::Display,
force_gles_minor_version: wgt::Gles3MinorVersion,
) -> Result<Self, crate::InstanceError> {
let version = egl.initialize(display).map_err(|_| crate::InstanceError)?;
let vendor = egl
Expand Down Expand Up @@ -542,9 +545,20 @@ 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 force_gles_minor_version != wgt::Gles3MinorVersion::Automatic {
context_attributes.push(khronos_egl::CONTEXT_MINOR_VERSION);
context_attributes.push(match force_gles_minor_version {
wgt::Gles3MinorVersion::Version0 => 0,
wgt::Gles3MinorVersion::Version1 => 1,
wgt::Gles3MinorVersion::Version2 => 2,
_ => unreachable!(),
});
}

if flags.contains(crate::InstanceFlags::DEBUG) {
if version >= (1, 5) {
log::info!("\tEGL context: +debug");
Expand Down Expand Up @@ -627,6 +641,7 @@ impl Inner {
config,
wl_display: None,
srgb_kind,
force_gles_minor_version,
})
}
}
Expand Down Expand Up @@ -836,7 +851,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.gles_minor_version)?;

Ok(Instance {
wsi: WindowSystemInterface {
Expand Down Expand Up @@ -918,9 +933,13 @@ impl crate::Instance<super::Api> for Instance {
)
.unwrap();

let new_inner =
Inner::create(self.flags, Arc::clone(&inner.egl.instance), display)
.map_err(|_| crate::InstanceError)?;
let new_inner = Inner::create(
self.flags,
Arc::clone(&inner.egl.instance),
display,
inner.force_gles_minor_version,
)
.map_err(|_| crate::InstanceError)?;

let old_inner = std::mem::replace(inner.deref_mut(), new_inner);
inner.wl_display = Some(display_handle.display);
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 @@ -787,6 +787,7 @@ pub struct InstanceDescriptor<'a> {
pub name: &'a str,
pub flags: InstanceFlags,
pub dx12_shader_compiler: wgt::Dx12Compiler,
pub gles_minor_version: wgt::Gles3MinorVersion,
}

#[derive(Clone, Debug)]
Expand Down
22 changes: 22 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6399,19 +6399,41 @@ pub enum Dx12Compiler {
},
}

/// Selects which OpenGL ES 3 minor version to request.
///
/// When using ANGLE as an OpenGL ES/EGL implementation, explicitly requesting `Version1` can provide a non-conformant ES 3.1 on APIs like D3D11.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)]
pub enum Gles3MinorVersion {
/// No explicit minor version is requested, the driver automatically picks the highest available.
#[default]
Automatic,

/// Request an ES 3.0 context.
Version0,

/// Request an ES 3.1 context.
Version1,

/// Request an ES 3.2 context.
Version2,
}

/// Options for creating an instance.
pub struct InstanceDescriptor {
/// Which `Backends` to enable.
pub backends: Backends,
/// Which DX12 shader compiler to use.
pub dx12_shader_compiler: Dx12Compiler,
/// Which OpenGL ES 3 minor version to request.
pub gles_minor_version: Gles3MinorVersion,
}

impl Default for InstanceDescriptor {
fn default() -> Self {
Self {
backends: Backends::all(),
dx12_shader_compiler: Dx12Compiler::default(),
gles_minor_version: Gles3MinorVersion::default(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pub use wgt::{
BufferBindingType, BufferSize, BufferUsages, Color, ColorTargetState, ColorWrites,
CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, DepthBiasState,
DepthStencilState, DeviceType, DownlevelCapabilities, DownlevelFlags, Dx12Compiler,
DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, ImageDataLayout,
ImageSubresourceRange, IndexFormat, InstanceDescriptor, Limits, MultisampleState, Origin2d,
Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, PredefinedColorSpace,
PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology, PushConstantRange,
QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor, ShaderLocation,
ShaderModel, ShaderStages, StencilFaceState, StencilOperation, StencilState,
DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, Gles3MinorVersion,
ImageDataLayout, ImageSubresourceRange, IndexFormat, InstanceDescriptor, Limits,
MultisampleState, Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference,
PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,
PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor,
ShaderLocation, ShaderModel, ShaderStages, StencilFaceState, StencilOperation, StencilState,
StorageTextureAccess, SurfaceCapabilities, SurfaceStatus, TextureAspect, TextureDimension,
TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType,
TextureUsages, TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode,
Expand Down
19 changes: 19 additions & 0 deletions wgpu/src/util/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,22 @@ pub fn dx12_shader_compiler_from_env() -> Option<wgt::Dx12Compiler> {
},
)
}

/// Choose which minor OpenGL ES version to use from the environment variable `WGPU_GLES_MINOR_VERSION`.
///
/// Possible values are `0`, `1`, `2` or `automatic`. Case insensitive.
pub fn gles_minor_version_from_env() -> Option<wgt::Gles3MinorVersion> {
Some(
match std::env::var("WGPU_GLES_MINOR_VERSION")
.as_deref()
.map(str::to_lowercase)
.as_deref()
{
Ok("automatic") => wgt::Gles3MinorVersion::Automatic,
Ok("0") => wgt::Gles3MinorVersion::Version0,
Ok("1") => wgt::Gles3MinorVersion::Version1,
Ok("2") => wgt::Gles3MinorVersion::Version2,
_ => return None,
},
)
}

0 comments on commit e973a06

Please sign in to comment.