gfx-rs/wgpu

Panic: called glDebugMessageCallback but it was not loaded

davidar opened this issue · 10 comments

Description
The examples are failing to run in recent master (on Windows). I bisected it down to 476b6a1

Repro steps
cargo run --example cube

Expected vs observed behavior
Should run normally, instead it panics with thread 'main' panicked at 'called glDebugMessageCallback but it was not loaded.'

It runs if I set explicitly set WGPU_BACKEND to vulkan or dx12, but looks like it's now defaulting to gl for some reason

Extra materials

stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:498
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\panicking.rs:116
   2: glow::gl46::go_panic_because_fn_not_loaded
             at C:\Users\d\.cargo\registry\src\github.com-1ecc6299db9ec823\glow-0.11.1\src\gl46.rs:4232
   3: glow::gl46::call_atomic_ptr_2arg
             at C:\Users\d\.cargo\registry\src\github.com-1ecc6299db9ec823\glow-0.11.1\src\gl46.rs:4314
   4: glow::gl46::struct_commands::GlFns::DebugMessageCallback
             at C:\Users\d\.cargo\registry\src\github.com-1ecc6299db9ec823\glow-0.11.1\src\gl46.rs:10199
   5: glow::native::impl$2::debug_message_callback<void (*)(u32,u32,u32,u32,str)>
             at C:\Users\d\.cargo\registry\src\github.com-1ecc6299db9ec823\glow-0.11.1\src\native.rs:2299
   6: wgpu_hal::gles::egl::impl$11::enumerate_adapters
             at .\wgpu-hal\src\gles\egl.rs:840
   7: wgpu_core::instance::impl$6::request_adapter::gather<wgpu_hal::gles::Api,core::marker::PhantomData<wgpu_core::id::Id<wgpu_core::instance::Adapter<wgpu_hal::empty::Api> > > >
             at .\wgpu-core\src\instance.rs:663
   8: wgpu_core::hub::Global<wgpu_core::hub::IdentityManagerFactory>::request_adapter<wgpu_core::hub::IdentityManagerFactory>
             at .\wgpu-core\src\instance.rs:729
   9: wgpu::backend::direct::impl$3::instance_request_adapter
             at .\wgpu\src\backend\direct.rs:812
  10: wgpu::Instance::request_adapter
             at .\wgpu\src\lib.rs:1471
  11: wgpu::util::init::initialize_adapter_from_env_or_default::generator$0
             at .\wgpu\src\util\init.rs:79
  12: core::future::from_generator::impl$1::poll<wgpu::util::init::initialize_adapter_from_env_or_default::generator$0>
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\future\mod.rs:84
  13: cube::framework::setup::generator$0<cube::Example>
             at .\wgpu\examples\framework.rs:134
  14: core::future::from_generator::impl$1::poll<cube::framework::setup::generator$0>
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\future\mod.rs:84
  15: pollster::block_on<core::future::from_generator::GenFuture<cube::framework::setup::generator$0> >
             at C:\Users\d\.cargo\registry\src\github.com-1ecc6299db9ec823\pollster-0.2.4\src\lib.rs:132
  16: cube::framework::run<cube::Example>
             at .\wgpu\examples\framework.rs:385
  17: cube::main
             at .\wgpu\examples\cube\main.rs:400
  18: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\ops\function.rs:227

Platform
Windows 11, NVIDIA

I got the same issue in Windows, can't seem to get around it without
set WGPU_BACKEND=vulkan
in the terminal

This feels like either a glow or gl46 issue. @grovesNL thoughts?

We should probably guard this call by GL version since it's not always available, see the table version in https://registry.khronos.org/OpenGL-Refpages/es3/html/glDebugMessageCallback.xhtml for example

We could also add a helper function to glow like fn supports_debug_message_callback(&self) -> bool and use that to guard this call on either side.

Fresh clone on Windows 10 & NVIDIA RTX 3080 driver 527.56, can confirm this issue is still happening. (EDTI: Hello sample fails no matter what.)

I got the same issue in Windows, can't seem to get around it without set WGPU_BACKEND=vulkan in the terminal

If setting the environment variable $env:WGPU_BACKEND="vulkan" doesn't work, how can I run wgpu on a pc that defaults to gl?

The issue is we call the function on context creation, which happens unconditionally even when running on vulkan.

Okay so I think this is a naming problem - glDebugMessageCallback is supported on gles 3.2, but GL_KHR_debug, which is what we are gating our call with, defines glDebugMessageCallbackKHR. So an implementation that wants to be picky, could not support glDebugMessageCallback but support glDebugMessageCallbackKHR.

https://github.com/gfx-rs/wgpu/blob/master/wgpu-hal/src/gles/egl.rs#L885-L889 is where we call it, and supports_debug just checks for GL_KHR_debug.

@askeladd123 and those running into this issue following the example code from here: https://sotrh.github.io/learn-wgpu/beginner/tutorial2-surface/#render, I found you can change the backend on the wgpu instance you create in code by changing it from all() to the following:

        // The instance is a handle to our GPU
        // Backends::all => Vulkan + Metal + DX12 + Browser WebGPU
        let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
            backends: wgpu::Backends::from_bits_truncate(1 << wgpu::Backend::Vulkan as u32),
            dx12_shader_compiler: Default::default(),
        });

I was finding that setting the environment variable didn't work for me either.

Fixed in the glow 0.12.1 release