umem: what it asks of the driver in one struct (driver.rs) #178

Manually merged
github merged 1 commit from github-bot/gh-178 into gh-pr/178/base 2026-12-02 18:26:56 +00:00 AGit
Owner

@⁠tylerstraub on GitHub · 2026-12-02 00:24 UTC · original
tylerstraub:umem-driver-seam → main · +81 −55 · 6 files · 1 commits · merged 2026-12-02 17:35 UTC

What

Why: so that forks for drivers VKtory does not support can carry their differences in their own files, instead of patching umem's call sites and re-doing that after every merge from here. This is not a request to support another driver: nothing but RADV's values is added, and every line can be checked on the reference card.

What umem asks of the driver is read from one struct, Driver (umem/src/driver.rs), chosen once in Memory::new, instead of from constants at each call site:

  • bias: the device address asked for title address 0 (BIAS_REQUEST, Memory::window; Memory::bias_request, which tests/sparse_probe.rs now reads instead of its own copy of the constant).
  • handle() / ext(): the chunks' handle type (EXPORT) and its device extension, used at setup, in make_chunk and on the windows. vkback's in-place linear images take it from Memory::chunk_handle instead of umem::EXPORT.
  • placed(kind): the kind a request is placed in (the kind asked for), in commit_prot, create_pool and pool_view_with.

Also driver-independent: a buried chunk keeps its RawChunk, so reap, reap_all and free_raw_chunk free it through one function. Before, the same code was in three places (rule 33), and reap_all's SAFETY comment named memfd_create, which none of them uses.

Credit: this is the driver-independent half of #168 by @⁠360900, split out so it can be reviewed and merged on its own. It keeps #168's names and signatures (Driver, bias, handle, ext, placed, bias_request, chunk_handle, the RawChunk in Dead), so #168 rebases onto it: merged onto this branch, #168 has 8 conflict hunks (driver.rs 1, lib.rs 6, imgmake.rs 1), each resolved by taking #168's side, and the result is #168's tree exactly. Its change to umem/src and vkback/src goes from 261 changed lines in 5 files to 171 in 3. Left for #168: the sparse bind grain (NVIDIA binds in 64 KiB), which is a new check and not a moved value.

I keep a local NVIDIA fork (RTX 5090, results on #3). With this in, a fork for another driver changes driver.rs and its chunk source, and no other call site.

Related: the docs/TASKS.md item "umem's lib.rs holds six separable responsibilities". This does not split anything, but per-driver facts no longer live in lib.rs. lib.rs grows by 10 lines, to 1,463.

The reference

No counterpart: vkd3d-proton has no title memory at fixed addresses.

Evidence

  • Same calls, same values on RADV: Driver::of() returns BIAS_REQUEST, handle() is EXPORT, ext() is VK_KHR_external_memory_fd and placed is the identity. Every replaced use took exactly that constant before. The only visible difference is the text of one setup error ("no OPAQUE_FD memory for sparse buffers" instead of "no opaque-fd export"). So under rule 30 no validation run was done: the Vulkan calls and their arguments stay the same.
  • An AMD integrated GPU (RADV RAPHAEL_MENDOCINO, Mesa 26.0.8), not the reference card. The harness was pointed at it with a local tweak that is not in this PR. cargo test -p umem --release -- --test-threads=1 gives the same on main and on this branch: 22 unit tests, bench 1, gpu 12, identity_probe 2, sparse_mode 14 (1 ignored), sparse_probe 1, sparse_speed 1. The loud errors are the same set on both, and the device bias is the same (0xffffa00000000000). sparse_wait_probe fails on both: it looks for a discrete GPU itself.
  • clippy -D warnings in greenfield and greenfield/wine (both depend on umem). cargo test -p umem -p frame -p vkback --lib, cargo test -p vkback --test policy, cargo xtask policy.
  • Not shown: the RX 9070 XT, and a game run. Nothing in it changes what is drawn.

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen
  • No fallback or second path for a case that can't happen (rule 33); unexpected input fails loudly (rule 9): no new path, no trait, no second driver
  • Constants come from the console, the hardware or the title's data (rule 9b): RADV's existing values, unchanged
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2): no new switches
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35): no queue use changed
  • Every unsafe block has a // SAFETY: comment (rule 36): the changed blocks in reap and reap_all have it
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION: the translator is not touched (rule 27)
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found

Written with Claude Code; I reviewed it and ran the checks above on my machine.

🤖 Generated with Claude Code

**@⁠tylerstraub** on GitHub · 2026-12-02 00:24 UTC · [original](https://github.com/vktory6/VKtory/pull/178) `tylerstraub:umem-driver-seam` → `main` · +81 −55 · 6 files · 1 commits · merged 2026-12-02 17:35 UTC ## What **Why:** so that forks for drivers VKtory does not support can carry their differences in their own files, instead of patching umem's call sites and re-doing that after every merge from here. This is not a request to support another driver: nothing but RADV's values is added, and every line can be checked on the reference card. What umem asks of the driver is read from one struct, `Driver` (`umem/src/driver.rs`), chosen once in `Memory::new`, instead of from constants at each call site: - `bias`: the device address asked for title address 0 (`BIAS_REQUEST`, `Memory::window`; `Memory::bias_request`, which `tests/sparse_probe.rs` now reads instead of its own copy of the constant). - `handle()` / `ext()`: the chunks' handle type (`EXPORT`) and its device extension, used at setup, in `make_chunk` and on the windows. vkback's in-place linear images take it from `Memory::chunk_handle` instead of `umem::EXPORT`. - `placed(kind)`: the kind a request is placed in (the kind asked for), in `commit_prot`, `create_pool` and `pool_view_with`. Also driver-independent: a buried chunk keeps its `RawChunk`, so `reap`, `reap_all` and `free_raw_chunk` free it through one function. Before, the same code was in three places (rule 33), and `reap_all`'s SAFETY comment named `memfd_create`, which none of them uses. **Credit:** this is the driver-independent half of #168 by @⁠360900, split out so it can be reviewed and merged on its own. It keeps #168's names and signatures (`Driver`, `bias`, `handle`, `ext`, `placed`, `bias_request`, `chunk_handle`, the `RawChunk` in `Dead`), so #168 rebases onto it: merged onto this branch, #168 has 8 conflict hunks (driver.rs 1, lib.rs 6, imgmake.rs 1), each resolved by taking #168's side, and the result is #168's tree exactly. Its change to `umem/src` and `vkback/src` goes from 261 changed lines in 5 files to 171 in 3. Left for #168: the sparse bind grain (NVIDIA binds in 64 KiB), which is a new check and not a moved value. I keep a local NVIDIA fork (RTX 5090, results on #3). With this in, a fork for another driver changes `driver.rs` and its chunk source, and no other call site. Related: the `docs/TASKS.md` item "umem's lib.rs holds six separable responsibilities". This does not split anything, but per-driver facts no longer live in `lib.rs`. `lib.rs` grows by 10 lines, to 1,463. ## The reference No counterpart: vkd3d-proton has no title memory at fixed addresses. ## Evidence - Same calls, same values on RADV: `Driver::of()` returns `BIAS_REQUEST`, `handle()` is `EXPORT`, `ext()` is `VK_KHR_external_memory_fd` and `placed` is the identity. Every replaced use took exactly that constant before. The only visible difference is the text of one setup error ("no OPAQUE_FD memory for sparse buffers" instead of "no opaque-fd export"). So under rule 30 no validation run was done: the Vulkan calls and their arguments stay the same. - An AMD integrated GPU (RADV RAPHAEL_MENDOCINO, Mesa 26.0.8), **not the reference card**. The harness was pointed at it with a local tweak that is not in this PR. `cargo test -p umem --release -- --test-threads=1` gives the same on `main` and on this branch: 22 unit tests, bench 1, gpu 12, identity_probe 2, sparse_mode 14 (1 ignored), sparse_probe 1, sparse_speed 1. The loud errors are the same set on both, and the device bias is the same (0xffffa00000000000). `sparse_wait_probe` fails on both: it looks for a discrete GPU itself. - clippy `-D warnings` in `greenfield` and `greenfield/wine` (both depend on umem). `cargo test -p umem -p frame -p vkback --lib`, `cargo test -p vkback --test policy`, `cargo xtask policy`. - Not shown: the RX 9070 XT, and a game run. Nothing in it changes what is drawn. ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen - [x] No fallback or second path for a case that can't happen (rule 33); unexpected input fails loudly (rule 9): no new path, no trait, no second driver - [x] Constants come from the console, the hardware or the title's data (rule 9b): RADV's existing values, unchanged - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2): no new switches - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35): no queue use changed - [x] Every `unsafe` block has a `// SAFETY:` comment (rule 36): the changed blocks in `reap` and `reap_all` have it - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION`: the translator is not touched (rule 27) - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found Written with Claude Code; I reviewed it and ran the checks above on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The device address asked for title address 0, the chunks' external memory
handle type and its device extension, and the kind a request is placed in are
read from one struct chosen in Memory::new, instead of from constants at each
call site. RADV's values only; the Vulkan calls and their arguments are
unchanged. A buried chunk keeps its RawChunk, so reap, reap_all and
free_raw_chunk free it through one function.

The driver-independent half of #168 (360900), with its names kept so it
rebases onto this.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 00:26:43 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 17:37 UTC · original

Merged, thanks: the driver-specific constants are in one struct, and the three copies of the chunk-freeing code are one. #168 can merge main now, as its author offered.

**@⁠vktory6** on GitHub · 2026-12-02 17:37 UTC · [original](https://github.com/vktory6/VKtory/pull/178#issuecomment-7353480485) Merged, thanks: the driver-specific constants are in one struct, and the three copies of the chunk-freeing code are one. #168 can merge main now, as its author offered.
github-bot changed target branch from main to gh-pr/178/base 2026-12-02 18:26:54 +00:00
github manually merged commit 3d3658f16c into gh-pr/178/base 2026-12-02 18:26:56 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.