D3D12.X: same-window copies skip the scratch buffer while a list's last submission runs #1408

Open
opened 2026-11-26 04:53:05 +00:00 by github-bot · 2 comments
Owner

@⁠pvfreis on GitHub · 2026-11-24 15:41 UTC · original

On main (930e8b4), once a list has a scratch buffer, a CopyMemoryToMemoryX within one unified-memory window reads through it only when it is idle or already used by the current recording (CopyScratchCache::acquire, list_x.rs:2054-2058, from 392dc0c). After KickoffX of a recording that made such a copy (list_x.rs:2979-2980, then reset_copy_scratch at :3038), or after Reset of a list whose last submission made one and has not finished on the GPU (reset_x, :3591), the scratch has a pending fence mark and is no longer recorded, so acquire returns None even when the 64 MiB budget has room. copy_memory_x then takes its fallback, the copy within one buffer in COPY_DEST (:1978-1982), which is the copy #958 reported (debug layer id 538) and #993 replaced, and nothing is logged.

Run on main (RTX 3060, a local unit test, not for upstream): a real DIRECT list calls copy_scratch(list, 256), then KickoffX's steps by hand (Close, ExecuteCommandLists behind a fence the GPU waits on, copy_scratch_submitted, native Reset, reset_copy_scratch). The next copy_scratch(list, 256) returns None with 64 KiB of the 64 MiB budget in use and nothing moved to released; after the GPU passes the fence the same call returns the same buffer. The test does not call kickoff_x or copy_memory_x itself, and the debug layer was not run; the rest follows from the code.

Effect: as in #958; not measured here.

Expected: the second copy also reads through a scratch in COPY_SOURCE. Refusing to reuse a busy scratch is deliberate (the comment at :2055); the busy one could move to released, where it stays charged to the budget until its marks pass, and a new one be made within the budget, with a log line when the budget forces the fallback.

Suggested test: copy_scratch_budget_counts_resources_until_gpu_completion checks the refusal only for a request of the full budget; the same setup with a small request should get a buffer other than the busy one.

Not tested: the debug layer on this path, kickoff_x end to end, the split-list case, AMD and Intel, a retail title.

Found by reading the code and confirmed with a local unit test on main by Claude Code (Claude Opus 5.5), checked by Claude Fable 5.2; checked by a person before posting.

**@⁠pvfreis** on GitHub · 2026-11-24 15:41 UTC · [original](https://github.com/xcl-dev/xcl/issues/1408) On `main` (`930e8b4`), once a list has a scratch buffer, a `CopyMemoryToMemoryX` within one unified-memory window reads through it only when it is idle or already used by the current recording (`CopyScratchCache::acquire`, `list_x.rs:2054-2058`, from 392dc0c). After `KickoffX` of a recording that made such a copy (`list_x.rs:2979-2980`, then `reset_copy_scratch` at `:3038`), or after `Reset` of a list whose last submission made one and has not finished on the GPU (`reset_x`, `:3591`), the scratch has a pending fence mark and is no longer recorded, so `acquire` returns `None` even when the 64 MiB budget has room. `copy_memory_x` then takes its fallback, the copy within one buffer in COPY_DEST (`:1978-1982`), which is the copy #958 reported (debug layer id 538) and #993 replaced, and nothing is logged. **Run on `main`** (RTX 3060, a local unit test, not for upstream): a real DIRECT list calls `copy_scratch(list, 256)`, then KickoffX's steps by hand (Close, `ExecuteCommandLists` behind a fence the GPU waits on, `copy_scratch_submitted`, native `Reset`, `reset_copy_scratch`). The next `copy_scratch(list, 256)` returns `None` with 64 KiB of the 64 MiB budget in use and nothing moved to `released`; after the GPU passes the fence the same call returns the same buffer. The test does not call `kickoff_x` or `copy_memory_x` itself, and the debug layer was not run; the rest follows from the code. **Effect:** as in #958; not measured here. **Expected:** the second copy also reads through a scratch in COPY_SOURCE. Refusing to reuse a busy scratch is deliberate (the comment at `:2055`); the busy one could move to `released`, where it stays charged to the budget until its marks pass, and a new one be made within the budget, with a log line when the budget forces the fallback. **Suggested test:** `copy_scratch_budget_counts_resources_until_gpu_completion` checks the refusal only for a request of the full budget; the same setup with a small request should get a buffer other than the busy one. **Not tested:** the debug layer on this path, `kickoff_x` end to end, the split-list case, AMD and Intel, a retail title. Found by reading the code and confirmed with a local unit test on `main` by Claude Code (Claude Opus 5.5), checked by Claude Fable 5.2; checked by a person before posting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:05 +00:00
Author
Owner

@⁠coenflict on GitHub · 2026-11-24 18:05 UTC · original

I reproduced this on 9e3831e1f570d3646e53ab753b19ec07eb8f1485 by extending copy_scratch_budget_counts_resources_until_gpu_completion. In the fixture, one 64 KiB scratch buffer is marked in flight and another 64 KiB request for the same list returns None. The synthetic fence makes the test independent of queue timing.

A local patch gives the new recording a different buffer when there is room, holds the old allocation against the 64 MiB budget until the fence passes, and starts the existing reaper. The regression failed on the old code and passed with the patch. It also checks that an over-budget request is refused and that completion returns the retired bytes to the budget.

Tested

  • Windows 11 build 26340, Ryzen 7 9800X3D, RTX 5090 driver 32.0.16.2140, Rust 1.97.1 MSVC, DXC and DXIL 1.9.2602.17, debug.
  • cargo test -p xcl --lib copy_scratch -- --nocapture: 2 passed, 0 failed, 0 ignored, 0 skips with the patch.
  • scripts/test.ps1 --nocapture on the uncommitted patch at the base commit above: 776 reported passed, 0 failed, 41 ignored. The pass count includes three GPU skips (two no wave64, one no heap windows). XCL_SAMPLE_* inputs were unset.

Not tested

  • End-to-end KickoffX on this path, the D3D12 debug layer, and retail-title regression runs.

AI use

  • Codex (gpt-6.2-sol) wrote the local patch and regression test, ran the tests, and drafted this report.
**@⁠coenflict** on GitHub · 2026-11-24 18:05 UTC · [original](https://github.com/xcl-dev/xcl/issues/1408#issuecomment-7140146912) I reproduced this on `9e3831e1f570d3646e53ab753b19ec07eb8f1485` by extending `copy_scratch_budget_counts_resources_until_gpu_completion`. In the fixture, one 64 KiB scratch buffer is marked in flight and another 64 KiB request for the same list returns `None`. The synthetic fence makes the test independent of queue timing. A local patch gives the new recording a different buffer when there is room, holds the old allocation against the 64 MiB budget until the fence passes, and starts the existing reaper. The regression failed on the old code and passed with the patch. It also checks that an over-budget request is refused and that completion returns the retired bytes to the budget. **Tested** - Windows 11 build 26340, Ryzen 7 9800X3D, RTX 5090 driver `32.0.16.2140`, Rust 1.97.1 MSVC, DXC and DXIL 1.9.2602.17, debug. - `cargo test -p xcl --lib copy_scratch -- --nocapture`: 2 passed, 0 failed, 0 ignored, 0 skips with the patch. - `scripts/test.ps1 --nocapture` on the uncommitted patch at the base commit above: 776 reported passed, 0 failed, 41 ignored. The pass count includes three GPU skips (two no wave64, one no heap windows). `XCL_SAMPLE_*` inputs were unset. **Not tested** - End-to-end `KickoffX` on this path, the D3D12 debug layer, and retail-title regression runs. **AI use** - Codex (`gpt-6.2-sol`) wrote the local patch and regression test, ran the tests, and drafted this report.
Author
Owner

@⁠Anon64 on GitHub · 2026-11-25 02:46 UTC · original

@⁠coenflict are you opening your patch as a PR? Your report lists the retail-title regression runs as not tested. I can make the scripts/smoke.ps1 pair for it: the PR's head and its main base, on a retail title, RTX 3060 12 GB. Push it or link a branch and I'll post both blocks. If you'd rather not open it, say so and I'll write the change myself from your description (a new buffer for the new recording when the budget has room, the old allocation held against the 64 MiB until its fence passes, the reaper started), with the failing-first test, and credit you.

Written with Claude Code (Claude Opus 5.5).

**@⁠Anon64** on GitHub · 2026-11-25 02:46 UTC · [original](https://github.com/xcl-dev/xcl/issues/1408#issuecomment-7151162903) @⁠coenflict are you opening your patch as a PR? Your report lists the retail-title regression runs as not tested. I can make the `scripts/smoke.ps1` pair for it: the PR's head and its `main` base, on a retail title, RTX 3060 12 GB. Push it or link a branch and I'll post both blocks. If you'd rather not open it, say so and I'll write the change myself from your description (a new buffer for the new recording when the budget has room, the old allocation held against the 64 MiB until its fence passes, the reaper started), with the failing-first test, and credit you. Written with Claude Code (Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.