mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 08:53:20 +00:00
Prefer OpenGL over OpenGL ES (#5482)
* Prefer OpenGL over OpenGL ES * Fix sRGB on egl * Check if OpenGL is supported * Add changelog entry * Remove expected failure for OpenGL Non-ES, add comment explaining FRAMEBUFFER_SRGB, add driver info to AdapterInfo * Fix draw indexed * CI host doesn't seem to support Rg8Snorm and Rgb9eUfloat clearing
This commit is contained in:
parent
2b0e3ed01c
commit
0dc9dd6bec
@ -171,6 +171,9 @@ Bottom level categories:
|
||||
- Don't create a program for shader-clearing if that workaround isn't required. By @Dinnerbone in [#5348](https://github.com/gfx-rs/wgpu/pull/5348).
|
||||
- Fix crash when holding multiple devices on wayland/surfaceless. By @ashdnazg in [#5351](https://github.com/gfx-rs/wgpu/pull/5351).
|
||||
- Don't depend on bind group and bind group layout entry order in HAL. This caused incorrect severely incorrect command execution and, in some cases, crashes. By @ErichDonGubler in [#5421](https://github.com/gfx-rs/wgpu/pull/5421).
|
||||
- OpenGL will now be preferred over OpenGL ES on EGL, making it consistent with WGL. By @valaphee in [#5482](https://github.com/gfx-rs/wgpu/pull/5482)
|
||||
- Fix `first_instance` getting ignored in draw indexed when `ARB_shader_draw_parameters` feature is present and `base_vertex` is 0. By @valaphee in [#5482](https://github.com/gfx-rs/wgpu/pull/5482)
|
||||
- Fill out `driver` and `driver_info`, with the OpenGL flavor and version, similar to Vulkan. By @valaphee in [#5482](https://github.com/gfx-rs/wgpu/pull/5482)
|
||||
|
||||
#### Vulkan
|
||||
|
||||
|
@ -104,7 +104,7 @@ impl super::Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_info(vendor_orig: String, renderer_orig: String) -> wgt::AdapterInfo {
|
||||
fn make_info(vendor_orig: String, renderer_orig: String, version: String) -> wgt::AdapterInfo {
|
||||
let vendor = vendor_orig.to_lowercase();
|
||||
let renderer = renderer_orig.to_lowercase();
|
||||
|
||||
@ -179,13 +179,33 @@ impl super::Adapter {
|
||||
0
|
||||
};
|
||||
|
||||
let driver;
|
||||
let driver_info;
|
||||
if version.starts_with("WebGL ") || version.starts_with("OpenGL ") {
|
||||
let es_sig = " ES";
|
||||
match version.find(es_sig) {
|
||||
Some(pos) => {
|
||||
driver = version[..pos + es_sig.len()].to_owned();
|
||||
driver_info = version[pos + es_sig.len() + 1..].to_owned();
|
||||
}
|
||||
None => {
|
||||
let pos = version.find(' ').unwrap();
|
||||
driver = version[..pos].to_owned();
|
||||
driver_info = version[pos + 1..].to_owned();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
driver = "OpenGL".to_owned();
|
||||
driver_info = version;
|
||||
}
|
||||
|
||||
wgt::AdapterInfo {
|
||||
name: renderer_orig,
|
||||
vendor: vendor_id,
|
||||
device: 0,
|
||||
device_type: inferred_device_type,
|
||||
driver: String::new(),
|
||||
driver_info: String::new(),
|
||||
driver,
|
||||
driver_info,
|
||||
backend: wgt::Backend::Gl,
|
||||
}
|
||||
}
|
||||
@ -825,7 +845,7 @@ impl super::Adapter {
|
||||
max_msaa_samples: max_samples,
|
||||
}),
|
||||
},
|
||||
info: Self::make_info(vendor, renderer),
|
||||
info: Self::make_info(vendor, renderer, version),
|
||||
features,
|
||||
capabilities: crate::Capabilities {
|
||||
limits,
|
||||
|
@ -526,7 +526,24 @@ impl Inner {
|
||||
}
|
||||
|
||||
let (config, supports_native_window) = choose_config(&egl, display, srgb_kind)?;
|
||||
egl.bind_api(khronos_egl::OPENGL_ES_API).unwrap();
|
||||
|
||||
let supports_opengl = if version >= (1, 4) {
|
||||
let client_apis = egl
|
||||
.query_string(Some(display), khronos_egl::CLIENT_APIS)
|
||||
.unwrap()
|
||||
.to_string_lossy();
|
||||
client_apis
|
||||
.split(' ')
|
||||
.any(|client_api| client_api == "OpenGL")
|
||||
} else {
|
||||
false
|
||||
};
|
||||
egl.bind_api(if supports_opengl {
|
||||
khronos_egl::OPENGL_API
|
||||
} else {
|
||||
khronos_egl::OPENGL_ES_API
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let needs_robustness = true;
|
||||
let mut khr_context_flags = 0;
|
||||
@ -977,6 +994,7 @@ impl crate::Instance for Instance {
|
||||
srgb_kind: inner.srgb_kind,
|
||||
})
|
||||
}
|
||||
|
||||
unsafe fn destroy_surface(&self, _surface: Surface) {}
|
||||
|
||||
unsafe fn enumerate_adapters(&self) -> Vec<crate::ExposedAdapter<super::Api>> {
|
||||
@ -993,6 +1011,12 @@ impl crate::Instance for Instance {
|
||||
})
|
||||
};
|
||||
|
||||
// In contrast to OpenGL ES, OpenGL requires explicitly enabling sRGB conversions,
|
||||
// as otherwise the user has to do the sRGB conversion.
|
||||
if !matches!(inner.srgb_kind, SrgbFrameBufferKind::None) {
|
||||
unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) };
|
||||
}
|
||||
|
||||
if self.flags.contains(wgt::InstanceFlags::DEBUG) && gl.supports_debug() {
|
||||
log::debug!("Max label length: {}", unsafe {
|
||||
gl.get_parameter_i32(glow::MAX_LABEL_LENGTH)
|
||||
|
@ -213,12 +213,27 @@ impl super::Queue {
|
||||
instance_count,
|
||||
ref first_instance_location,
|
||||
} => {
|
||||
match base_vertex {
|
||||
0 => {
|
||||
unsafe {
|
||||
gl.uniform_1_u32(first_instance_location.as_ref(), first_instance)
|
||||
};
|
||||
let supports_full_instancing = self
|
||||
.shared
|
||||
.private_caps
|
||||
.contains(PrivateCapabilities::FULLY_FEATURED_INSTANCING);
|
||||
|
||||
if supports_full_instancing {
|
||||
unsafe {
|
||||
gl.draw_elements_instanced_base_vertex_base_instance(
|
||||
topology,
|
||||
index_count as i32,
|
||||
index_type,
|
||||
index_offset as i32,
|
||||
instance_count as i32,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
unsafe { gl.uniform_1_u32(first_instance_location.as_ref(), first_instance) };
|
||||
|
||||
if base_vertex == 0 {
|
||||
unsafe {
|
||||
// Don't use `gl.draw_elements`/`gl.draw_elements_base_vertex` for `instance_count == 1`.
|
||||
// Angle has a bug where it doesn't consider the instance divisor when `DYNAMIC_DRAW` is used in `gl.draw_elements`/`gl.draw_elements_base_vertex`.
|
||||
@ -231,41 +246,17 @@ impl super::Queue {
|
||||
instance_count as i32,
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let supports_full_instancing = self
|
||||
.shared
|
||||
.private_caps
|
||||
.contains(PrivateCapabilities::FULLY_FEATURED_INSTANCING);
|
||||
|
||||
if supports_full_instancing {
|
||||
unsafe {
|
||||
gl.draw_elements_instanced_base_vertex_base_instance(
|
||||
topology,
|
||||
index_count as i32,
|
||||
index_type,
|
||||
index_offset as i32,
|
||||
instance_count as i32,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
unsafe {
|
||||
gl.uniform_1_u32(first_instance_location.as_ref(), first_instance)
|
||||
};
|
||||
|
||||
// If we've gotten here, wgpu-core has already validated that this function exists via the DownlevelFlags::BASE_VERTEX feature.
|
||||
unsafe {
|
||||
gl.draw_elements_instanced_base_vertex(
|
||||
topology,
|
||||
index_count as _,
|
||||
index_type,
|
||||
index_offset as i32,
|
||||
instance_count as i32,
|
||||
base_vertex,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// If we've gotten here, wgpu-core has already validated that this function exists via the DownlevelFlags::BASE_VERTEX feature.
|
||||
unsafe {
|
||||
gl.draw_elements_instanced_base_vertex(
|
||||
topology,
|
||||
index_count as _,
|
||||
index_type,
|
||||
index_offset as i32,
|
||||
instance_count as i32,
|
||||
base_vertex,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -507,6 +507,8 @@ impl crate::Instance for Instance {
|
||||
.supported_extensions()
|
||||
.contains("GL_ARB_framebuffer_sRGB");
|
||||
|
||||
// In contrast to OpenGL ES, OpenGL requires explicitly enabling sRGB conversions,
|
||||
// as otherwise the user has to do the sRGB conversion.
|
||||
if srgb_capable {
|
||||
unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user