Skip to content

Add programmatic GPU frame capture via TestUtils.captureNextFrame.#1675

Merged
bkaradzic-microsoft merged 1 commit intoBabylonJS:masterfrom
bkaradzic-microsoft:master
Apr 23, 2026
Merged

Add programmatic GPU frame capture via TestUtils.captureNextFrame.#1675
bkaradzic-microsoft merged 1 commit intoBabylonJS:masterfrom
bkaradzic-microsoft:master

Conversation

@bkaradzic-microsoft
Copy link
Copy Markdown
Contributor

@bkaradzic-microsoft bkaradzic-microsoft commented Apr 23, 2026

Introduces a one-shot, cross-backend API for requesting a GPU debugger capture of the next submitted frame. Wraps bgfx's BGFX_FRAME_DEBUG_CAPTURE flag, so the same call works with Xcode Metal capture on macOS/iOS, PIX or RenderDoc on Windows, and RenderDoc on Linux/Android.

Primary use case: producing a .gputrace for a failing validation test without having to manually time a capture in the IDE. Add "capture": true to a test entry in Apps/Playground/Scripts/config.json and the test harness will request a capture on the screenshot frame; with the platform GPU debugger attached, a capture document opens automatically.

Implementation:

  • DeviceImpl owns an std::atomic<bool> m_captureNextFrame. Frame() consumes it via exchange(false) and ORs BGFX_FRAME_DEBUG_CAPTURE into the bgfx::frame() flags, guaranteeing the request is applied to exactly one frame even under concurrent JS-thread calls.
  • DeviceContext exposes RequestCaptureNextFrame()as a thin forwarder, extending the existing public surface alongside RequestScreenShot.
  • TestUtils plugin adds a cross-platform captureNextFrame() JS method (no per-platform .mm/.cpp variants required).
    validation_native.js honors an optional per-test "capture" flag and arms a capture before the final currentScene.render() of the screenshot frame.

When no GPU debugger is attached the bgfx flag is a no-op, so the API is safe to leave in JS that ships in release builds.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a one-shot API to request a GPU debugger capture of the next submitted frame, exposed from the graphics device up through the TestUtils JS plugin and consumed by the Playground validation harness.

Changes:

  • Introduces DeviceContext::RequestCaptureNextFrame() and forwards it into DeviceImpl.
  • Implements one-shot capture behavior via an atomic flag consumed in DeviceImpl::Frame() to set a bgfx frame capture flag.
  • Adds TestUtils.captureNextFrame() and wires validation_native.js to optionally arm capture on the screenshot frame (test.capture).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Plugins/TestUtils/Source/TestUtils.h Exposes captureNextFrame as a JS instance method.
Plugins/TestUtils/Source/TestUtils.cpp Implements JS method by forwarding to DeviceContext.
Core/Graphics/Source/DeviceImpl.h Adds atomic state and public request method on DeviceImpl.
Core/Graphics/Source/DeviceImpl.cpp Implements capture request + applies bgfx frame capture flag for one frame.
Core/Graphics/Source/DeviceContext.cpp Forwards RequestCaptureNextFrame from context to impl.
Core/Graphics/InternalInclude/Babylon/Graphics/DeviceContext.h Adds RequestCaptureNextFrame() to the DeviceContext contract.
Apps/Playground/Scripts/validation_native.js Arms capture on the final render pass when test.capture is set.

Comment thread Core/Graphics/Source/DeviceImpl.cpp
Copy link
Copy Markdown
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

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

[Reviewed by Copilot on behalf of @bghgary]

LGTM

@bkaradzic-microsoft bkaradzic-microsoft enabled auto-merge (squash) April 23, 2026 23:10
@bkaradzic-microsoft bkaradzic-microsoft merged commit 81a7bfe into BabylonJS:master Apr 23, 2026
57 of 58 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.

3 participants