Skip to content

Graphics: opt-in RenderDoc capture via BABYLON_NATIVE_RENDERDOC - #1832

Merged
bkaradzic-microsoft merged 2 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:pr/graphics-renderdoc
Aug 12, 2026
Merged

Graphics: opt-in RenderDoc capture via BABYLON_NATIVE_RENDERDOC#1832
bkaradzic-microsoft merged 2 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:pr/graphics-renderdoc

Conversation

@bkaradzic-microsoft

@bkaradzic-microsoft bkaradzic-microsoft commented Aug 12, 2026

Copy link
Copy Markdown
Member

Problem

bgfx only loads RenderDoc — and therefore only arms the BGFX_FRAME_DEBUG_CAPTURE trigger that Playground's existing --capture flag relies on — when init.debug is set. Release builds leave that false, so you can't take a GPU capture from a normal build without recompiling.

Change

Gate init.debug behind an environment variable that's only set when a capture is actually wanted:

set BABYLON_NATIVE_RENDERDOC=1
Playground.exe --capture=30 app:///Scripts/validation_native.js

Any value other than absent, empty or exactly "0" enables it (compared in full, so 01 and 0x1 enable too). When unset, the code path is identical to today.

_dupenv_s on MSVC / std::getenv elsewhere, so no CRT deprecation warning on Win32.

Verification

result
variable unset run unchanged, test passes
BABYLON_NATIVE_RENDERDOC=1 debug device created successfully, test still passes

Worth noting explicitly: enabling init.debug turns on the D3D11 debug layer, which can fail device creation on machines without the SDK layers installed. That's why this is opt-in per-run rather than, say, defaulted on in Debug builds — an unset variable can never affect anyone.

Why

Chasing rendering-parity bugs against Babylon.js repeatedly needed a frame capture, and every time it meant a custom rebuild. This makes --capture usable as shipped.

bgfx only loads RenderDoc -- and therefore only enables the
BGFX_FRAME_DEBUG_CAPTURE trigger behind Playground's --capture -- when
init.debug is set. Release builds leave that false, so a GPU capture cannot
be taken from a normal build without recompiling.

Gate it behind an environment variable that is only set when a capture is
actually wanted, so the default path is untouched. Any value other than
empty or "0" enables it.

Verified on Win32: with the variable unset the run is unchanged, and with
BABYLON_NATIVE_RENDERDOC=1 the debug device is created successfully and the
test still passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
@bkaradzic-microsoft
bkaradzic-microsoft requested review from bghgary and ryantrem and a lite review from Copilot August 12, 2026 18:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds an opt-in mechanism to enable bgfx’s debug device initialization (to allow RenderDoc captures via the existing --capture flow) by reading an environment variable, keeping default behavior unchanged when the variable is unset.

Changes:

  • Include <cstdlib> for environment variable access.
  • Set init.debug = true only when BABYLON_NATIVE_RENDERDOC is set (Windows via _dupenv_s, non-Windows via std::getenv).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Core/Graphics/Source/DeviceImpl.cpp Outdated
Comment thread Core/Graphics/Source/DeviceImpl.cpp Outdated
…acter

The check rejected any value whose first character was '0', so "01", "0x1" and
"00" disabled the capture even though only an absent, empty or exactly "0"
value is meant to. Extracted the test into IsEnvironmentFlagSet, which compares
the whole string and is now shared by the Win32 and POSIX branches.

The predicate is still only ever used to set init.debug to true, never to clear
it: bgfx defaults init.debug to BGFX_CONFIG_DEBUG, so assigning the predicate
directly would turn the debug device off in Debug builds that get it for free.
@bkaradzic-microsoft
bkaradzic-microsoft enabled auto-merge (squash) August 12, 2026 22:07
@bkaradzic-microsoft
bkaradzic-microsoft merged commit e92b0fd into BabylonJS:master Aug 12, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants