D3D12.X: charge the compute-blob budget once per cache entry #826

Open
github-bot wants to merge 1 commit from github-bot/gh-826 into main AGit
Owner

@⁠mikebuckets171 on GitHub · 2026-11-24 06:12 UTC · original
mikebuckets171:pr/blob-cache-accounting → main · +35 −3 · 1 files · 1 commits · draft

What

keep_compute_blob charges a driver blob's size to the COMPUTE_BLOBS_MAX total and then inserts it.
Two calls for the same key can pass the compute_blob(key).is_some() guard above before either has
stored its result (the guard and the insert are not one step): both charge, only one entry ends up in
the map, and the discarded charge is never taken back — forget_compute_blob subtracts only what the
map holds. The budget then drifts upward with bytes the map never kept, and later blobs of real
programs are refused while memory is free.

Insert through the entry API and charge a vacant key only. insert_compute_blob is split out so the
accounting is testable without a GPU; the new test is CPU-only.

Size: +35 / −3, one file (crates/xcl/src/hle/d3d12x/real.rs), one logical change.

Note on ordering: #774 changes the call site around keep_compute_blob (a refused driver blob going to
the big-compile queue). It does not touch the charge or the insert, so the two are independent, but
whichever lands first I will rebase onto.

Tested

  • Builds on macOS (Apple silicon) for the Wine target x86_64-pc-windows-gnullvm (LLVM-MinGW 20261117 as
    the linker): main at e50836b and this head — both green in 0.1–20 s incremental.
  • The unit tests, run under Wine (CrossOver 26 bottle, D3DMetal), lib unit binary of this head, filtered
    to the module this patch is about: compute_blob_tests → 2 passed, 0 failed (the new
    two_results_for_one_key_charge_the_budget_once, which asserts that the second result for one key
    charges nothing and that the first blob is the one kept, plus the existing key/forget test).
  • The same binary unfiltered on this host: 188 tests started, 14 failed, 0 skipped before a 300 s cap —
    all in the GPU families this host is known for (the v_*_f64 programs and several graphics tests), the
    same ones the other macOS reports in #258 name. None of them reach the code this patch changes; the
    section that runs on the CPU passes.
  • A 60 s xcl-smoke pair from this bench (same title, same bottle, same sandbox, same DXC 1.9.2609, each
    on a fresh data root), one on a commit of main, one on this head:
xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: AMD Compatibility Mode
title: retail (Xbox Series X|S package, private drive)
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB
xcl-smoke v1
commit: 991b4da1a0dc6b299410f3d6981d3bd84ad1224c
gpu: AMD Compatibility Mode
title: retail (Xbox Series X|S package, private drive)
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

Read these as what they are: on this host they show that the head adds no device removals, no crashes and
no commit growth — not frame parity. main cross-built for the Wine target does not reach a presented
frame at all (it stops ~1.8 s in with 0 presents and no PSO work; main has no Mac host path yet), so
both sides of a main-based Mac pair are 0 frames. The host where this title does run is @⁠Ahmet-Dedeler's
Mac port; COMPUTE_BLOBS does not exist on that port's base, so there is no pair to take there for this
patch. The package is on a private drive, so its name is not put here.

  • Cross-built on Windows with the whole suite, by other contributors, with the counts CONTRIBUTING item 2
    asks for (quoted from their comments below, not run by this bench):
    • @⁠dcastell1 — Windows 11, RTX 5090, MSVC, applied on main@beaa245: cargo test --workspace -- --test-threads=4 → 738 passed, 0 failed, 41 ignored (one more passing test than main on the
      same box).
    • @⁠SlopTart — Linux / RX 7900 XT, cross x86_64-pc-windows-gnu, head on main@a1672ef: 705 passed,
      11 failed, 41 ignored
      , the 11 being that host's known Wine-lane set, "nothing here fails because of
      your change".
  • A review by @⁠iggyvilla found a clause in the new doc comment that was not true (a blob forgotten and
    built again is vacant again and charged once, because forget_compute_blob removes and subtracts under
    one lock). It is corrected in 991b4da, which is why this head was re-pushed and its block re-run.

Not tested

  • Windows: this bench has no Windows machine; the suite counts above are other contributors' runs, and the
    Windows xcl-smoke pair @⁠Kalmarv offered in #258 (04:34) — main and this head, same title and time, on
    an RTX 5070 Ti — is still to come.
  • A title that reaches the compute-blob cache on a host that has it: on this host the title never gets to
    compute work.

AI use

  • GPT-6 Luna, for the patch and its test, from a diagnosis made on a macOS bench.
**@⁠mikebuckets171** on GitHub · 2026-11-24 06:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/826) `mikebuckets171:pr/blob-cache-accounting` → `main` · +35 −3 · 1 files · 1 commits · draft ## What `keep_compute_blob` charges a driver blob's size to the `COMPUTE_BLOBS_MAX` total and then inserts it. Two calls for the same key can pass the `compute_blob(key).is_some()` guard above before either has stored its result (the guard and the insert are not one step): both charge, only one entry ends up in the map, and the discarded charge is never taken back — `forget_compute_blob` subtracts only what the map holds. The budget then drifts upward with bytes the map never kept, and later blobs of real programs are refused while memory is free. Insert through the entry API and charge a vacant key only. `insert_compute_blob` is split out so the accounting is testable without a GPU; the new test is CPU-only. Size: +35 / −3, one file (`crates/xcl/src/hle/d3d12x/real.rs`), one logical change. Note on ordering: #774 changes the call site around `keep_compute_blob` (a refused driver blob going to the big-compile queue). It does not touch the charge or the insert, so the two are independent, but whichever lands first I will rebase onto. **Tested** - Builds on macOS (Apple silicon) for the Wine target `x86_64-pc-windows-gnullvm` (LLVM-MinGW 20261117 as the linker): `main` at `e50836b` and this head — both green in 0.1–20 s incremental. - The unit tests, run under Wine (CrossOver 26 bottle, D3DMetal), lib unit binary of this head, filtered to the module this patch is about: `compute_blob_tests` → **2 passed, 0 failed** (the new `two_results_for_one_key_charge_the_budget_once`, which asserts that the second result for one key charges nothing and that the first blob is the one kept, plus the existing key/forget test). - The same binary unfiltered on this host: 188 tests started, **14 failed, 0 skipped** before a 300 s cap — all in the GPU families this host is known for (the `v_*_f64` programs and several graphics tests), the same ones the other macOS reports in #258 name. None of them reach the code this patch changes; the section that runs on the CPU passes. - A 60 s `xcl-smoke` pair from this bench (same title, same bottle, same sandbox, same DXC 1.9.2609, each on a fresh data root), one on a commit of `main`, one on this head: ``` xcl-smoke v1 commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a gpu: AMD Compatibility Mode title: retail (Xbox Series X|S package, private drive) seconds: 60 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 0 MB ``` ``` xcl-smoke v1 commit: 991b4da1a0dc6b299410f3d6981d3bd84ad1224c gpu: AMD Compatibility Mode title: retail (Xbox Series X|S package, private drive) seconds: 60 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 0 MB ``` Read these as what they are: on this host they show that the head adds no device removals, no crashes and no commit growth — not frame parity. `main` cross-built for the Wine target does not reach a presented frame at all (it stops ~1.8 s in with 0 presents and no PSO work; `main` has no Mac host path yet), so both sides of a `main`-based Mac pair are 0 frames. The host where this title does run is @⁠Ahmet-Dedeler's Mac port; `COMPUTE_BLOBS` does not exist on that port's base, so there is no pair to take there for this patch. The package is on a private drive, so its name is not put here. - Cross-built on Windows with the whole suite, by other contributors, with the counts CONTRIBUTING item 2 asks for (quoted from their comments below, not run by this bench): - @⁠dcastell1 — Windows 11, RTX 5090, MSVC, applied on `main@beaa245`: `cargo test --workspace -- --test-threads=4` → **738 passed, 0 failed, 41 ignored** (one more passing test than `main` on the same box). - @⁠SlopTart — Linux / RX 7900 XT, cross `x86_64-pc-windows-gnu`, head on `main@a1672ef`: **705 passed, 11 failed, 41 ignored**, the 11 being that host's known Wine-lane set, "nothing here fails because of your change". - A review by @⁠iggyvilla found a clause in the new doc comment that was not true (a blob forgotten and built again is vacant again and charged once, because `forget_compute_blob` removes and subtracts under one lock). It is corrected in `991b4da`, which is why this head was re-pushed and its block re-run. **Not tested** - Windows: this bench has no Windows machine; the suite counts above are other contributors' runs, and the Windows `xcl-smoke` pair @⁠Kalmarv offered in #258 (04:34) — `main` and this head, same title and time, on an RTX 5070 Ti — is still to come. - A title that reaches the compute-blob cache on a host that has it: on this host the title never gets to compute work. **AI use** - GPT-6 Luna, for the patch and its test, from a diagnosis made on a macOS bench.
keep_compute_blob checks compute_blob(key) and then inserts, two separate lock acquisitions: two
xcl-pso workers can both pass the check for the same pipeline, both charge the COMPUTE_BLOBS_MAX
total, and only one entry ends up in the map. The discarded charge is never taken back -
forget_compute_blob subtracts only what the map holds - so the budget drifts upward with bytes the
map never kept and later blobs of real programs are refused while memory is free.

Insert through the entry API and charge a vacant key only, which keeps the total equal to what the
map holds. insert_compute_blob is split out so the accounting is testable without a GPU; the new
test is CPU-only.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:52 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 06:50 UTC · original

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, applied on main@beaa245:

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
test result: 738 passed; 0 failed; 41 ignored   (20 blocks, exit 0)

That is one more passing test than main on the same box (737), so the compute-blob budget charged once per cache entry runs green here and nothing else in the workspace changes verdict. No game data, hardware adapter, no Wine.

AI-assisted (opencode): applied the patch to a built tree, ran the suite, restored the two files.

**@⁠dcastell1** on GitHub · 2026-11-24 06:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/826#issuecomment-7124351185) Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, applied on `main@beaa245`: ``` patch -p1 < this PR # clean, no fuzz cargo test --workspace -- --test-threads=4 test result: 738 passed; 0 failed; 41 ignored (20 blocks, exit 0) ``` That is one more passing test than `main` on the same box (737), so the compute-blob budget charged once per cache entry runs green here and nothing else in the workspace changes verdict. No game data, hardware adapter, no Wine. AI-assisted (opencode): applied the patch to a built tree, ran the suite, restored the two files.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-24 07:17 UTC · original

Linux / AMD RDNA3 datapoint.

Merged state: head 5aa4c42 onto main a1672ef, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 705 passed, 11 failed, 41 ignored. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Compute-blob budget accounting tests green; no new failures.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-24 07:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/826#issuecomment-7124835446) Linux / AMD RDNA3 datapoint. **Merged state:** head `5aa4c42` onto main `a1672ef`, clean merge. **Full suite, `cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4`:** **705 passed, 11 failed, 41 ignored**. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Compute-blob budget accounting tests green; no new failures. **Not tested:** retail titles (none here), Windows, RDNA4. Counts only, no game data. **Machine:** RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross `x86_64-pc-windows-gnu`, `XCL_NETWORK=0`, release profile, `--test-threads=4`. Linux rows: #42 / #718. AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Author
Owner

@⁠iggyvilla on GitHub · 2026-11-24 07:34 UTC · original

Read of 5aa4c42 (not built or run by me): the fix is right. keep_compute_blob runs on the xcl-pso workers, the compute_blob(key).is_some() check and the insert are two separate lock acquisitions, and charging only the Entry::Vacant case keeps total equal to what the map holds.

One sentence in the doc comment of insert_compute_blob is not true: "a program built again after its blob was forgotten reaches this call a second time: inserting in both cases charges the budget for bytes the map does not hold". forget_compute_blob removes the entry and subtracts its length from total in the same lock, so a later insert for that key is vacant and is charged once, correctly; only two workers inserting the same key at once ever double-charged. I would drop that clause so the comment names the one case the change fixes.

AI use: Claude Code, Claude Sonnet 5.5, read the diff and checked it against forget_compute_blob; the comment is mine.

**@⁠iggyvilla** on GitHub · 2026-11-24 07:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/826#issuecomment-7125139315) Read of `5aa4c42` (not built or run by me): the fix is right. `keep_compute_blob` runs on the `xcl-pso` workers, the `compute_blob(key).is_some()` check and the insert are two separate lock acquisitions, and charging only the `Entry::Vacant` case keeps `total` equal to what the map holds. One sentence in the doc comment of `insert_compute_blob` is not true: "a program built again after its blob was forgotten reaches this call a second time: inserting in both cases charges the budget for bytes the map does not hold". `forget_compute_blob` removes the entry and subtracts its length from `total` in the same lock, so a later insert for that key is vacant and is charged once, correctly; only two workers inserting the same key at once ever double-charged. I would drop that clause so the comment names the one case the change fixes. **AI use:** Claude Code, Claude Sonnet 5.5, read the diff and checked it against `forget_compute_blob`; the comment is mine.
Author
Owner

@⁠mikebuckets171 on GitHub · 2026-11-24 07:42 UTC · original

@⁠iggyvilla you are right and it is fixed: forget_compute_blob removes the entry and subtracts its length under the same lock, so a blob built again after being forgotten is vacant and is charged once, correctly. The double charge only ever happens between two workers that both pass the compute_blob(key).is_some() check. The doc comment now names that one case and says explicitly that the forgotten-then-rebuilt case is correct (991b4da). The head's xcl-smoke block was re-run on the new commit; the suite counts from @⁠dcastell1 and @⁠SlopTart are quoted in the description so the gate sees them where the PR is read. Thanks for reading the diff closely.

**@⁠mikebuckets171** on GitHub · 2026-11-24 07:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/826#issuecomment-7125282200) @⁠iggyvilla you are right and it is fixed: `forget_compute_blob` removes the entry and subtracts its length under the same lock, so a blob built again after being forgotten is vacant and is charged once, correctly. The double charge only ever happens between two workers that both pass the `compute_blob(key).is_some()` check. The doc comment now names that one case and says explicitly that the forgotten-then-rebuilt case is correct (`991b4da`). The head's `xcl-smoke` block was re-run on the new commit; the suite counts from @⁠dcastell1 and @⁠SlopTart are quoted in the description so the gate sees them where the PR is read. Thanks for reading the diff closely.
Author
Owner

@⁠mikebuckets171 on GitHub · 2026-11-24 11:07 UTC · original

Premise re-checked against today's main, because real.rs moved under this PR after it was filed - the change still describes main accurately.

Since this was filed, real.rs absorbed at least four merges (5c3ff31, 11920b5, e7da8a1, 285560f). Re-read at 6efdabc:

  • keep_compute_blob is at real.rs:3640. It still takes the lock, checks only capacity - if bytes.is_empty() || *total + bytes.len() > COMPUTE_BLOBS_MAX { return; } (3654) - then charges *total += bytes.len() (3657) and inserts m.insert(key, std::sync::Arc::new(bytes)) (3658), with no check of whether key is already charged.
  • The vacancy question is still asked earlier and elsewhere: the caller does let mut cached = compute_blob(key) at real.rs:3420 and calls keep_compute_blob(key, *ppv, dxil.len()) at 3449. Two workers can still both find the key vacant and both charge for it, which is what this PR closes.
  • New since filing: line 3450 re-reads the map after keeping (if let (Some(p), Some(b)) = (disk.as_deref(), compute_blob(key))) to write the blob to the disk cache. That interacts with this change but does not fight it: this patch keeps the first blob stored for a key, so the disk write takes the same blob the map holds. No behavioural fork between the two paths.

git merge-tree of 6efdabc against pr/blob-cache-accounting reports no conflict, so the branch needs no rebase for the Windows pair @⁠Kalmarv offered - head 991b4da onto 6efdabc is a clean merge. PR checks is green here; CI has never started on any of my heads (only the PR checks description job appears, which is main's own pull_request_target workflow), so a maintainer's workflow approval is still what it needs to leave draft.

Host: macOS 27.2.1 (Apple silicon, M5 Pro), CrossOver 26, D3DMetal - the port-side tests behind this PR's Tested section were run here. AI use: GPT-6 Luna re-read the code at 6efdabc, ran the merge check and drafted this comment; no new runs were needed for it.

**@⁠mikebuckets171** on GitHub · 2026-11-24 11:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/826#issuecomment-7129677170) **Premise re-checked against today's `main`, because `real.rs` moved under this PR after it was filed - the change still describes main accurately.** Since this was filed, `real.rs` absorbed at least four merges (`5c3ff31`, `11920b5`, `e7da8a1`, `285560f`). Re-read at `6efdabc`: - `keep_compute_blob` is at `real.rs:3640`. It still takes the lock, checks only capacity - `if bytes.is_empty() || *total + bytes.len() > COMPUTE_BLOBS_MAX { return; }` (3654) - then charges `*total += bytes.len()` (3657) and inserts `m.insert(key, std::sync::Arc::new(bytes))` (3658), with no check of whether `key` is already charged. - The vacancy question is still asked earlier and elsewhere: the caller does `let mut cached = compute_blob(key)` at `real.rs:3420` and calls `keep_compute_blob(key, *ppv, dxil.len())` at 3449. Two workers can still both find the key vacant and both charge for it, which is what this PR closes. - New since filing: line 3450 re-reads the map after keeping (`if let (Some(p), Some(b)) = (disk.as_deref(), compute_blob(key))`) to write the blob to the disk cache. That interacts with this change but does not fight it: this patch keeps the first blob stored for a key, so the disk write takes the same blob the map holds. No behavioural fork between the two paths. `git merge-tree` of `6efdabc` against `pr/blob-cache-accounting` reports no conflict, so the branch needs no rebase for the Windows pair @⁠Kalmarv offered - head `991b4da` onto `6efdabc` is a clean merge. `PR checks` is green here; `CI` has never started on any of my heads (only the `PR checks` description job appears, which is main's own `pull_request_target` workflow), so a maintainer's workflow approval is still what it needs to leave draft. Host: macOS 27.2.1 (Apple silicon, M5 Pro), CrossOver 26, D3DMetal - the port-side tests behind this PR's `Tested` section were run here. **AI use**: GPT-6 Luna re-read the code at `6efdabc`, ran the merge check and drafted this comment; no new runs were needed for it.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 10:38 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 10:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/826#issuecomment-7159978180) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/real.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/826/head:github-bot/gh-826'
git switch 'github-bot/gh-826'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-826'
git switch 'github-bot/gh-826'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-826'
git switch 'github-bot/gh-826'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-826'
git switch 'main'
git merge --squash 'github-bot/gh-826'
git switch 'main'
git merge --ff-only 'github-bot/gh-826'
git switch 'main'
git merge 'github-bot/gh-826'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.