Skip to content

Experiment: Port VMA/D3D12MA to Rust in place of existing allocator stack - #9794

Draft
cwfitzgerald wants to merge 5 commits into
gfx-rs:trunkfrom
cwfitzgerald:push-wottzwqnttxy
Draft

Experiment: Port VMA/D3D12MA to Rust in place of existing allocator stack#9794
cwfitzgerald wants to merge 5 commits into
gfx-rs:trunkfrom
cwfitzgerald:push-wottzwqnttxy

Conversation

@cwfitzgerald

Copy link
Copy Markdown
Member

Connections

#9745

Description

We've had lots of trouble with gpu-allocator causing weird allocation behavior. It also didn't have very complicated allocation logic so didn't get the advantages of state of the art things. This adds an LLM-powered port of VMA/D3D12MA to replace that and create consistent behavior.

Testing

In place testing, prop testing, adverserial llm reviews and diff-to-vma reviews.

Squash or Rebase?

Don't merge this.

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

@JMS55

JMS55 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Would it be better to just do FFI with the crates? That way we can update easier as new versions are published.

@cwfitzgerald

Copy link
Copy Markdown
Member Author

@JMS55 the main problem would be re-introducing a c dependency, all the auditing that would require, etc.

@cwfitzgerald

cwfitzgerald commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Just so the passing reader is clear, I'm aware that this PR is moderately insane. Amusingly it does pass all of our tests though

@cwfitzgerald
cwfitzgerald force-pushed the push-wottzwqnttxy branch 4 times, most recently from 8eccc56 to e651490 Compare July 9, 2026 20:32
@inner-daemons

Copy link
Copy Markdown
Collaborator

This is diabolical and I love it lol.

I cannot imagine how a vibe-coded rust port of a well established C library would be easier to audit or preferable to have in our dependency tree but thats not my domain lol

@cwfitzgerald

cwfitzgerald commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

I cannot imagine how a vibe-coded rust port of a well established C library would be easier to audit or preferable to have in our dependency tree but thats not my domain lol

Well that's why I'm not merging it right now, it needs review and iteration so it's not vibed just AI assisted :) In general C/C++ is a ton harder to audit as there's UB lurking at every corner. Here unsafe is the only place that UB can really manifest outside of the allocator itself misbehaving (which is why we have tests). By the time this lands at least two people will have reviewed every bit of this change (me and the reviewer).

Port the Vulkan backend off gpu-allocator onto the new in-repo
wgpu-block-pool / wgpu-offset-allocator crates via a new
vulkan/suballocation.rs (VMA-style memory-type selection, per-heap block
sizing, dedicated-allocation heuristics, budget gating, persistent
mapping). Vulkan no longer references lib.rs's shared AllocationSizes; it
uses a local BlockSizePolicy instead. Also hardens acceleration-structure
buffer alignment and fixes device-memory leaks on error paths.

The dx12 backend still uses gpu-allocator, so the shared gpu_allocator
glue in lib.rs (gated on any(dx12, vulkan)) is kept; the gpu-allocator
crate remains a wgpu-hal dependency (its vulkan feature is dropped, its
d3d12 feature retained). Removing that glue is a follow-up once dx12 is
ported too.
Delete the shared gpu-allocator glue from wgpu-hal/src/lib.rs, inline a
local AllocationSizes into the dx12 backend, drop gpu-allocator from the
workspace and wgpu-hal manifests, and add the feature changelog entry.
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.

3 participants