Skip to content

D3D12.X: skip the memory refresh for submits of flush-only lists - #3605

Draft
raylitebull wants to merge 5 commits into
amd-devfrom
capy/d3d12x-skip-the-memory
Draft

raylitebull wants to merge 5 commits into
amd-devfrom
capy/d3d12x-skip-the-memory

Conversation

@raylitebull

@raylitebull raylitebull commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

On AMD, amd-dev is limited by the thread that submits the title's work: ~19-28 title submits a frame at 8.8-11 ms each, 6.4-8.9 ms of it in title_textures::refresh_for (b54c6d9, 9f9a9bc). ReVIctory found that a retail title submits its queue's cache-flush list alone in about a tenth of its 50-60 submits a frame and folds it into the neighbouring submit with a title patch (median 27.8 -> 29.0 fps). This PR does the title-agnostic version: a submit whose lists only flushed and synced skips the parts of the refresh that bring memory up to date for the GPU. Behind XCL_FLUSH_SUBMIT_SKIP=1, off by default.

The idea and evidence come from ReVIctory (https://github.com/ReTerryDavis/ReVIctory, GPL-3.0-or-later), crates/victory-loader/src/submit_merge.rs and docs/title-patch-candidates.md §2. No code was ported.

What is in it

  • title_list: the console list object keeps F_ONLY_SYNCS, set when the list is made (wrap) or Reset and cleared by the forwarder of every slot outside SYNC_SLOTS. SYNC_SLOTS is ID3D12Object's methods (XAudio2: real Opus decoder via Windows MSOpusDecoder MFT #3–Olympus: harden media and package ingestion #8), the markers (XAsync: a failing Begin fails the call, and E_PENDING does not complete #56–VFS: moves through MoveFileWithProgressW are redirected too #58), FlushPipelineX (Wave64 console programs on GPUs with 32-lane waves only (NVIDIA) #67) and FlushGpuCacheRangeX / FlushShaderCacheRangeX (#131 / Add synthetic Cargo benchmark suite #132): slots whose XCL handler records a UAV barrier at most. ResourceBarrier, Compute dispatches: a shader takes no more arguments from user SGPRs than it has (XboxBvhBuilder builds empty BLAS / TLAS) #146 and newer-layout Fix D3D12 frame and texture handling #69 are not on it. only_syncs(list) is false for anything that is not a console list object. The byte is kept with the switch off too (one byte store a forwarded list call), so the log can show how many submits would qualify before the skip is tried.
  • title_textures::refresh_for: for a submit with at least one list and every list only_syncs, with the switch on, there is no look and no sparse or texture uploads. The queue still waits for the texture page mappings (vram::before_execute) and XCL's own uploads, under the refresh lock as before, and owes the refresh. What the CPU wrote and committed goes up at the next refresh.
  • An owed refresh is paid at the title's next queue call that makes the queue's work visible to others or touches memory (real::queue_dispatch: Signal, SignalX, PresentX, CopyPageMappingsBatchX, and methods not modelled), as a full refresh (refresh_once, under the refresh lock, its look sampled for the memory report), and counted on its own in the submit cost line. It is not paid at a Wait or a query: they publish nothing, and the queue's next ExecuteCommandLists refreshes anyway, so paying there would run two refreshes where there was one. While a queue owes one, other queues' texture uploads go to XCL's own queue, which the owed refresh waits for, so work on other queues that waits for a fence the owing queue signals finds what the CPU wrote before the skipped submit. That is the path compute queues' uploads already take; they cannot stay on the refreshing queue, because the owing queue cannot wait for it: the refreshing queue may itself wait for the owing queue's fence. Like a compute queue's, those uploads are not ordered after the refreshing queue's earlier work still on the GPU, so with the switch on an upload can rewrite a texture that work still reads. A queue the title releases owes nothing more. The owed refresh checks the debt again under the refresh lock, so it runs once. XCL's own signals on the title's behalf (list_x::signal_write64_pairs) follow only submits whose lists wrote memory, which refreshed. With the switch off nothing of this is set and nothing new locks.
  • submit_cost: the average line counts these submits ("N of them only flushed or synced: …") whether the switch is on or not, and the owed refreshes paid at a queue call with their time (also in the lock wait, refresh and whole: the per-ExecuteCommandLists averages include the refreshes the submits left to a later queue call).
  • Unit tests: the allowlist through the real vtable (new list, flushes, a marker, Close, Dispatch, failed and successful Reset, ResourceBarrier, Fix D3D12 frame and texture handling #69, Compute dispatches: a shader takes no more arguments from user SGPRs than it has (XboxBvhBuilder builds empty BLAS / TLAS) #146, a PC list), and the submit decision (all, mixed, none, not console list objects); a GPU test of the skip branch (refresh_for_as): the queue owes the refresh, other queues' uploads go to XCL's own queue meanwhile, another queue's refresh does not pay it, a later queue call, the queue's release or its next full refresh does, and with the switch off the same submit has the full refresh; a test of which queue methods pay (real::pays_owed_refresh).

Tested

  • Linux, cargo check --workspace --all-targets --target x86_64-pc-windows-gnu (the Setup's typecheck), run again after each round of review fixes (deac669, 36d8b36, d6175c8, the latest commit): passes, no warnings in the changed code.
  • By Foniass, not by me (test report on this PR, fb0f23b merged onto amd-dev 41aa60c, RTX 5070 Ti, Ryzen 7 7800X3D, Windows 11 26300): cargo build --workspace ok; cargo test --workspace --no-fail-fast -- --test-threads=4: 2963 passed, 9 failed, 49 ignored, 28 SKIPPED, the 9 failures the same as on amd-dev alone on that card; a 60 s smoke run of a retail title with the switch off: 1671 -> 1664 frames shown, no device removal, no crash. That run predates deac669 and did not exercise XCL_FLUSH_SUBMIT_SKIP=1.
  • By Foniass, not by me (second test report on this PR, deac669 merged onto amd-dev 41aa60c, same RTX 5070 Ti machine): cargo build --workspace ok; cargo test --workspace --no-fail-fast -- --test-threads=4: 2964 passed, 9 failed, 49 ignored, 28 SKIPPED, the 9 failures the same as on amd-dev alone, the new GPU test passes; 60 s smoke runs of a retail title clean with the switch off (1671 -> 1657 frames shown) and with XCL_FLUSH_SUBMIT_SKIP=1 (1673 frames), no device removal, no crash. That run predates 36d8b36, and its log did not show how many submits were skipped.
  • By Foniass, not by me (third test report on this PR, 36d8b36 merged onto amd-dev 41aa60c, same machine): build ok; 2964 passed, the same 9 failures as on amd-dev, the GPU test passes on a GPU; 60 s smoke runs clean with the switch off (1671 -> 1670 frames shown) and on (1669 frames). That run predates d6175c8.
  • By Foniass, not by me (fourth test report on this PR, d6175c8 merged onto amd-dev 41aa60c, same machine): build ok; 2965 passed, the same 9 failures as on amd-dev, the GPU test passes; 60 s smoke runs clean with the switch off (1671 -> 1679 frames shown) and on (1673 frames).

Not tested

  • Reading the count on hardware: xcl.log gets the line "submit cost, average of 1024 ExecuteCommandLists: … (… submits/s, N of them only flushed or synced: …; M owed refreshes at a queue call, X ms in all, in the refresh)" at INFO, the default level, with no switch needed. It is written every 1,024 title ExecuteCommandLists, starting at the 2,048th (the first 1,024 only set the baseline), and each line covers only the last 1,024. At ~20-30 submits a frame and 2-4 fps on AMD that is the first line after roughly 20-50 s of submitting; run a minute or more and add up N over the lines. N is counted with the switch off too, so a run without XCL_FLUSH_SUBMIT_SKIP=1 already shows whether the title has flush-only submits.
  • Not built for Windows or tested by me. XCL_FLUSH_SUBMIT_SKIP=1 has been run only in Foniass's 60 s smoke runs on NVIDIA (clean), not on AMD, and no run has shown how many submits were skipped, so its effect on the submitting thread is unmeasured. The smoke blocks under Regression run follow after a Windows run.

Regression run
(follows after a Windows run)

AI use
Capy (Claude Opus 5.5) read the submit path and the list hooks, wrote the change and the tests, and ran the typecheck.

Open in Capy

A retail title submits its queue's cache-flush list alone in about a
tenth of its 50-60 submits a frame (a list recorded once at start: a
sync with wait flags 0x700000 and a cache operation 0xc3c0/0xc380,
FlushShaderCacheRangeX / FlushGpuCacheRangeX here). Every title submit
pays title_textures::refresh_for, 6.4-8.9 ms of the 8.8-11 ms a submit
on amd-dev (look, sparse lock, textures, scan, upload), though such a
list reads and writes no memory. ReVIctory folds that list into the
neighbouring submit with a title patch (submit_merge.rs; median 27.8 ->
29.0 fps, submitting thread 32-33 -> 29-30 ms a frame).

Do it for any title: the console list object keeps a byte that is set
when the list is made or Reset and cleared by the forwarder of every
slot outside an allowlist (object methods, markers, FlushPipelineX,
FlushGpuCacheRangeX / FlushShaderCacheRangeX). With
XCL_FLUSH_SUBMIT_SKIP=1 a submit whose every list kept it goes without
the look and the sparse and texture uploads; the queue still waits for
the page mappings and XCL's uploads made so far, and owes the refresh
until its next one, which a title Signal or SignalX on it runs first.
The submit cost line counts these submits whether the switch is on or
not.

Not measured yet: off by default until it is run on hardware.

Assisted-by: Capy (Claude Opus 5.5)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60c
head: fb0f23b
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2963 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60c alone on this card, so none is from this PR)
review: read the whole diff (+170/-10) against amd-dev. The PR adds an opt-in switch, XCL_FLUSH_SUBMIT_SKIP=1, off by default: when every list in a submit only called allowlisted slots since it was made or Reset, the submit skips the look and the uploads, and the queue owes the refresh until its next Signal/SignalX. The classification is sound, but the deferred refresh is not paid everywhere it used to land. Findings: (1) The owed refresh can land on another queue. refresh_without_memory (title_textures.rs ~1952) leaves the dirty pages in place. If another queue B submits before queue A's Signal, B's full refresh takes those pages and uploads them on B (upload_target picks B when it is a DIRECT queue). before_title_signal (~1944) then finds nothing dirty on A, and wait_for_own_uploads waits only for XCL's own upload fence, not for B. So work that waits on A's fence is not ordered after those uploads, where before the PR the skipped submit's refresh put them on A ahead of the Signal. The same race already existed when no submit on A came between, so this widens an existing window; the impact is unverified. (2) Only Signal/SignalX pay what is owed. PresentX (present_x -> present_now, which copies the planes on the title's queue) and CopyPageMappingsBatchX (#29) on an owing queue run without the refresh, so a plane the CPU wrote, followed by a flush-only submit and PresentX, would show stale contents until the next refresh (unverified whether any title presents a CPU-written plane). (3) No tests for the skip itself. The classifier test has good negative cases through the real thunks (Dispatch, ResourceBarrier, #69, #146, a failed Reset, a PC list), but syncs_only is tested only through a closure, and nothing tests refresh_for's skip branch (~2026), the OWED set and its removal in refresh_once (~2629), the owed refresh at Signal/SignalX (real.rs ~12742 / ~12914), or that the full refresh stays with the switch off. (4) Skewed measurement. The Signal-time refresh goes through refresh_for, so its time is added to submit_cost's per-ExecuteCommandLists averages and it counts as a submit in the look-skip counter. With the usual pattern (a flush list submitted alone right before a Signal) the cost just moves to the Signal, and these numbers would hide that. The fps gain is unmeasured. (5) Wrong "Known edge" in the description, and a lock on every Signal. flush_pipeline_x and flush_cache_range_x go flush_barrier -> emit_uav_barrier_pc -> the original PC ResourceBarrier with no format_alias call (that only happens in uav_barrier_x and resource_barrier_x), so the edge it describes can't happen. Separately, before_title_signal takes the OWED mutex on every title Signal/SignalX even with the switch off. Fine: flush-only is decided by an allowlist of slots (3-8, 56-58, 67, 131, 132) and every other forwarder clears the byte, including the traced variant and the #139 forwarder. The handlers for the allowed slots record at most a global UAV barrier, so nothing that reads title memory (copies, clears, resolves, queries, predication, indirect args, memory writes and waits) can be classed as flush-only. The mov byte [rcx+0x2108], 0 encoding is right, Reset sets the byte only on success, KickoffX passes the PC list so it's never skipped, and the skip keeps vram::before_execute and wait_for_own_uploads.
performance: 60 s smoke of a retail title, amd-dev 41aa60c vs this merge (fb0f23b): 1671 -> 1664 frames shown (99 %; last presents per 2 s: 60 61 60), peak commit 16722 -> 16681 MB, 0 device removals, 0 crashes. Only the default path (switch off) was run.
assessment: merges cleanly into amd-dev, builds, adds no test failure (the failing ones fail on amd-dev alone on this NVIDIA card), and with the switch off (the default) a 60 s smoke run shows no change. The run doesn't exercise XCL_FLUSH_SUBMIT_SKIP=1, and on NVIDIA it can't show the AMD submit-thread gain; the review findings stand, mainly the owed refresh landing on another queue and PresentX not paying it
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

Review of the flush-only submit skip (#3605): the refresh a skipped
submit owes was paid only at Signal / SignalX, so PresentX and
CopyPageMappingsBatchX on the owing queue ran without it; another
queue's refresh could take the owed pages and upload the textures on
that queue, which the owing queue never waits for; and the owed refresh
went through refresh_for, so its time counted as submit cost.

Pay it in queue_dispatch before Signal, SignalX, PresentX,
CopyPageMappingsBatchX and methods not modelled, through the plain
refresh, counted on its own in the submit cost line. Not at a Wait or
a query: they publish nothing and the queue's next ExecuteCommandLists
refreshes anyway, so paying there would run two refreshes for one.
While a queue owes one, other queues' texture uploads go to XCL's own
queue, which every queue's refresh waits for. Nothing is locked with
the switch off. A GPU test covers the debt and the full refresh with
the switch off.

Assisted-by: Capy (Claude Opus 5.5)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60c
head: deac669
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2964 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60c alone on this card, so none is from this PR)
review: follow-up on deac669 (+82/-15 since fb0f23b, the head of my test report above). The commit moves the owed refresh out of Signal/SignalX into real::queue_dispatch (real.rs ~12738), before every queue method except Wait, the three queries (older #16-#18) and the newer layout's ExecuteCommandListsX, through the plain refresh behind a flush_submit_skip() check (before_title_queue_call, title_textures.rs ~1948). While any queue owes a refresh, other queues' refreshes upload on XCL's own queue (upload_target, ~2827). It also adds an owed count and time to submit_cost, and one GPU test. (1) Fixed for the case I raised: B's refresh now sees A in OWED and uploads on XCL's queue, and A's owed refresh always reaches wait_for_own_uploads(A) (refresh_once ~2639 waits either way), so A's Signal is ordered after those uploads; OWED changes only under REFRESH. (2) Fixed: PresentX (older #30) and CopyPageMappingsBatchX (#29, and the _ arm when page mappings are off) now pay before they run, with no double refresh; Signal's refresh runs once, outside the retry loop and the queue turn. (3) Partly fixed: gpu_a_refresh_left_out_is_owed_until_the_queue_has_one (~6097) covers the insert in refresh_without_memory, the removal in refresh_once, that another queue's refresh doesn't pay it, and the full refresh with the switch off, but not refresh_for's skip branch with the switch on (the switch is a process-wide OnceLock and the test returns when it is set), which queue_dispatch slots pay, or the redirect to XCL's queue. (4) Partly fixed: the owed refresh no longer adds to REFRESH or the look-skip counter and has its own count and time (submit_cost.rs ~76), but refresh_parts still adds its recheck/ranges/textures stages (~2658, ~2670, ~2940), the sparse totals and the texture counters into the same 1024-ExecuteCommandLists window, so rest (submit_cost.rs ~200) is understated and can go negative. (5) The "Known edge" text is gone and Signal/SignalX no longer take OWED with the switch off, but refresh_once (~2640) still locks OWED on every refresh, so the description's new "With the switch off nothing of this runs or takes a lock" isn't true. New: (6) A released queue stays owed. forget_queue (title_textures.rs ~3361) doesn't remove a released queue from OWED. If a title releases a queue whose last submit was skipped before a Signal/Present there, OWED stays non-empty for the rest of the run: every later DIRECT-queue upload then goes to XCL's queue, every title queue waits for it, and a new queue at the same address pays a refresh it doesn't owe. (7) DIRECT-queue uploads change path. They now take the XCL-queue path, used before only for compute and copy queues, which isn't ordered after the title's earlier work on the queue that refreshes; with the switch on this applies to all queues whenever any queue owes, and the PR doesn't mention it. On the default path the only addition is an extra is_fence read lock on each queue Wait (the gate at ~12739 evaluates it before the switch check). Fine: lock order (OWED is a leaf, never held across REFRESH), the Wait/query exclusions, no double refresh after a paid Signal, stop_unless_prepared keeps the old failure handling, and the switch-off upload target short-circuits without taking the lock.
performance: 60 s smoke of a retail title, amd-dev 41aa60c vs this merge (deac669): 1671 -> 1657 frames shown (99 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 17695 MB, 0 device removals, 0 crashes. With XCL_FLUSH_SUBMIT_SKIP=1: 1673 frames, peak commit 16825 MB, 0 device removals, 0 crashes; the log doesn't say how many submits were skipped, so it's not known whether this title has flush-only submits.
assessment: on the new head, merges cleanly into amd-dev, builds, adds no test failure (the new GPU test passes), and both smoke runs are clean, with the switch off and on. (1) and (2) from my first review are fixed; still open are the released queue staying owed (6), the change of upload path for DIRECT queues with the switch on (7), and the test and measurement gaps (3), (4)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

…kip off

Second review of #3605: a queue released while it owed a refresh stayed
in OWED, so every later direct-queue upload went to XCL's own queue for
the rest of the run; refresh_once took OWED's lock on every refresh and
a Wait looked the fence up with XCL_FLUSH_SUBMIT_SKIP off; and the owed
refresh's parts went into the submit cost stages without its own time,
so "rest" could go negative.

forget_queue drops the queue from OWED. An OWING flag mirrors OWED
being non-empty and is read before its lock, never set with the switch
off; queue_dispatch checks the switch first. The owed refresh counts in
the refresh stage too. The GPU test now runs the skip branch itself
(refresh_for_as) and the payment at a queue call. The doc says why the
uploads go to XCL's own queue while one is owed: the owing queue cannot
wait for the refreshing one, which may wait for its fence.

Assisted-by: Capy (Claude Opus 5.5)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60c
head: 36d8b36
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2964 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60c alone on this card, so none is from this PR)
review: follow-up on 36d8b36 (+58/-31 since deac669, the head of my test report above). The commit adds an OWING flag mirroring OWED being non-empty, written only under OWED's lock (owe, title_textures.rs ~1942) and never set with the switch off; refresh_once (~2661), forget_queue (~3389), owes_refresh (~1953) and the upload_target filter (~2850) read it before taking the lock; forget_queue drops a released queue from OWED; queue_dispatch checks the switch first; the owed refresh's time goes into the refresh stage; and the GPU test drives the skip branch through a new refresh_for_as(…, skip) (~2037). (3) Partly fixed: the skip branch, another queue's refresh not paying, payment at before_title_queue_call and by the next full refresh are now tested whatever the env says (~6123); still untested are which queue_dispatch slots pay (real.rs ~12739), the redirect to XCL's queue while one is owed (~2850), and the removal in forget_queue. (4) Partly fixed: the owed refresh's time now goes into REFRESH (submit_cost.rs ~81), so rest no longer goes negative, but that time isn't in TOTAL or CALL (it runs outside ExecuteCommandLists), so "in all = lock + refresh + driver + after" no longer adds up and outside_part (CALL − LOCK − REFRESH, ~89) is understated or clamped to 0; its wait for the refresh lock (taken inside refresh(), ~1847) also lands in refresh/rest, not in "refresh lock wait". (5) Fixed: with the switch off nothing sets OWING, so refresh_once takes no lock. (6) Fixed: forget_queue removes the queue, and it runs from the retirement worker after the queue's completion mark and before the registry owner is dropped (present.rs ~692-726), so a new queue can't reuse the address while the stale entry is there. Left open: if retirement fails (fail_queue_retirement, present.rs ~748-760) the queue is pinned and forget_queue never runs, so an owing queue keeps OWING set and DIRECT uploads go to XCL's queue for the rest of the run. (7) Partly fixed: the doc (~1924-1930) and the description now give the reason (the owing queue can't wait for the refreshing queue, which may wait on its fence, and compute queues' uploads already take this path), but neither says that uploads on XCL's queue aren't ordered after the refreshing DIRECT queue's earlier, still-running work, so with the switch on an upload can rewrite a texture that work still reads. Wait lock: fixed with the switch off (flush_submit_skip() first, real.rs ~12739); with it on, each Wait still takes a second FENCES read lock for a lookup done a few lines up (~12728 / ~12731). New: (8) before_title_queue_call (~1968) checks owes_refresh before refresh() takes the refresh lock, so an ExecuteCommandLists on the same queue on another thread paying in between leads to a second full refresh counted as owed (time only). (9) The test sets the process-wide OWING with the switch off; during that window, GPU tests outside this module's TEST_LOCK that refresh (e.g. sparse.rs ~9441) send their uploads to XCL's queue, and a failed assertion partway leaves q in OWED for the rest of the test binary. (10) The description's "Not tested" says XCL_FLUSH_SUBMIT_SKIP=1 wasn't run in a game by anyone, while Tested lists my 60 s smoke run with the switch on. Fine: OWED is a leaf lock with no other lock taken under it; its inserts and refresh_once's unlocked read of OWING both run under the refresh lock, so that read can't miss an owing queue; only a title submitting on an already released queue could insert after forget_queue.
performance: 60 s smoke of a retail title, amd-dev 41aa60c vs this merge (36d8b36): 1671 -> 1670 frames shown (99 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16667 MB, 0 device removals, 0 crashes. With XCL_FLUSH_SUBMIT_SKIP=1: 1669 frames, peak commit 16453 MB, 0 device removals, 0 crashes.
assessment: on the new head, merges cleanly into amd-dev, builds, adds no test failure, and the rewritten GPU test gpu_a_refresh_left_out_is_owed_until_the_queue_has_one passes (first run on a GPU); both smoke runs are clean with the switch off and on. (5) and (6) are fixed; still open are the pinned-queue case of (6), the ordering of DIRECT uploads on XCL's queue (7), the measurement gaps (4) and the smaller new points (8)-(10)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

Third review of #3605: a queue released while it owed a refresh kept it
when its retirement failed (forget_queue never runs for a pinned queue),
so DIRECT uploads went to XCL's own queue for the rest of the run; the
owed refresh checked the debt before the refresh lock, so a submit on
the same queue on another thread could pay it in between and the
refresh ran twice; and its time was in the refresh stage but not in the
whole, so "in all" no longer added up.

The debt goes when the title releases the queue (retire_released_queue).
The owed refresh checks it again under the refresh lock and counts its
lock wait, refresh and whole in the submit stages. Which queue methods
pay is a function of its own with a test; the GPU test also checks the
upload target while a queue owes and keeps nothing owed if it fails.
The doc says that those uploads are not ordered after the refreshing
queue's earlier work, as a compute queue's are not.

Assisted-by: Capy (Claude Opus 5.5)
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60c
head: d6175c8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2965 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60c alone on this card, so none is from this PR)
review: follow-up on d6175c8 (+81/-17 since 36d8b36, the head of my test report above). The commit re-checks the debt under REFRESH in before_title_queue_call and calls refresh_once directly, adds the owed refresh's lock wait and refresh time to the lock / refresh / call / total sums, and clears the debt at the title's Release through forget_owed in retire_released_queue; smaller changes move the slot condition into pays_owed_refresh with a unit test, move the OWING check into upload_target, document the upload ordering gap, and add a drop guard to the GPU test. (3) Partly fixed: the slot choice has a unit test (real.rs ~12849 / ~12860) and the redirect to XCL's queue is asserted through upload_target (title_textures.rs ~6166), but the unit test copies the predicate's own expression and nothing goes through queue_dispatch's numbering (e.g. the newer layout's Wait at #17 becoming older #15); the release path is covered only by calling forget_owed directly (~6173), not through q_release -> retire_released_queue. (4) Fixed: owed_refresh (submit_cost.rs ~79-86) adds the wait to LOCK, the refresh to REFRESH and both to CALL and TOTAL, so "in all" adds up; left: the log line (~197) still says the owed time is "in the refresh" though its wait is in the lock wait, and a lock wait that ends with the debt already paid (title_textures.rs ~1979) is counted nowhere. (6) Fixed: forget_owed runs right after begin_queue_retirement succeeds (present.rs ~744), so the debt is cleared whether retirement is later pinned or completes; the n == 0 Release path can't hold a debt, since an owing queue is always registered by note_execute in the same ExecuteCommandLists (real.rs ~13188). (7) Documented in flush_submit_skip's doc (~1929-1931) and the description; the ordering gap itself remains, as it does for compute queues. Wait lock: still open; with the switch on, each older-#15 Wait now takes three FENCES read locks (real.rs ~12726 / ~12730, pays_owed_refresh, and the match guard ~12776). (8) Fixed: the second owes_refresh under the lock (~1977-1980) makes a call return when another ExecuteCommandLists paid in between. (9) Partly fixed: the Paid guard (~6156-6162) clears q on a failed assertion, but OWING is still set process-wide with the switch off and TEST_LOCK is local to title_textures (~6396), so the refresh in sparse.rs ~9441 can send its uploads to XCL's queue during that window. (10) Fixed: Tested and Not tested now agree. New: (11) the owed refresh no longer goes through refresh(), which recorded a note_look_sample when memory_report is on; refresh_once(queue, true, None) (~1981) leaves its looks out of that report, and the description's "through the plain refresh" is out of date. (12) TOTAL now includes owed time spent in Signal, SignalX or PresentX while N counts only ExecuteCommandLists, so the "average of 1024 ExecuteCommandLists" rises with time not spent in them. Fine: the order between REFRESH and OWED (OWED is only taken inside REFRESH or alone), clearing the debt before quiesce_queue, and the OWING check in upload_target, whose only caller is refresh_parts.
performance: 60 s smoke of a retail title, amd-dev 41aa60c vs this merge (d6175c8): 1671 -> 1679 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 17164 MB, 0 device removals, 0 crashes. With XCL_FLUSH_SUBMIT_SKIP=1: 1673 frames, peak commit 16562 MB, 0 device removals, 0 crashes. The suite took three runs: the first two lost the lib test binary to this machine's known intermittent aborts (the uma_driver coherent window, then the driver crash in create_device_sets_dred_first), not to this PR; the smoke runs are from the first.
assessment: on the new head, merges cleanly into amd-dev, builds, adds no test failure, and gpu_a_refresh_left_out_is_owed_until_the_queue_has_one passes; both smoke runs are clean with the switch off and on. (4), (6), (8) and (10) are fixed; still open are the upload ordering gap (7, now documented), the third FENCES lock per Wait with the switch on, the test gaps (3), (9) and the small new points (11), (12)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

Fourth review of #3605: the owed refresh had left refresh() for
refresh_once, so with the memory report on its look was no longer
sampled; and the submit cost line said its time was in the refresh
stage, though its lock wait is in the lock wait and the whole is in the
total of the ExecuteCommandLists averages.

Sample its look as refresh() does. The module doc says that a refresh a
submit left out counts in the stages as the submit's own, and the line
says the owed time is in the stages before it.

Assisted-by: Capy (Claude Opus 5.5)
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 75b71bf, since d6175c8, diff read, not a merge-check; draft):

  • (11) fixed. before_title_queue_call (title_textures.rs ~1981-1986) now takes a LookSample when memory_report is on and passes it to note_look_sample with the same (active, wait) arguments refresh_for uses (~2096), so the owed refresh's looks are back in the memory report.
  • (12) answered in words. submit_cost.rs's module doc and log line now say the owed refresh counts "in the stages before", as the submit's own. The averages still divide by ExecuteCommandLists only, so a title that pays mostly at Signal / PresentX will show a higher per-submit cost than its submits really take; that's now stated rather than hidden, which is fine for a diagnostic.
  • Not rerun on the GPU: the change only touches diagnostics (the memory-report sample and a log string), and the run on d6175c8 in my report above covers the rest. Still open from that report: the third FENCES read lock per Wait with the switch on, the upload ordering gap (documented), and the test gaps (3), (9).

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants