Skip to content

feat(gpu): expose startup GpuMemoryPolicy for wgpu suballocation - #1903

Merged
Hona merged 1 commit into
devfrom
feat/80-gpu-memory-policy
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
feat/80-gpu-memory-policy

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #80

Summary

  • Adds a Rune-owned startup GPU suballocation policy enum GpuMemoryPolicy (MemoryUsage default, Performance, Manual { block_size: Range<u64> }) in crates/rune-gpu/src/memory.rs and re-exports it from rune.
  • Adds process-wide startup configuration via rune::set_gpu_memory_policy(policy) and App::gpu_memory_policy(self, policy) (crates/rune/src/render/device.rs, crates/rune/src/app.rs), keeping wgpu types out of rune's public API.
  • Wires Gpu::device_on (crates/rune/src/render/device.rs) to pass rune_gpu::memory::wgpu_hints() to wgpu::DeviceDescriptor::memory_hints, reaching every window, overlay, headless, prewarmed, and warmed device.
  • Changing the effective policy restarts an in-flight macOS prewarm_gpu thread or discards a parked/warming Windows/Linux warm_gpu device so a cached device built under the old policy is never silently reused.
  • Normalizes degenerate Manual ranges (start.max(1)..end.max(start.max(1))) while preserving fixed-size ranges (4 MiB..4 MiB).
  • Adds LAUNCH_FLOOR_MEMORY_POLICY to examples/launch-floor/src/main.rs (memory-usage, performance, manual:<mib>, manual:<min>-<max>), updates crates/rune/README.md and examples/README.md, and adds changelog/unreleased/2026-11-24-gpu-memory-policy.md.

Design basis

  • Behaviour: wgpu::MemoryHints (MemoryUsage, Performance, Manual { suballocated_device_memory_block_size }), preserving Rune's existing MemoryUsage default. Honored by wgpu's D3D12 (Windows) and Vulkan (Linux) suballocators; ignored by Rune's native Metal backend, wgpu's Metal backend, and browser backends (WebGPU/WebGL2). Resources larger than a Manual block range still succeed via dedicated allocations.
  • API shape: mirrors Rune's GpuBackend / App::gpu_backend process-wide startup pattern (crates/rune-gpu/src/backend.rs, crates/rune/src/app.rs, crates/rune/src/render/device.rs).

Usage

use rune::{App, AppSpec, GpuMemoryPolicy, el};

App::new(AppSpec::new("Low memory", (640.0, 480.0), || (), |_, _| el()))
    .gpu_memory_policy(GpuMemoryPolicy::Manual {
        block_size: (4 * 1024 * 1024)..(8 * 1024 * 1024),
    })
    .run();

For apps calling prewarm_gpu(), warm_gpu(), or warm_gpu_cache() before building App, call rune::set_gpu_memory_policy(...) first.

flowchart LR
  A[App::gpu_memory_policy / set_gpu_memory_policy] --> B[rune_gpu::memory::choose]
  B -->|changed| C[prewarm::restart macOS / prewarm::discard Win+Linux]
  B --> D[Gpu::device_on -> wgpu_hints]
  D --> E[wgpu::DeviceDescriptor::memory_hints]
Loading

Verification

  • Windows (D3D12): rune-gpu (50 passed + 1 doctest), rune::render::device (25 passed, including isolated child-process D3D12 allocator-report checks verifying 8 MiB default MemoryUsage, 4 MiB Manual { 4..8 MiB } via both set_gpu_memory_policy and App::gpu_memory_policy plus a 10 MiB dedicated allocation, 128 MiB Performance, and parked-GPU discard on policy change), render::prewarm_tests (1 passed), render::warm_tests (6 passed), launch-floor (1 passed), rune doctests (2 passed), cargo check -p rune -p rune-kit.
  • macOS (arm64): cargo test -p rune-gpu -p rune --lib -- memory render::device render::prewarm_tests (31 + 6 passed).
  • Linux (aarch64): cargo check -p rune-gpu -p rune -p rune-kit --tests (compiled).
  • Web (wasm32): cargo check-wasm and cargo check-webgl (compiled).
  • Repo checks: scripts/file-size.sh passed.
  • Not verified: live Vulkan driver allocator reports (Linux container has no GPU), iOS compile, or interactive desktop window launch.

@Hona
Hona merged commit eb588e3 into dev Nov 24, 2026
1 check passed
@Hona
Hona deleted the feat/80-gpu-memory-policy branch November 24, 2026 12:32
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.

Expose GPU memory policy and allocation block sizing

1 participant