Add programmatic GPU frame capture via TestUtils.captureNextFrame.#1675
Merged
bkaradzic-microsoft merged 1 commit intoBabylonJS:masterfrom Apr 23, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 intoDeviceImpl. - Implements one-shot capture behavior via an atomic flag consumed in
DeviceImpl::Frame()to set a bgfx frame capture flag. - Adds
TestUtils.captureNextFrame()and wiresvalidation_native.jsto 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a one-shot, cross-backend API for requesting a GPU debugger capture of the next submitted frame. Wraps bgfx's
BGFX_FRAME_DEBUG_CAPTUREflag, 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:
std::atomic<bool> m_captureNextFrame.Frame()consumes it via exchange(false) and ORsBGFX_FRAME_DEBUG_CAPTUREinto thebgfx::frame()flags, guaranteeing the request is applied to exactly one frame even under concurrent JS-thread calls.RequestCaptureNextFrame()as a thin forwarder, extending the existing public surface alongside RequestScreenShot.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.