Linux OpenGL: when context creation fails, bgfx silently falls back to the Noop renderer

Open
#2,087 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, linux

Research direction

Start in DeviceImpl.cpp, where bgfx::init is called and the renderer type is never checked, and look at the deviceStillLost path you must leave alone. Compare init.type with bgfx::getRendererType() after init, then make the device throw "bgfx could not initialize the OpenGL renderer" when a non-Noop request comes back as Noop. ShaderProvider.cpp and TestUtils.getFrameBufferData show the symptoms but are not the fix. Done means a failed EGL display setup stops the device with that error instead of running on as Noop.

Written by the indexing model from the issue text.

Description

Describe the bug
When bgfx can't create the OpenGL context, bgfx::init still succeeds: it falls back to RendererType::Noop. DeviceImpl doesn't check for this. Babylon Native keeps running and the render loop spins, but nothing is drawn:

  • every effect fails to compile with "Shader compiler assumptions are not met" (ShaderProvider.cpp), because the Noop renderer's caps don't match OpenGL's;
  • TestUtils.getFrameBufferData never calls back.

The real cause (here, eglGetDisplay failing) appears only in a BX_CONFIG_DEBUG trace ("Init error: Failed to get display").

To Reproduce

  1. Build the X11 Playground with GRAPHICS_API=OpenGL on master (ea62d5b).
  2. Run it on an NVIDIA GPU with NVIDIA's EGL. On a hybrid laptop: __NV_PRIME_RENDER_OFFLOAD=1 __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json.
  3. Every scene fails to compile its shaders and nothing is drawn. The underlying failure is fixed by #2086.

Expected behavior
If a real renderer was requested (init.type != Noop) and bgfx::getRendererType() comes back as Noop after bgfx::init, without a device loss in progress, the device should fail loudly, for example by throwing "bgfx could not initialize the OpenGL renderer". It should not run on as Noop. The device-lost path (deviceStillLost in DeviceImpl.cpp) may need to keep its current behavior.

Other

  • Platform: Linux (X11), OpenGL. Seen on NVIDIA GTX 1660 Ti, driver 620.70.06, Fedora 44.
Dominant language
C++
Stars
931
Forks
169
Avg merge
2d 17h
Merged PRs (30d)
66

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BabylonJS/BabylonNative

All issues in BabylonJS/BabylonNative

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.