Repository navigation
Description
Request
Would you consider exposing the GPU memory allocation policy through App / AppSpec, while keeping Rune's current default?
wgpu already provides MemoryHints::{Performance, MemoryUsage, Manual}. Rune currently selects Performance inside Gpu::device_on, so a downstream app must patch Rune to choose another policy.
This is a request for configurability, not for making small allocation blocks the default for every Rune app.
Downstream use case
I'm building Brazap, a Rust WhatsApp desktop client using Rune and whatsapp-rust. Its main window has a chat sidebar, message history, and image/video/voice previews. It is intended to stay open during the day, so a low idle memory footprint matters. The ordinary idle view needs relatively little GPU resource memory compared with a game or a graphics-heavy application.
We currently carry a small local patch to select MemoryHints::Manual with a 4–8 MiB allocation-block range. A supported API would let the app make this tradeoff without modifying Rune's device creation.
Measurements motivating the request
Approximate snapshots from the same idle 1180 × 800 Brazap window, with full-pane blur disabled and the same integrated GPU / DX12 backend selected for all three runs:
| Memory policy | Live GPU allocations | Reserved GPU memory |
|---|---|---|
Performance |
9.6 MiB | 192 MiB |
MemoryUsage |
9.8 MiB | 64 MiB |
Manual, 4–8 MiB blocks |
9.6 MiB | 24 MiB |
These values come from wgpu::Device::generate_allocator_report() (total_allocated_bytes and total_reserved_bytes). They are allocator measurements, not process RAM or total VRAM figures, and should not be added to those totals. These were separate development-build launches, not a controlled latency/throughput benchmark; they demonstrate the allocation tradeoff rather than establish an optimal block size.
Environment: Windows build 26200 / 25H2, AMD Radeon integrated graphics alongside an RX 9070 XT, Rune 1213159f9ec300c7a309c67a89176f61a0b47753, wgpu 30.0.1, Rust 1.99.1, x86_64-pc-windows-gnu, development profile with debug information disabled. Only Windows was measured.
Possible API
For example, an illustrative builder method forwarding wgpu's existing type, or a Rune-owned equivalent:
App::new(spec)
.gpu_memory_hints(wgpu::MemoryHints::Manual {
suballocated_device_memory_block_size:
(4 * 1024 * 1024)..(8 * 1024 * 1024),
})
.try_run()?;The exact API/name is flexible. Useful behavior would be:
- Preserve
Performancewhen the application supplies no preference. - Allow
MemoryUsageand a custom allocation-block range. - Define how the choice applies to prewarmed/shared devices, so an existing device does not silently bypass the requested policy. A startup-only option would be sufficient.
- Document which backends honor or ignore the preference, including the native Metal path. No claim of equal savings across platforms.
- Make clear that the block range is not an image/video size limit: larger resources can still use dedicated allocations. Smaller blocks can trade allocation overhead for lower reservation.
Related: #46 addresses Windows GPU selection, which also affected Brazap's process memory. That was a separate experiment; its effects are excluded from the table above. This request is specifically about exposing the allocation policy.
Activity
godismyjudge95 commentedon Nov 6, 2026
Data from a second app for this request, on Linux with lavapipe.
devnow asks forMemoryHints::MemoryUsage(render.rs#L477). That helps, but a screenshot app that draws a few screen-size images still keeps several 32 MiB blocks after the images are gone. AManualblock range would let us trade that.Setup
Ubuntu 26.04, GNOME 50 Wayland, VM with 7 vCPUs and no GPU (Mesa lavapipe), screen 2880x1696 at scale 2. Rune
7ead7d63;render.rs,render/layers.rsandpixels.rsare the same ondevd03349e2. On lavapipe, device memory is process memory (memfd:allocation fdmappings), so it shows in PSS. On a GPU with its own VRAM this would not be process RAM. We did not measure that case.What we see
One probe run, main window hidden at the end (per-mapping PSS from smaps):
Each capture shows one 3024x1964 RGBA image (23.8 MB). The block sizes double 4, 8, 16, 32 MiB and stop at 32. That matches the host-visible range wgpu-hal 30.0.1 gives
MemoryUsage(4 to 32 MiB,AllocationSizes::from_memory_hints), so lavapipe's memory types are host-visible (inference). gpu-allocator 0.28 frees a general block only when it is empty and is not the last one (vulkan/mod.rslines 672-673). One small live resource keeps a whole block, and lavapipe keeps every page that was touched. We did not trace which resource keeps each block.Effect on the whole process, against the same app on our previous toolkit, same harness, 5 alternating runs per side (median MB PSS):
These numbers are after we removed our own extra copies of the frozen frame. Our smaps probes put the rest of the gap in device memory; the heap is about equal.
One source of short-lived large allocations: a fade on a window-size element makes an
Rgba16Float"isolated group" target (render/layers.rs#L415-L420). For our 2240x1536 bucket that is 27.5 MB per fade (seen with a gdb breakpoint oncreate_texture). When we removed that fade, the full benchmark did not change (after 10 captures 335.1 to 335.7 MB, p = 0.42), so this is churn, not the cause.Ask
The API in this issue, with
Manualallowed. Inference from the allocator code, not measured: withManual { 4..8 MiB }, a 23.8 MB image texture is larger than the block, so it gets its own allocation that is freed with the texture. That is the behaviour a screenshot app wants.Done when: an app can choose
Performance,MemoryUsageorManualwith a block range at startup, the choice reaches every device that draws its windows and overlays (prewarmed ones too), and a test reads it back fromgenerate_allocator_reportor the device descriptor.Posted via Claude
godismyjudge95 commentedon Nov 6, 2026
Related, filed since our comment: #142 (a hidden Wayland overlay keeps its image atlas pages and last frame, which is part of what fills these blocks in our numbers) and #148 (no read access to
Pixels, so apps keep a second copy of each image).Posted via Claude
purian23 commentedon Nov 12, 2026
A data point for making this settable. With
MemoryHints::MemoryUsage, blocks double in size and a block is freed only when it's empty. One small long-lived allocation pinned a closed popup's 16 MiB block for the life of the device.With fixed 4 MiB blocks (
MemoryHints::Manual), our bar went from 33.1 to 28.9 MB of GPU memory, and opening a popup cost +5.9 MB instead of +18. +1 for a settable block range.Hona commentedon Nov 24, 2026
Startup GPU suballocation policy configuration is now on
devin #1903 (eb588e335).API:
rune::GpuMemoryPolicy(MemoryUsagedefault,Performance,Manual { block_size: Range<u64> }),App::gpu_memory_policy, andrune::set_gpu_memory_policy(call beforeprewarm_gpu,warm_gpu, orwarm_gpu_cache). Changing the policy restarts an in-flight macOS prewarm or discards a parked Windows/Linux warm-up device so windows and overlays never silently reuse a device created under the old policy.This follows
wgpu::MemoryHintsfor allocation behaviour (honored by D3D12 and Vulkan; ignored by Rune's native Metal backend, wgpu Metal, and web; resources larger than aManualblock range still succeed via dedicated allocations) and Rune'sGpuBackend/App::gpu_backendstartup pattern. Compared to the proposal in the issue, we used a Rune-owned enum instead of exposingwgpu::MemoryHintsdirectly (to keepwgpuout ofrune's public API) and kept currentdev'sMemoryUsagedefault rather thanPerformance. If any part of that shape doesn't fit your use case, please let us know.Verified: Windows D3D12 offscreen allocator-report tests (
default8 MiB,Manual4..8 MiB with a 10 MiB dedicated allocation,Performance128 MiB, and parked-GPU discard), macOS arm64 unit/prewarm tests, Linux aarch64 compile check, andwasm32(WebGPU + WebGL2) compile checks. Not verified: live Vulkan hardware/lavapipe allocator measurements, iOS compile, or an interactive desktop window. Thanks for the detailed measurements!