Skip to content

Build headless WGPU renderers on a shared context - #17

Merged
coreyleeunity merged 2 commits into
unity/hub-consolidatedfrom
unity/HUB-8144-shared-headless-context
Oct 29, 2026
Merged

coreyleeunity merged 2 commits into
unity/hub-consolidatedfrom
unity/HUB-8144-shared-headless-context

Conversation

@francois-unity

Copy link
Copy Markdown
Collaborator

Headless renderers can now share one GPU device. WgpuHeadlessRenderer::with_context(&WgpuContext) builds a renderer on an existing context’s device and queue instead of creating a new device.

  • Why: the native Unity Hub’s headless visual suite (HUB-8144) opens about 50 windows per run and builds a WgpuHeadlessRenderer for each one. new() creates a new instance, adapter and device on every call, and on lavapipe that setup is about four fifths of each scene’s time.
  • What: with_context takes the context by reference; each renderer still gets its own sprite atlas and render target, as every window does today. new_with_requirements now delegates to it, so new() behaves as before.
  • The constructor takes a WgpuContext rather than a WgpuContextHandle: the handle has no wgpu::Adapter, and building the render target needs one.

Testing

A new test in tests/headless_primitives.rs, renderers_on_one_context_share_its_device_and_render_alike, builds two renderers on one context and one on its own device. It checks that the two report the same device (and that it is the context’s device and queue), that the third reports a different one, and that all three render the same path scene to identical frames.

Locally on an Apple Silicon Mac: cargo test -p gpui_ce_wgpu --features test-support --test headless_primitives passes (6 tests), and clippy is clean on gpui_ce_wgpu (all targets, test-support).

This branch is unity/hub-consolidated (the Hub’s current pin, 94d0427e2d) plus this one commit.

WgpuHeadlessRenderer::with_context(&WgpuContext) renders on an existing
context's device and queue, so a test suite that opens many headless
windows creates one device instead of one per window. Each renderer keeps
its own sprite atlas and render target. new_with_requirements now
delegates to it.
@francois-unity francois-unity self-assigned this Oct 19, 2026
@francois-unity
francois-unity marked this pull request as ready for review October 29, 2026 18:32

@coreyleeunity coreyleeunity left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

c-l33-p0 c-l33-p0:

Shared-device headless renderers work. Small, clean change.

Check Result
New shared-context test ✅ passes
Existing headless primitives tests ✅ all pass
Clippy, gpui_ce_wgpu ✅ clean
Manual render on shared vs own device ✅ identical frames, no cross-renderer bleed
Full crate test run ❌ one border test fails, same on base branch

Not covered: Linux and Windows.

Approving. The one failing border test predates this PR and should get its own ticket.

@coreyleeunity
coreyleeunity merged commit c25e0ae into unity/hub-consolidated Oct 29, 2026
15 checks passed
@coreyleeunity
coreyleeunity deleted the unity/HUB-8144-shared-headless-context branch October 29, 2026 18:56
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.

2 participants