Skip to content

Return Metal renderer creation failures instead of panicking - #16

Merged
chris-addison merged 2 commits into
unity/hub-consolidatedfrom
unity/HUB-0000-fallible-metal-renderer
Oct 18, 2026
Merged

chris-addison merged 2 commits into
unity/hub-consolidatedfrom
unity/HUB-0000-fallible-metal-renderer

Conversation

@chris-addison

@chris-addison chris-addison commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Claudistopher Claudistopher:

A Metal driver that refuses to build the renderer now returns an error from open_window instead of panicking. Found in the native Unity Hub: Sentry issue UNITY-HUB-37DK shows Hub 4.0.0-beta.2 dying at startup on an Intel MacBookAir5,1 (macOS 26.7.2) with "Compiler encountered an internal error".

  • Before: MetalRenderer::new was infallible. A refused MSL compile panicked with "error building metal library", a missing entry point with "error locating …", a refused pipeline with "could not create render pipeline state", and a missing Metal device called std::process::exit(1). new_renderer already returned a Result, but it could only ever be Ok.
  • Now: MetalRenderer::new, new_headless and MetalHeadlessRenderer::new return Result<_, MetalRendererError>. The error carries the device name, the step that failed (for example "compiling the quads shader library") and Metal's own message. new_renderer passes it up through open_window, so an application can report it and exit. gpui_platform re-exports the type on macOS, so callers can downcast_ref it without depending on gpui_apple.
  • current_headless_renderer keeps panicking when Metal fails, the same way the WGPU headless renderer does on the other platforms. It is test and bench support only.

No fallback renderer: the macOS wgpu renderer is a compile-time feature, not a runtime choice, and it runs Naga's MSL through the same driver compiler, so it would most likely fail the same way.

Testing

Two new tests in metal_renderer::tests run on a real Metal device, like the existing ones (the test-mac CI job runs them):

  • a_shader_library_the_device_refuses_is_an_error hands the device an invalid source for the quads shader and checks that construction returns an error naming the device, the step and the compiler's text.
  • a_missing_shader_entry_point_is_an_error checks the entry-point lookup the same way.

Locally on an Apple Silicon Mac: cargo test -p gpui_ce_apple --lib passes (15 tests), and clippy with -D warnings is clean on gpui_ce_apple, gpui_ce_platform and gpui_ce_macos (all targets).

A second commit fixes CI that was already broken on unity/hub-consolidated: renderer_source_audit::windows_default_renderer_has_no_wgpu_path failed on every platform, because it required gpui_windows/Cargo.toml to never mention gpui_wgpu, while the branch carries an optional, non-default wgpu feature for the per-window WGPU renderer. The audit now allows gpui_wgpu only as an optional dependency that the wgpu feature enables, fails when default or any other feature turns it on, and checks that a build without the feature creates the DirectX renderer. Adding wgpu to default, or dropping optional = true, makes it fail again (checked locally). default is ["gpui/default"] today.

This branch is unity/hub-consolidated (the Hub's current pin, 02e408c456) plus these two commits.

🤖 Generated with Claude Code

Building the Metal renderer compiles the generated MSL with the driver's
runtime compiler and creates one pipeline state per primitive. Some drivers
refuse a step ("Compiler encountered an internal error" on an Intel MacBook
Air), and the renderer panicked with "error building metal library", "error
locating <entry>" or "could not create render pipeline state". A missing
Metal device called std::process::exit(1).

MetalRenderer::new, new_headless and MetalHeadlessRenderer::new now return
Result<_, MetalRendererError>. The error carries the device name, the step
that failed and Metal's own message, and new_renderer passes it to
open_window's Result, so an application can report it and exit. gpui_platform
re-exports the type on macOS for downcast_ref. The headless renderer factory
used by tests keeps panicking, as the WGPU one does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chris-addison
chris-addison marked this pull request as ready for review October 18, 2026 15:41
windows_default_renderer_has_no_wgpu_path failed on unity/hub-consolidated itself: it required crates/gpui_windows/Cargo.toml to never mention gpui_wgpu, and window.rs to hold no wgpu path, but the branch carries an optional, non-default `wgpu` feature (the per-window WGPU renderer). The audit now allows gpui_wgpu only as an optional dependency that the `wgpu` feature enables, fails when `default` or any other feature turns it on, and checks that a build without the feature creates the DirectX renderer. Mutation-checked: adding `wgpu` to `default`, or dropping `optional = true`, fails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chris-addison
chris-addison merged commit 94d0427 into unity/hub-consolidated Oct 18, 2026
15 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.

1 participant