Skip to content

Build headless WGPU renderers on a shared context - #17

Draft
francois-unity wants to merge 2 commits into
unity/hub-consolidatedfrom
unity/HUB-8144-shared-headless-context
Draft

francois-unity wants to merge 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
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.

1 participant