From 58e71ccfb72d6eadf847e543960ed58373dd8c6e Mon Sep 17 00:00:00 2001 From: Osei Fortune Date: Fri, 13 Nov 2026 15:53:14 -0400 Subject: [PATCH] perf(webgpu): stop reserving GPU memory in 128-256 MiB blocks Devices were requested with wgpu's default memory hints, which make the Vulkan allocator reserve device memory in 128 then 256 MiB blocks and host-visible memory in 64 then 128 MiB blocks. Reserved blocks count as graphics memory in full, so a fresh device held 192 MiB with nothing in it, and a 4K texture with mips (85 MiB) cost about 128 MiB because only two fit a block. MemoryHints::MemoryUsage starts blocks at 8 MiB and gives larger resources an exact-size allocation, as Dawn does. Measured on Linux (Intel, Mesa) through the native API and a three.js WebGPURenderer scene, DRM memory before -> after: empty device 215 -> 34 MiB; scene at +384 models 287 -> 183 MiB; 16 retained 4K textures 2331 -> 1716 MiB. Frame times unchanged. --- crates/canvas-c/src/webgpu/gpu_adapter.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/canvas-c/src/webgpu/gpu_adapter.rs b/crates/canvas-c/src/webgpu/gpu_adapter.rs index d174d68b..5d2bdcb5 100644 --- a/crates/canvas-c/src/webgpu/gpu_adapter.rs +++ b/crates/canvas-c/src/webgpu/gpu_adapter.rs @@ -176,7 +176,10 @@ pub extern "C" fn canvas_native_webgpu_adapter_request_device( label: label.clone(), required_features: features, required_limits: limits, - memory_hints: Default::default(), + // Exact-size allocations for large resources, as Dawn makes. The default hints + // sub-allocate from 128-256 MiB blocks that count as graphics memory in full: a fresh + // device reserved 192 MiB, and a 4K texture with mips about 128 MiB. + memory_hints: wgt::MemoryHints::MemoryUsage, default_queue: wgt::QueueDescriptor { label: None }, trace: Default::default(), experimental_features: Default::default(),