D3D12.X: refresh staged texture states before submission #3790

Open
Prime1997 wants to merge 2 commits from upstream-pr/3790 into main
Prime1997 commented 2026-12-03 14:47:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Prime1997 on 2026-12-03T14:47:07Z.


A title submission can update a texture’s state while XCL fills a CPU staging buffer. Refresh the destination’s registered subresource states under the native queue turn before recording its copy transitions. The upload carries the ownership revision selected before staging. A prior GPU writer on an eligible pending texture can stay valid. A replacement or a later GPU writer, copy-back, or source change invalidates the queued CPU copy.

What is in it

  • Use the states left by earlier work on the same queue.
  • Apply the check to tracked title uploads through the existing staging, mapping and fence paths.
  • Check timed retries against the original selection while holding the table lock used by normal selection.
  • The retail trace identifies an overlapping staged upload. The initiating command remains unknown. D3D12 queue state validation

Tested

  • Exact head 67651700045c940eadd0ebf6ef5996f546c7b4a5 on upstream main a815de932c4dc8da3b383ca44f4b094aa406fec9. Windows x64, Rust 1.100.0, RTX 3060 Ti.
  • cargo test --locked -p xcl --lib -- --test-threads=1 --nocapture --exact with the two upload ownership and retry fixtures. 2 passed, 0 failed, 0 ignored, 0 skips.
  • Same command with the two synthetic title queue upload and mapping-order fixtures. 2 passed, 0 failed, 0 ignored, 0 skips.

Regression run

The paired retail smoke is pending for this draft.

Not tested

The specific retail removal, independent cross-queue behavior, and the full workspace suite.

AI use

OpenAI Codex (GPT-6) investigated the queue path, wrote the patch and regression, and ran the targeted checks.

Contributors can use this optional temporary Discord to coordinate testing and compare results.

<!-- greyfinch-sync:ivall/xcl:issue:5628786077 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3790). Originally posted by [Prime1997](https://github.com/Prime1997) on 2026-12-03T14:47:07Z. --- A title submission can update a texture’s state while XCL fills a CPU staging buffer. Refresh the destination’s registered subresource states under the native queue turn before recording its copy transitions. The upload carries the ownership revision selected before staging. A prior GPU writer on an eligible pending texture can stay valid. A replacement or a later GPU writer, copy-back, or source change invalidates the queued CPU copy. **What is in it** - Use the states left by earlier work on the same queue. - Apply the check to tracked title uploads through the existing staging, mapping and fence paths. - Check timed retries against the original selection while holding the table lock used by normal selection. - The retail trace identifies an overlapping staged upload. The initiating command remains unknown. [D3D12 queue state validation](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12commandqueue-executecommandlists) **Tested** - Exact head `67651700045c940eadd0ebf6ef5996f546c7b4a5` on upstream `main` `a815de932c4dc8da3b383ca44f4b094aa406fec9`. Windows x64, Rust 1.100.0, RTX 3060 Ti. - `cargo test --locked -p xcl --lib -- --test-threads=1 --nocapture --exact` with the two upload ownership and retry fixtures. 2 passed, 0 failed, 0 ignored, 0 skips. - Same command with the two synthetic title queue upload and mapping-order fixtures. 2 passed, 0 failed, 0 ignored, 0 skips. **Regression run** The paired retail smoke is pending for this draft. **Not tested** The specific retail removal, independent cross-queue behavior, and the full workspace suite. **AI use** OpenAI Codex (GPT-6) investigated the queue path, wrote the patch and regression, and ran the targeted checks. Contributors can use this [optional temporary Discord](https://discord.gg/gK3y7WRRY) to coordinate testing and compare results.
Foniass commented 2026-12-03 17:42:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T17:42:15Z.


merge-check
base: 16c2fd082a
head: 6765170004
merge: clean
build: ok
tests: 3019 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 6 medium, 3 nits (below)
performance: 60 s smoke run: 1683 → 1659 frames (98 % of main), peak commit 18505 → 17840 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 238 s there, 0 device removals, 0 crashes, 3.6 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: not yet: it is a draft, and PR description is red; otherwise no blocking finding, the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: The PR records title texture uploads inside the title queue's ordered submission slot ("queue lease"). There it re-reads each destination's current resource states and drops any upload whose texture was replaced, written by the GPU, downloaded or remapped while the CPU filled the staging buffer. The new push adds a per-entry revision counter and moves retries under the texture table lock. The reading found no deadlock and no wrong barrier, and the code is consistent. The stale-drop path is still untested end to end, a retry assertion was reversed, and the conflict with #3791 remains, but nothing blocks merging.

Medium

  1. Stale-drop path is not tested. The only new test (staged_texture_upload_uses_the_latest_state_and_current_registration, title_textures.rs ~5456) calls refresh_upload_state on a local Table. Nothing runs submit_tracked (texture_upload.rs ~901) with a stale item: the retain on pieces, the "changed ownership" entry in failed, the forget() of its known pages in upload_all, and the re-upload that follows are not exercised. Add a test that publishes a GPU write or a source change between stage() and the queue-turn refresh and checks that the item is dropped and the others still upload.
  2. Same-queue ordering only on the title-queue path. The README and the submit_tracked comment promise "states left by earlier submissions on the same queue". In upload_all (title_textures.rs ~2951), the None branch uploads on XCL's own queue, which no title queue submits to. There the refreshed states are the latest published title states, which may belong to lists still in flight on other queues. This problem existed before the PR, but the wording claims more than the code does. Limit the README and comment to the title-queue path, or say that the own-queue path is not ordered.
  3. Retry now re-uploads entries already GPU-written at selection. The test failed_upload_requeues_only_the_selected_ownership (title_textures.rs ~5960) changes entry 1 to gpu_written=true and now expects it to be requeued. The old assertion "GPU-written content must not be overwritten by a retry" now holds only for writes after selection. This matches selection (pending wins over gpu_written), but it reverses a guarantee the old test asserted. Say so in the description, or keep the !gpu_written check in requeue_selections if it was not meant to change.
  4. Default-path cost unmeasured. On every title upload batch, allocator Reset, recording all the copies, Close and ExecuteCommandLists now run inside the title queue's lease (texture_upload.rs ~905), and each batch takes the TEXTURES lock once more to refresh. Another thread submitting to the same queue waits through all of it. The TEXTURES lock is released before recording.
  5. Conflicts with #3791. #3791 (9894873931), also open, changes title_textures.rs. A test merge of both onto origin/main conflicts in that file. One has to be rebased on the other.
  6. No issue link. The description has no "Fixes #N" or "Part of #N". It refers only to an unnamed retail trace.

Nit

  1. README entry is not user-facing. The README line (~411) describes internal upload ordering with no switch and no change users can see. It fits the PR description or a code comment better.
  2. Benign stale drops use up the failure warnings. A stale drop goes into failed and is logged through upload_all's warn (title_textures.rs ~2848), which prints only the first 4 "upload failed" messages. Normal races can use them up and hide real upload failures later. Skip warn for the stale reason, or give it its own counter.
  3. All-stale batch drops the pooled upload buffer. When every staged piece is stale, submit_tracked returns early and the Staged Job is dropped instead of being returned through give_back (texture_upload.rs ~912). Its reusable upload buffer and list are destroyed. Give the job back.
Checked and fine
  • Merges cleanly onto origin/main; git diff --check is clean; 227 added and 55 deleted lines across 3 files
  • Lock order is the queue lease, then TEXTURES, as in publish_submission_effects; refresh_parts releases TEXTURES before upload_all runs
  • Title submissions publish their transitions and GPU writers inside the same queue lease (submit_segment_effects under queue_submit::with), so a refresh on the title-queue path sees all earlier work on that queue
  • record() builds barriers from the remaining pieces only, so a dropped item gets no transitions; the stale indices come out ascending, so binary_search on them is valid
  • upload_revision is bumped on every GPU write, mapping change, source change and published download; replacements are caught by generation and by the known pointer
  • retry_failed now promotes retries under the TEXTURES lock, before pending_res is taken, and retry_ready keeps the early Ready return correct
  • pc_execute re-enters the same queue's lease on the same thread, which is allowed, so the upload's own ExecuteCommandLists does not deadlock
  • No game data and no new dependencies; AI use names the tool and model (OpenAI Codex, GPT-6)
How this was tested
  • Merged onto main 16c2fd08, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 16c2fd08 and on this merge; presents per 2 s at the end: 61 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7386930161 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3790#issuecomment-7386930161). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T17:42:15Z. --- merge-check base: 16c2fd082ae2e96967a2ab553bc2e1032e491f70 head: 67651700045c940eadd0ebf6ef5996f546c7b4a5 merge: clean build: ok tests: 3019 passed, 0 failed, 56 ignored; 28 skipped, the same as on main review: 6 medium, 3 nits (below) performance: 60 s smoke run: 1683 → 1659 frames (98 % of main), peak commit 18505 → 17840 MB, no device removal, no crash title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 238 s there, 0 device removals, 0 crashes, 3.6 presents/s; run with `XCL_SKIP_CS=95cc13288a27a96e` (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590) verdict: not yet: it is a draft, and `PR description` is red; otherwise no blocking finding, the suite passes and the smoke run is clean hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 --- **In short:** The PR records title texture uploads inside the title queue's ordered submission slot ("queue lease"). There it re-reads each destination's current resource states and drops any upload whose texture was replaced, written by the GPU, downloaded or remapped while the CPU filled the staging buffer. The new push adds a per-entry revision counter and moves retries under the texture table lock. The reading found no deadlock and no wrong barrier, and the code is consistent. The stale-drop path is still untested end to end, a retry assertion was reversed, and the conflict with #3791 remains, but nothing blocks merging. #### Medium 1. **Stale-drop path is not tested.** The only new test (staged_texture_upload_uses_the_latest_state_and_current_registration, title_textures.rs ~5456) calls refresh_upload_state on a local Table. Nothing runs submit_tracked (texture_upload.rs ~901) with a stale item: the retain on pieces, the "changed ownership" entry in failed, the forget() of its known pages in upload_all, and the re-upload that follows are not exercised. Add a test that publishes a GPU write or a source change between stage() and the queue-turn refresh and checks that the item is dropped and the others still upload. 2. **Same-queue ordering only on the title-queue path.** The README and the submit_tracked comment promise "states left by earlier submissions on the same queue". In upload_all (title_textures.rs ~2951), the None branch uploads on XCL's own queue, which no title queue submits to. There the refreshed states are the latest published title states, which may belong to lists still in flight on other queues. This problem existed before the PR, but the wording claims more than the code does. Limit the README and comment to the title-queue path, or say that the own-queue path is not ordered. 3. **Retry now re-uploads entries already GPU-written at selection.** The test failed_upload_requeues_only_the_selected_ownership (title_textures.rs ~5960) changes entry 1 to gpu_written=true and now expects it to be requeued. The old assertion "GPU-written content must not be overwritten by a retry" now holds only for writes after selection. This matches selection (pending wins over gpu_written), but it reverses a guarantee the old test asserted. Say so in the description, or keep the !gpu_written check in requeue_selections if it was not meant to change. 4. **Default-path cost unmeasured.** On every title upload batch, allocator Reset, recording all the copies, Close and ExecuteCommandLists now run inside the title queue's lease (texture_upload.rs ~905), and each batch takes the TEXTURES lock once more to refresh. Another thread submitting to the same queue waits through all of it. The TEXTURES lock is released before recording. 5. **Conflicts with #3791.** #3791 (989487393161cace0fb2882baf30a25d39d8d506), also open, changes title_textures.rs. A test merge of both onto origin/main conflicts in that file. One has to be rebased on the other. 6. **No issue link.** The description has no "Fixes #N" or "Part of #N". It refers only to an unnamed retail trace. #### Nit 7. **README entry is not user-facing.** The README line (~411) describes internal upload ordering with no switch and no change users can see. It fits the PR description or a code comment better. 8. **Benign stale drops use up the failure warnings.** A stale drop goes into failed and is logged through upload_all's warn (title_textures.rs ~2848), which prints only the first 4 "upload failed" messages. Normal races can use them up and hide real upload failures later. Skip warn for the stale reason, or give it its own counter. 9. **All-stale batch drops the pooled upload buffer.** When every staged piece is stale, submit_tracked returns early and the Staged Job is dropped instead of being returned through give_back (texture_upload.rs ~912). Its reusable upload buffer and list are destroyed. Give the job back. <details><summary>Checked and fine</summary> - Merges cleanly onto origin/main; git diff --check is clean; 227 added and 55 deleted lines across 3 files - Lock order is the queue lease, then TEXTURES, as in publish_submission_effects; refresh_parts releases TEXTURES before upload_all runs - Title submissions publish their transitions and GPU writers inside the same queue lease (submit_segment_effects under queue_submit::with), so a refresh on the title-queue path sees all earlier work on that queue - record() builds barriers from the remaining pieces only, so a dropped item gets no transitions; the stale indices come out ascending, so binary_search on them is valid - upload_revision is bumped on every GPU write, mapping change, source change and published download; replacements are caught by generation and by the known pointer - retry_failed now promotes retries under the TEXTURES lock, before pending_res is taken, and retry_ready keeps the early Ready return correct - pc_execute re-enters the same queue's lease on the same thread, which is allowed, so the upload's own ExecuteCommandLists does not deadlock - No game data and no new dependencies; AI use names the tool and model (OpenAI Codex, GPT-6) </details> <details><summary>How this was tested</summary> - Merged onto main `16c2fd08`, then `cargo build --workspace` and `cargo test --workspace --no-fail-fast -- --test-threads=4`. - The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar). - `scripts/smoke.ps1`: 60 s of a retail title on main `16c2fd08` and on this merge; presents per 2 s at the end: 61 60 60. - Title run: the release build of this merge launched the retail title with `XCL_RUN_SECONDS=300` and scripted A presses counted from the first frame (`XCL_PRESS_BASE=frame`, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Gevroska commented 2026-12-03 17:42:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-03T17:42:42Z.


@Prime1997 I found one case on 67651700 where an interrupted copy-back leaves two older mip uploads eligible. I ran the revision’s publication and queue-recording functions on Windows and varied how much progress the write callback reported.

Bytes written before return Result on 67651700
0 of 8 The GPU writer stayed pending. Both preselected copies were recorded.
4 of 8 The GPU writer stayed pending. Both copies were still recorded, even though four backing bytes had changed.
8 of 8 Publication completed, the upload revision advanced, and both copies were discarded.

I tried advancing the upload revision as soon as the callback reports partial progress, while keeping the GPU writer pending for retry. That discarded both older copies in the 4-byte case and preserved the zero-byte and complete-write behavior. All nine cases passed across three trials. The fixture injected the write outcomes, so whether the native page writer reports partial progress this way remains open.

Separately, on the earlier da0bf0dc revision, I replayed the selected barriers and copies on my RTX 3080 after a fenced state change on the same queue. All 640 texel bytes across 16 mips matched expectations, including the 400 bytes that should stay untouched.

AI disclosure: OpenAI Codex GPT-6.2 Sol ran the comparisons and wrote the local correction. An independent Codex reviewer reproduced the partial-write results. GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7386941855 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3790#issuecomment-7386941855). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-12-03T17:42:42Z. --- @Prime1997 I found one case on `67651700` where an interrupted copy-back leaves two older mip uploads eligible. I ran the revision’s publication and queue-recording functions on Windows and varied how much progress the write callback reported. | Bytes written before return | Result on `67651700` | |---|---| | 0 of 8 | The GPU writer stayed pending. Both preselected copies were recorded. | | 4 of 8 | The GPU writer stayed pending. Both copies were still recorded, even though four backing bytes had changed. | | 8 of 8 | Publication completed, the upload revision advanced, and both copies were discarded. | I tried advancing the upload revision as soon as the callback reports partial progress, while keeping the GPU writer pending for retry. That discarded both older copies in the 4-byte case and preserved the zero-byte and complete-write behavior. All nine cases passed across three trials. The fixture injected the write outcomes, so whether the native page writer reports partial progress this way remains open. Separately, on the earlier `da0bf0dc` revision, I replayed the selected barriers and copies on my RTX 3080 after a fenced state change on the same queue. All 640 texel bytes across 16 mips matched expectations, including the 400 bytes that should stay untouched. AI disclosure: OpenAI Codex GPT-6.2 Sol ran the comparisons and wrote the local correction. An independent Codex reviewer reproduced the partial-write results. GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting.
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/3790:upstream-pr/3790'
git switch 'upstream-pr/3790'

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/3790'
git switch 'upstream-pr/3790'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3790'
git switch 'upstream-pr/3790'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3790'
git switch 'main'
git merge --squash 'upstream-pr/3790'
git switch 'main'
git merge --ff-only 'upstream-pr/3790'
git switch 'main'
git merge 'upstream-pr/3790'
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!3790
No description provided.