Skip to content

GPU limits: a refused configure panics in LayerHost and on the web, an image past the device's largest texture is a validation error, and the Metal backend panics on macOS 11 and 12; fixes are on a fork #588

Closed

Description

@Entrpi

Three ways a GPU's limits end the app instead of costing a frame or an image. ba5e7c8 already fixed the window side of the first one; these are the paths it leaves.

1. A surface configuration that is refused panics (LayerHost, web)

Windows and overlays configure through window::configure, which returns wgpu's error instead of panicking. LayerHost (platform/embed.rs, 3 sites) and the web host (platform/web.rs, 3 sites) still call Surface::configure directly, so a refusal reaches wgpu's default handler and panics. Some related gaps:

  • On wasm, window::configure returns Ok without checking anything.
  • On every platform it scopes validation and internal errors, but not out-of-memory ones.
  • A LayerHost whose drawable stays lost reports animating for as long as each reconfigure takes.
  • Window and overlay drawables have a floor of 1 but no ceiling. A resize that reports a wrapped client height (1156×65527, as in Windows: Surface::configure panics when a resize reports a wrapped negative height #306) asks for a configuration the device can't take.

2. An image larger than the device's largest texture is a validation error

ImageAtlas::place_at places frames up to a fixed 8192 px a side. Renderer::upload_images makes each page's texture at the page's size, without looking at max_texture_dimension_2d. WebGL2, downlevel and older mobile adapters report 2048 or 4096. So one large photo is:

  • a panic in a headless or embedded host;
  • an uncaptured error and a missing image in a window.

There are two more paths:

  • prepare_layers makes a window-sized blurred layer 2112 px on a 2048 window.
  • upload_outlines grows the glyph outline texture to 4096 rows, whatever the device takes.

3. The Metal backend panics on macOS 11 and 12

gpu/backend.rs picks the native backend on any macOS when metal-backend is on, which it is by default. That backend writes MSL 3.0, which needs macOS 13. Its precompiled libraries are built with -mmacosx-version-min=13.0. On macOS 11 or 12, the libraries don't load, the runtime compile fails, and pipeline::create panics. An app with default features opens no window.

Fix

Three commits on dev 14e3c5d, one per problem, on branch safety-gpu-failures of Entrpi/rune.

d73e5a04: a refused configuration costs frames, never the app.

  • LayerHost and the web host configure through window::configure. That function now also catches out-of-memory errors.
  • One state machine. What each host knows of its surface is one state machine on rune::machine (window/configured.rs). A refused configure, and a drawable still lost after reconfiguring, count toward one run of failures, which only a drawn frame ends.
  • Retries. The surface tries again after 50 ms, doubling, and after five failures in a row only a resize tries. The run is reported when it begins and when it gives up. A suspended or zero-sized host holds its retry.
  • LayerHost stops reporting animating once it gives up.
  • Web. On WebGPU, configure_then reads the JS device's own error scopes (platform/web/health.rs), because wgpu 30.0.1's Error::from_js panics on a GPUInternalError. The answer carries its configure's attempt, so a late answer to an earlier configure changes nothing. When its retries run out, the canvas says so on the console and waits for a resize; the app keeps running.
  • Ceiling. drawable_size holds window and overlay drawables to 1..=max_texture_dimension_2d. For Windows: Surface::configure panics when a resize reports a wrapped negative height #306, this means the window gets a drawable at the device's limit instead of a refused configuration. It does not detect the wrapped height itself, so the drawable is still far taller than the window.
  • Tests.
    • A source test fails on any surface configure call outside the helper. On dev it lists 8.
    • Unit tests step the state machine.
    • LayerHost tests refuse configures through a test-only hook.
    • On a real CAMetalLayer, 65527 is held to the limit and a refused configuration comes back as an error.

4c8082da: nothing Rune draws asks for a texture larger than the GPU makes.

  • The atlas places images no larger than the device's largest texture, and learns that limit before it places anything. A renderer records its device's limit when it is made, as the smallest of any renderer in the process. Rune's hosts also tell the atlas before the first frame.
  • An oversized image draws at its largest decoded mip that fits. If none fits, it is halved in linear light with image/mips.rs's filter.
  • A layer past the limit keeps what the viewport shows, then as much of its blur's support around that as fits.
  • The outline store is held to the device's rows.
  • The headless renderer refuses a canvas larger than the device allows, with a readable error.
  • Tests run on a wgpu device requested with a 2048 limit, under a validation scope. A 4096×4096 image draws on its first frame with its colours in place. A blurred window-sized layer draws its edges. On dev, both tests fail with validation errors.

a6eed401: the Metal backend is the macOS default only from macOS 13.

  • resolve takes the OS major version. Below the backend's floor (macOS 13, iOS 16) it returns wgpu, whatever the environment, the app or the default asked.
  • When RUNE_GPU_BACKEND=metal or App::gpu_backend(Metal) asked for the native backend there, Rune says once on stderr that it draws with wgpu. describe_gpu gives the reason.
  • The README states each backend's minimum macOS.

Each commit has a changelog fragment.

Not fixed here

  • gpu/metal/pipeline.rs still panics on a supported OS when the precompiled library fails and the runtime compile fails. wgpu's custom backend gives create_render_pipeline no error to return.
  • The timestamp resolve behind Video: resizing during NativeSurface playback can panic in Surface::configure #345 still races a configure on another thread. Its refusal is now caught.
  • Nothing here drives a browser. configure_then and the web host are checked by compiling for wasm32 and by the state machine's unit tests.

On macOS (Apple silicon), the documented test command, cargo test -p rune -p rune-kit --features rune-kit/markdown --no-fail-fast, passes with this branch and the other three safety branches merged on dev 14e3c5d: 2,786 passed, 0 failed. Dev alone gives 2,749 passed, 0 failed. The four branches are safety-secure-fields, safety-hostile-content, safety-gpu-failures and safety-release-dev-surface; they merge cleanly except for one import line in image.rs. cargo check --workspace --all-targets and scripts/file-size.sh pass. cargo check -p rune --target wasm32-unknown-unknown passes.

Filed together with #586, #587 and #589, the other safety fixes from the same review.

Activity

  1. Hona commented on Nov 23, 2026

    @Hona
    Member

    All three are fixed on dev. Window resizes already kept the drawable within the device's limit from #1449. #1586 (137eb56) routes every web and LayerHost surface configure through guarded error scopes (out-of-memory included) with a backoff, and stops a LayerHost from reporting animating while its drawable stays lost. #1611 (9d4b463) draws an oversized image from its largest mip that fits and holds the outline texture to the device's limit. #1590 (501d1d9) uses wgpu instead of the native Metal backend below macOS 13 and iOS 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions