Skip to content

Commit 09f49b6

Browse files
Xavientoismobile-pusher-bot[bot]Wumpf
authored
feat(gles): Add GlDebugFns option to disable OpenGL debug functions (gfx-rs#8931)
Co-authored-by: mobile-pusher-bot[bot] <127349242+mobile-pusher-bot[bot]@users.noreply.github.com> Co-authored-by: Andreas Reich <[email protected]>
1 parent a7ed7f4 commit 09f49b6

4 files changed

Lines changed: 95 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999).
7575
- Initial wgsl-in ray tracing pipelines. By @Vecvec in [#8570](https://github.com/gfx-rs/wgpu/pull/8570).
7676
- Allow parsing shaders which make use of `SPV_KHR_non_semantic_info` for debug info. Also removes `naga::front::spv::SUPPORTED_EXT_SETS`. By @inner-daemons in #8827.
7777

78+
#### GLES
79+
80+
- Added `GlDebugFns` option in `GlBackendOptions` to control OpenGL debug functions (`glPushDebugGroup`, `glPopDebugGroup`, `glObjectLabel`, etc.). Automatically disables them on Mali GPUs to work around a driver crash. By @Xavientois in [#8931](https://github.com/gfx-rs/wgpu/pull/8931).
81+
7882
### Changes
7983

8084
#### Metal

wgpu-hal/src/gles/adapter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,13 @@ impl super::Adapter {
633633
super::PrivateCapabilities::TEXTURE_STORAGE,
634634
supported((3, 0), (4, 2)),
635635
);
636-
private_caps.set(super::PrivateCapabilities::DEBUG_FNS, gl.supports_debug());
636+
let is_mali = renderer.to_lowercase().contains("mali");
637+
let debug_fns_enabled = match backend_options.debug_fns {
638+
wgt::GlDebugFns::Auto => gl.supports_debug() && !is_mali,
639+
wgt::GlDebugFns::ForceEnabled => gl.supports_debug(),
640+
wgt::GlDebugFns::Disabled => false,
641+
};
642+
private_caps.set(super::PrivateCapabilities::DEBUG_FNS, debug_fns_enabled);
637643
private_caps.set(
638644
super::PrivateCapabilities::INVALIDATE_FRAMEBUFFER,
639645
supported((3, 0), (4, 3)),

wgpu-types/src/backend.rs

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ pub struct GlBackendOptions {
252252
pub gles_minor_version: Gles3MinorVersion,
253253
/// Behavior of OpenGL fences. Affects how `on_completed_work_done` and `device.poll` behave.
254254
pub fence_behavior: GlFenceBehavior,
255+
/// Controls whether debug functions (`glPushDebugGroup`, `glPopDebugGroup`,
256+
/// `glObjectLabel`, etc.) are enabled when supported by the driver.
257+
///
258+
/// By default ([`GlDebugFns::Auto`]), debug functions are automatically
259+
/// disabled on devices with known bugs (e.g., Mali GPUs can crash in
260+
/// `glPushDebugGroup`). Use [`GlDebugFns::ForceEnabled`] to override this
261+
/// behavior, or [`GlDebugFns::Disabled`] to disable debug functions entirely.
262+
///
263+
/// See also [`InstanceFlags::DISCARD_HAL_LABELS`], which prevents debug
264+
/// markers and labels from being sent to *any* backend, but without the
265+
/// driver-specific bug workarounds provided here.
266+
///
267+
/// [`InstanceFlags::DISCARD_HAL_LABELS`]: crate::InstanceFlags::DISCARD_HAL_LABELS
268+
pub debug_fns: GlDebugFns,
255269
}
256270

257271
impl GlBackendOptions {
@@ -261,9 +275,11 @@ impl GlBackendOptions {
261275
#[must_use]
262276
pub fn from_env_or_default() -> Self {
263277
let gles_minor_version = Gles3MinorVersion::from_env().unwrap_or_default();
278+
let debug_fns = GlDebugFns::from_env().unwrap_or_default();
264279
Self {
265280
gles_minor_version,
266281
fence_behavior: GlFenceBehavior::Normal,
282+
debug_fns,
267283
}
268284
}
269285

@@ -273,10 +289,73 @@ impl GlBackendOptions {
273289
#[must_use]
274290
pub fn with_env(self) -> Self {
275291
let gles_minor_version = self.gles_minor_version.with_env();
276-
let short_circuit_fences = self.fence_behavior.with_env();
292+
let fence_behavior = self.fence_behavior.with_env();
293+
let debug_fns = self.debug_fns.with_env();
277294
Self {
278295
gles_minor_version,
279-
fence_behavior: short_circuit_fences,
296+
fence_behavior,
297+
debug_fns,
298+
}
299+
}
300+
}
301+
302+
/// Controls whether OpenGL debug functions are enabled.
303+
///
304+
/// Debug functions include `glPushDebugGroup`, `glPopDebugGroup`, `glObjectLabel`, etc.
305+
/// These are useful for debugging but can cause crashes on some buggy drivers.
306+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
307+
pub enum GlDebugFns {
308+
/// Automatically decide whether to enable debug functions.
309+
///
310+
/// Debug functions will be enabled if supported by the driver, unless
311+
/// running on a device known to have buggy debug function implementations
312+
/// (e.g., Mali GPUs which can crash in `glPushDebugGroup`).
313+
///
314+
/// This is the default behavior.
315+
#[default]
316+
Auto,
317+
/// Force enable debug functions if supported by the driver.
318+
///
319+
/// This ignores any device-specific workarounds and enables debug functions
320+
/// on all devices that support them, including those with known bugs.
321+
ForceEnabled,
322+
/// Disable debug functions entirely.
323+
///
324+
/// Debug functions will not be used even if supported by the driver.
325+
Disabled,
326+
}
327+
328+
impl GlDebugFns {
329+
/// Choose debug functions setting from the environment variable `WGPU_GL_DEBUG_FNS`.
330+
///
331+
/// Possible values (case insensitive):
332+
/// - `auto` - automatically decide based on device
333+
/// - `forceenabled`, `force_enabled`, or `enabled` - force enable
334+
/// - `disabled` - disable entirely
335+
///
336+
/// Use with `unwrap_or_default()` to get the default value if the environment variable is not set.
337+
#[must_use]
338+
pub fn from_env() -> Option<Self> {
339+
let value = crate::env::var("WGPU_GL_DEBUG_FNS")
340+
.as_deref()?
341+
.to_lowercase();
342+
match value.as_str() {
343+
"auto" => Some(Self::Auto),
344+
"forceenabled" | "force_enabled" | "enabled" => Some(Self::ForceEnabled),
345+
"disabled" => Some(Self::Disabled),
346+
_ => None,
347+
}
348+
}
349+
350+
/// Takes the given setting, modifies it based on the `WGPU_GL_DEBUG_FNS` environment variable, and returns the result.
351+
///
352+
/// See `from_env` for more information.
353+
#[must_use]
354+
pub fn with_env(self) -> Self {
355+
if let Some(debug_fns) = Self::from_env() {
356+
debug_fns
357+
} else {
358+
self
280359
}
281360
}
282361
}

wgpu/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ pub use wgt::{
138138
DownlevelLimits, Dx12BackendOptions, Dx12Compiler, Dx12SwapchainKind,
139139
Dx12UseFrameLatencyWaitableObject, DxcShaderModel, DynamicOffset, ExperimentalFeatures,
140140
Extent3d, ExternalTextureFormat, ExternalTextureTransferFunction, Face, Features, FeaturesWGPU,
141-
FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, GlFenceBehavior, Gles3MinorVersion,
142-
HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags,
143-
InternalCounters, Limits, LoadOpDontCare, MemoryBudgetThresholds, MemoryHints,
141+
FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, GlDebugFns, GlFenceBehavior,
142+
Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor,
143+
InstanceFlags, InternalCounters, Limits, LoadOpDontCare, MemoryBudgetThresholds, MemoryHints,
144144
MipmapFilterMode, MultisampleState, NoopBackendOptions, Origin2d, Origin3d,
145145
PipelineStatisticsTypes, PollError, PollStatus, PolygonMode, PowerPreference,
146146
PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,

0 commit comments

Comments
 (0)