D3D12.X: keep an argument-ordering buffer per device #3685

Open
KDenKC wants to merge 1 commit from upstream-pr/3685 into main
KDenKC commented 2026-12-02 09:57:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T09:57:30Z.


fresh_indirect_arguments keeps one buffer of XCL's own for reordering ExecuteIndirect arguments. It was a single (device, buffer) slot. A list of another device (two devices in one process, or a device made again) replaced it, and so dropped a buffer that lists already recorded on the first device may still use. Each device now keeps its own buffer, and the entry holds a reference to its device, so no other device can be made at the address it is keyed by while the entry exists.

bmjask found this while reviewing #3317, whose indirect scaling-pipeline cache had the same kind of bug. It was a commit of #3317 until Foniass asked for the split (CONTRIBUTING: one logical change per PR).

Related: #3317.

What is in it (hle/d3d12x/bind.rs)

  • D3D12.X: keep an argument-ordering buffer per device (01de8f39): ARGUMENT_ORDER becomes a map from the device's address to (device, buffer); argument_order_buffer looks up and inserts by device.
    • Test: argument_order_buffers_are_kept_per_device. The hardware device and WARP each get their own buffer, and the first device's buffer is still its own after the second one asked. It fails with the single slot.

Tested

  • NVIDIA GeForce RTX 3090 24 GB, driver 621.24 (32.0.16.2124), Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug, head 01de8f39:
    • cargo test --workspace --no-fail-fast -- --test-threads=4: 2902 passed, 5 failed, 51 ignored. The 5 fail on main 1c8b5514 too: title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, the 3 stream_recheck_* tests, and e2e test_title_runs_and_game_folder_is_untouched.
    • SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no debug layer, 1 driver cache cannot be disabled).
    • The run leaves out the 3 uma_driver coherent-window remake tests, as on every run on this machine.
    • -- argument_order_buffers_are_kept_per_device: 1 passed (as part of #3317's head 444aa227, the same code).

Regression run

Smoke arm: the #3685 head vs the REUSED gate-batch-t main block (main 1c8b5514): 600 s each, JIT (XCL_PREPARE=0), seed copy of main-full-d8bd + the r18-terms data seed (2026-12-02 03:17, RTX 5090)

main: 1724 frames, removals 0, peak commit 47581 MB

  • main block:
xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1724 (PresentX 1725)
presents per 2 s (last 3): 2 1 2
device removals: 0
crashes: 0
peak commit: 47581 MB
  • #3685 head block (#3685 head 01de8f39e9: 1994 frames, removals 0, peak commit 48132 MB (main: 1724 frames, removals 0, peak commit 47581 MB)) -
xcl-smoke v1
commit: 01de8f39e9b36fbd82be093d66820f33ab032185
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1994 (PresentX 1995)
presents per 2 s (last 3): 2 2 2
device removals: 0
crashes: 0
peak commit: 48132 MB

Not tested

  • Two devices in the retail title: the title makes one device, so the bug does not show there; the test makes two (hardware and WARP).
  • AMD, Intel.

AI use

  • Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 4 Hydrogen): an agent swarm wrote, tested, reviewed and described this change.
<!-- greyfinch-sync:ivall/xcl:issue:5604084507 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3685). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-02T09:57:30Z. --- `fresh_indirect_arguments` keeps one buffer of XCL's own for reordering ExecuteIndirect arguments. It was a single (device, buffer) slot. A list of another device (two devices in one process, or a device made again) replaced it, and so dropped a buffer that lists already recorded on the first device may still use. Each device now keeps its own buffer, and the entry holds a reference to its device, so no other device can be made at the address it is keyed by while the entry exists. bmjask found this while reviewing #3317, whose indirect scaling-pipeline cache had the same kind of bug. It was a commit of #3317 until Foniass asked for the split (CONTRIBUTING: one logical change per PR). Related: #3317. **What is in it** (`hle/d3d12x/bind.rs`) - `D3D12.X: keep an argument-ordering buffer per device` (`01de8f39`): `ARGUMENT_ORDER` becomes a map from the device's address to (device, buffer); `argument_order_buffer` looks up and inserts by device. - Test: `argument_order_buffers_are_kept_per_device`. The hardware device and WARP each get their own buffer, and the first device's buffer is still its own after the second one asked. It fails with the single slot. **Tested** - NVIDIA GeForce RTX 3090 24 GB, driver 621.24 (32.0.16.2124), Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug, head `01de8f39`: - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2902 passed, 5 failed, 51 ignored. The 5 fail on `main` `1c8b5514` too: `title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels`, the 3 `stream_recheck_*` tests, and e2e `test_title_runs_and_game_folder_is_untouched`. - SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no debug layer, 1 driver cache cannot be disabled). - The run leaves out the 3 `uma_driver` coherent-window remake tests, as on every run on this machine. - `-- argument_order_buffers_are_kept_per_device`: 1 passed (as part of #3317's head `444aa227`, the same code). **Regression run** ## Smoke arm: the #3685 head vs the REUSED gate-batch-t main block (main 1c8b5514): 600 s each, JIT (XCL_PREPARE=0), seed copy of main-full-d8bd + the r18-terms data seed (2026-12-02 03:17, RTX 5090) main: 1724 frames, removals 0, peak commit 47581 MB - main block: ``` xcl-smoke v1 commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f gpu: NVIDIA GeForce RTX 5090 title: 9cc6a39e seconds: 600 exit: 0x0 frames shown: 1724 (PresentX 1725) presents per 2 s (last 3): 2 1 2 device removals: 0 crashes: 0 peak commit: 47581 MB ``` - #3685 head block (#3685 head 01de8f39e9b36fbd82be093d66820f33ab032185: 1994 frames, removals 0, peak commit 48132 MB (main: 1724 frames, removals 0, peak commit 47581 MB)) - ``` xcl-smoke v1 commit: 01de8f39e9b36fbd82be093d66820f33ab032185 gpu: NVIDIA GeForce RTX 5090 title: 9cc6a39e seconds: 600 exit: 0x0 frames shown: 1994 (PresentX 1995) presents per 2 s (last 3): 2 2 2 device removals: 0 crashes: 0 peak commit: 48132 MB ``` **Not tested** - Two devices in the retail title: the title makes one device, so the bug does not show there; the test makes two (hardware and WARP). - AMD, Intel. **AI use** - Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 4 Hydrogen): an agent swarm wrote, tested, reviewed and described this change.
Foniass commented 2026-12-02 10:00:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:00:06Z.


Review (head 01de8f39, diff read, not a merge-check; draft, checks red):

No problems found in the diff. This is 444aa227 from #3317 split out (only the commit message differs): ARGUMENT_ORDER (bind.rs ~3956) is now one buffer per device keyed by its address, with the entry holding a reference to the device so the key cannot be reused while the entry exists, and a list of another device no longer replaces a buffer the first device's recorded lists may use. argument_order_buffers_are_kept_per_device checks it with the hardware device and WARP (it fails with the single slot). Note the test leaves both devices in the process-wide map for the rest of the test run. The xcl-smoke blocks are owed (the reason PR description is red).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7341806461 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3685#issuecomment-7341806461). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T10:00:06Z. --- Review (head 01de8f39, diff read, not a merge-check; draft, checks red): No problems found in the diff. This is `444aa227` from #3317 split out (only the commit message differs): `ARGUMENT_ORDER` (`bind.rs` ~3956) is now one buffer per device keyed by its address, with the entry holding a reference to the device so the key cannot be reused while the entry exists, and a list of another device no longer replaces a buffer the first device's recorded lists may use. `argument_order_buffers_are_kept_per_device` checks it with the hardware device and WARP (it fails with the single slot). Note the test leaves both devices in the process-wide map for the rest of the test run. The `xcl-smoke` blocks are owed (the reason `PR description` is red). AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
thehollowedone commented 2026-12-02 12:13:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-02T12:13:02Z.


merge-check
base: df0cfef638
head: 01de8f39e9
merge: clean (local trial merge 19b1b0fa296c83131b26029927309edd9a35dd12); git diff --check origin/main..HEAD clean
build: cargo build --workspace -> ok; cargo build --release -p xcl -> ok on both clean trees
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2,912 passed, 0 failed, 51 ignored across 43 test targets; 24 SKIPPED notices (22 no wave64, 2 heap windows not enabled). The new argument_order_buffers_are_kept_per_device test passed on the NVIDIA device and WARP.
review: Read the whole merged diff (one file, +41/-4). The cache now retains the first buffer for each device and a strong reference to that device, so another device cannot replace a buffer already used by recorded lists or reuse its address as a cache key. #3317 has split this change out. No blocking correctness issue found. The map retains one entry per device for process lifetime; repeated device creation and AMD/Intel execution were not tested here.
performance: Matched 60 s release smoke: 1,674 -> 1,678 frames (+0.24%); peak commit 16,944 -> 17,617 MB (+673 MB, +3.97%); both exited 0 with zero device removals and crashes, and the last three 2 s present counts were 60 60 60. The cache change adds a lookup on the argument-buffer path and retains one buffer per device; the short smoke cannot isolate its memory cost from run variation.
verdict: safe to merge: the current-main merge is clean, the complete suite has no failures, the two-device regression passes, and the matched smoke meets the repository's frame and memory thresholds. No unresolved critical finding in the diff.
hardware / tool and model: NVIDIA GeForce RTX 3080 Ti (driver 621.40), AMD Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC / OpenAI Codex (GPT-6 Sol)

Generated smoke blocks from scripts/smoke.ps1 with the same title label and settings:

xcl-smoke v1
commit: df0cfef638306f325b208e5adae18d35ab4bf4ed
gpu: NVIDIA GeForce RTX 3080 Ti
title: retail sample
seconds: 60
exit: 0x0
frames shown: 1674 (PresentX 1674)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16944 MB
xcl-smoke v1
commit: 19b1b0fa296c83131b26029927309edd9a35dd12
gpu: NVIDIA GeForce RTX 3080 Ti
title: retail sample
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17617 MB
<!-- greyfinch-sync:ivall/xcl:comment:7345008951 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3685#issuecomment-7345008951). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-02T12:13:02Z. --- merge-check base: df0cfef638306f325b208e5adae18d35ab4bf4ed head: 01de8f39e9b36fbd82be093d66820f33ab032185 merge: clean (local trial merge 19b1b0fa296c83131b26029927309edd9a35dd12); `git diff --check origin/main..HEAD` clean build: `cargo build --workspace` -> ok; `cargo build --release -p xcl` -> ok on both clean trees tests: `cargo test --workspace --no-fail-fast -- --test-threads=4` -> 2,912 passed, 0 failed, 51 ignored across 43 test targets; 24 `SKIPPED` notices (22 no wave64, 2 heap windows not enabled). The new `argument_order_buffers_are_kept_per_device` test passed on the NVIDIA device and WARP. review: Read the whole merged diff (one file, +41/-4). The cache now retains the first buffer for each device and a strong reference to that device, so another device cannot replace a buffer already used by recorded lists or reuse its address as a cache key. #3317 has split this change out. No blocking correctness issue found. The map retains one entry per device for process lifetime; repeated device creation and AMD/Intel execution were not tested here. performance: Matched 60 s release smoke: 1,674 -> 1,678 frames (+0.24%); peak commit 16,944 -> 17,617 MB (+673 MB, +3.97%); both exited 0 with zero device removals and crashes, and the last three 2 s present counts were 60 60 60. The cache change adds a lookup on the argument-buffer path and retains one buffer per device; the short smoke cannot isolate its memory cost from run variation. verdict: safe to merge: the current-main merge is clean, the complete suite has no failures, the two-device regression passes, and the matched smoke meets the repository's frame and memory thresholds. No unresolved critical finding in the diff. hardware / tool and model: NVIDIA GeForce RTX 3080 Ti (driver 621.40), AMD Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC / OpenAI Codex (GPT-6 Sol) Generated smoke blocks from `scripts/smoke.ps1` with the same title label and settings: ``` xcl-smoke v1 commit: df0cfef638306f325b208e5adae18d35ab4bf4ed gpu: NVIDIA GeForce RTX 3080 Ti title: retail sample seconds: 60 exit: 0x0 frames shown: 1674 (PresentX 1674) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16944 MB ``` ``` xcl-smoke v1 commit: 19b1b0fa296c83131b26029927309edd9a35dd12 gpu: NVIDIA GeForce RTX 3080 Ti title: retail sample seconds: 60 exit: 0x0 frames shown: 1678 (PresentX 1678) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17617 MB ```
fromthemoonx commented 2026-12-02 14:15:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-02T14:15:11Z.


merge-check
base: 5eaadb54c1
head: 01de8f39e9
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2975 passed, 0 failed, 52 ignored (base: 2974 passed, 0 failed, 52 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (1 file, +41 -4). No problem found.

  • Each device keeps its own buffer, and the entry holds a reference to the device, so its address cannot be reused as a key while the entry exists. Entries are never removed: one small buffer per device for the life of the process.
  • argument_order_buffers_are_kept_per_device alone: 30 of 30, on the RTX 3060 and WARP, not skipped. With the old single-slot behaviour put back it fails ("the first device's buffer was not replaced").
  • The bind::tests module at 8 threads flakes with and without this PR. Not this PR:
    • base: 186 of 480 runs fail, nearly all in later_queue_completion_during_sleep_reclaims_before_wait_deadline, 3 failures in two other buffer-reclaim tests;
    • this PR: 105 of 330 runs fail, nearly all in that same test, 3 failures in two other buffer-reclaim tests;
    • this PR with #3609 (my open fix for the test that empties their shared pool): 330 of 330 pass.
  • No title was run here, and the author says the retail title makes only one device.
    performance: a map lookup under the lock that was already taken, once per ordered ExecuteIndirect. Not measured here; the author's smoke pair and thehollowedone's are within the limits.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
<!-- greyfinch-sync:ivall/xcl:comment:7348236724 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3685#issuecomment-7348236724). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-02T14:15:11Z. --- merge-check base: 5eaadb54c14e0fc29597b2a1689d7dbd83491303 head: 01de8f39e9b36fbd82be093d66820f33ab032185 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2975 passed, 0 failed, 52 ignored (base: 2974 passed, 0 failed, 52 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none review: read the whole diff (1 file, +41 -4). No problem found. - Each device keeps its own buffer, and the entry holds a reference to the device, so its address cannot be reused as a key while the entry exists. Entries are never removed: one small buffer per device for the life of the process. - `argument_order_buffers_are_kept_per_device` alone: 30 of 30, on the RTX 3060 and WARP, not skipped. With the old single-slot behaviour put back it fails ("the first device's buffer was not replaced"). - The `bind::tests` module at 8 threads flakes with and without this PR. Not this PR: - base: 186 of 480 runs fail, nearly all in `later_queue_completion_during_sleep_reclaims_before_wait_deadline`, 3 failures in two other buffer-reclaim tests; - this PR: 105 of 330 runs fail, nearly all in that same test, 3 failures in two other buffer-reclaim tests; - this PR with #3609 (my open fix for the test that empties their shared pool): 330 of 330 pass. - No title was run here, and the author says the retail title makes only one device. performance: a map lookup under the lock that was already taken, once per ordered ExecuteIndirect. Not measured here; the author's smoke pair and thehollowedone's are within the limits. verdict: safe to merge hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
gut0to commented 2026-12-02 19:45:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T19:45:57Z.

Review: COMMENTED


AI-assisted review: GPT-6 helped inspect the cache; I checked the retention path in the current diff.

<!-- greyfinch-sync:ivall/xcl:review:6157723029 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3685#pullrequestreview-6157723029). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T19:45:57Z. **Review:** COMMENTED --- AI-assisted review: GPT-6 helped inspect the cache; I checked the retention path in the current diff.
gut0to commented 2026-12-02 19:45:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T19:45:57Z.

Code review location: crates/xcl/src/hle/d3d12x/bind.rs; line 4060

@@ -4054,7 +4057,7 @@ unsafe fn argument_order_buffer(list: &ID3D12GraphicsCommandList) -> Option<ID3D
         return None;
     }
     let b = b?;
-    *g = Some((dev.as_raw() as usize, b.clone()));
+    g.get_or_insert_with(HashMap::new).insert(key, (dev.clone(), b.clone()));

Medium: This process-global map retains a strong ID3D12Device and its argument-ordering buffer for every device pointer, but the PR adds no removal path. If a title recreates its D3D12 device, each old device and buffer remains referenced; repeated recreations accumulate them for the process lifetime. Could entries be retired once no recorded command list can reference the buffer? AI-assisted review: GPT-6 helped inspect the cache; I checked the retention path in the current diff.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775026683 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3685#discussion_r4775026683). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T19:45:57Z. **Code review location:** `crates/xcl/src/hle/d3d12x/bind.rs`; line 4060 ~~~~diff @@ -4054,7 +4057,7 @@ unsafe fn argument_order_buffer(list: &ID3D12GraphicsCommandList) -> Option<ID3D return None; } let b = b?; - *g = Some((dev.as_raw() as usize, b.clone())); + g.get_or_insert_with(HashMap::new).insert(key, (dev.clone(), b.clone())); ~~~~ --- **Medium**: This process-global map retains a strong `ID3D12Device` and its argument-ordering buffer for every device pointer, but the PR adds no removal path. If a title recreates its D3D12 device, each old device and buffer remains referenced; repeated recreations accumulate them for the process lifetime. Could entries be retired once no recorded command list can reference the buffer? AI-assisted review: GPT-6 helped inspect the cache; I checked the retention path in the current diff.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3685:upstream-pr/3685'
git switch 'upstream-pr/3685'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3685'
git switch 'upstream-pr/3685'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3685'
git switch 'upstream-pr/3685'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3685'
git switch 'main'
git merge --squash 'upstream-pr/3685'
git switch 'main'
git merge --ff-only 'upstream-pr/3685'
git switch 'main'
git merge 'upstream-pr/3685'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3685
No description provided.