GPU: a present waits for the previous frame's submissions, not its own #1828

Closed
github-bot wants to merge 2 commits from gh-pr/1828/head into gh-pr/1828/base
Owner

@⁠Jitheswar on GitHub · 2026-11-24 23:05 UTC · original
claude/595-present-frame-lag → main · +2195 −306 · 15 files · 2 commits · closed without merging

Grand Theft Auto VI submits from one thread: for each batch it calls
ExecuteX, PresentX and Signal, and only then gives its ring slots back
to the producers its main thread waits on (#1118). With submissions
asynchronous, Host::present still drained every submission after
Present, so that thread waited for the frame's whole GPU time inside
PresentX. The title waits for its fences, not for the present, so the
shortcut's condition holds: a present now finishes the previous
frame's submissions (and its copy, whose list it reuses) before it
records this frame's, and leaves this frame's running. ResizeBuffers
still drains; a saved capture settles its frame before reading it back.
The copy list now holds the presented texture, since the title may
release it while the copy still runs.

Diagnostics: the black-frame probe of a frame is read at the next
present, once that frame's work has finished, and reported with that
frame's own number, resource and draws.

Co-Authored-By: Claude Opus 5.5 [email protected]

**@⁠Jitheswar** on GitHub · 2026-11-24 23:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1828) `claude/595-present-frame-lag` → `main` · +2195 −306 · 15 files · 2 commits · closed without merging Grand Theft Auto VI submits from one thread: for each batch it calls ExecuteX, PresentX and Signal, and only then gives its ring slots back to the producers its main thread waits on (#1118). With submissions asynchronous, `Host::present` still drained every submission after `Present`, so that thread waited for the frame's whole GPU time inside PresentX. The title waits for its fences, not for the present, so the shortcut's condition holds: a present now finishes the previous frame's submissions (and its copy, whose list it reuses) before it records this frame's, and leaves this frame's running. ResizeBuffers still drains; a saved capture settles its frame before reading it back. The copy list now holds the presented texture, since the title may release it while the copy still runs. Diagnostics: the black-frame probe of a frame is read at the next present, once that frame's work has finished, and reported with that frame's own number, resource and draws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Submissions are no longer waited for: each signals the next host fence
value and joins a timeline of up to 16 in flight, finished in order (copy
back, then bottom-of-pipe writes, then title fence signals) by a finisher
thread or whichever thread first needs one. Allocators, preludes, scratch,
kept objects, twins, dynamic descriptor leases and retired heap resources
are released behind their submission's fence. A step touching title memory,
host copies or texture staging waits only for in-flight submissions that
write (or read) it.

Rebased onto the page table, bindless heap views, twins and change journal:
a list's after-run work and missed-memory checks move into the pending
submission; bindless texture uploads, view heap refreshes and page table
refreshes wait for in-flight writers like other steps, a page table is
rewritten only with no reader in flight, and a page table user counts as
writing every copy it names.

A list named again in one submission gets its own prelude, and what its
steps write into the list's own memory (upload memory, scratch, budget
word) goes into an upload buffer of the submission that the repeat's
prelude copies in on the GPU, so each run reads its own data with no CPU
wait. List memory is a CPU-visible custom heap the GPU can copy into.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Grand Theft Auto VI submits from one thread: for each batch it calls
ExecuteX, PresentX and Signal, and only then gives its ring slots back
to the producers its main thread waits on (#1118). With submissions
asynchronous, `Host::present` still drained every submission after
`Present`, so that thread waited for the frame's whole GPU time inside
PresentX. The title waits for its fences, not for the present, so the
shortcut's condition holds: a present now finishes the previous
frame's submissions (and its copy, whose list it reuses) before it
records this frame's, and leaves this frame's running. ResizeBuffers
still drains; a saved capture settles its frame before reading it back.
The copy list now holds the presented texture, since the title may
release it while the copy still runs.

Diagnostics: the black-frame probe of a frame is read at the next
present, once that frame's work has finished, and reported with that
frame's own number, resource and draws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:45:54 +00:00
github-bot closed this pull request 2026-11-26 04:45:54 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 23:06 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-24 23:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1828#issuecomment-7147017410) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-25 00:28 UTC · original

Ran this on AMD hardware. One of the PR's own tests fails there; I found why and have a small fix, tested on the same card.

Setup: main 70564ae0 + this PR (dfac3b4, 3a85ae5; merges cleanly). RX 6750 XT (RDNA2, driver 32.0.21045.29003), Windows 11, Rust 1.98.1 MSVC.

What fails. host::submissions::a_repeated_list_reads_its_own_upload_memory fails 10 of 11 runs on hardware, always with left: [0x00000000, 0x22222222]. It passes on WARP (--features diagnostics, VICTORY_D3D12_WARP=1). The other 9 new tests pass.

Narrowing it down. I ran a print-only diagnostic with the test's lists and out pre-filled with 0xEE:

  • In [list, between, list], between's copy never lands: out[0] stays 0xEEEEEEEE.
    • The same happens with the copies 64 or 128 bytes apart, in a 64 KiB buffer, and with between writing into a buffer of its own.
  • [list, between] alone, and [list, between, third] with a different third list, are fine.
  • A GPU-side queue.Wait on the previous group's fence before the second ExecuteCommandLists doesn't help, and neither does a global UAV barrier at the start of the repeat's prelude.
  • With the D3D12 debug layer on, it mostly passes. The debug layer changes timing.

So it isn't a memory or cache problem. The lists before the cut don't run when the same list is submitted again in the next ExecuteCommandLists while the first group is still pending.

Why. The ExecuteCommandLists docs say "the driver is free to patch the submitted command lists". They make it the application's job to ensure the GPU isn't still reading any of them from a previous execution. The repeat resubmits list while its first execution is pending.

My best explanation, which I haven't verified inside the driver: AMD chains the lists of one call by patching their ends. Resubmitting list re-patches it before the GPU has read the first group, so between, which list chained to, is skipped. That would also explain why only a CPU-side wait helps: the patching happens at submission, on the CPU.

Fix. Before a later group (the cut a repeat makes), wait on the CPU for the previous group's fence. Only submissions that name a list twice wait; every other submission stays asynchronous. The two-preludes test held the first group behind a gate and asserted that nothing waits, so with the fix it can't finish. It now runs without the gate and checks the same things: the repeat makes its own prelude (counted from the spares pool once it has run), and the final texture state is COPY_SOURCE.

Results with the fix, same card:

  • a_repeated_list_reads_its_own_upload_memory: 10/10.
  • victory-gpu, whole suite: 88/88 twice. The third run failed only draw::tests::root_views_reach_their_copy_and_read_zeros_past_it, main's intermittent test, which fails on main alone too.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
Patch on top of this PR (host.rs)
--- a/crates/victory-gpu/src/host.rs
+++ b/crates/victory-gpu/src/host.rs
@@ -1057,6 +1057,16 @@
             let started = std::time::Instant::now();
             #[cfg(feature = "diagnostics")]
             crate::resource::life::note(0, crate::resource::life::SUBMITTED, *submitted, 0);
+            // A later group starts with a list the earlier one names (a
+            // repeat). The driver may patch submitted lists, and the GPU must
+            // not be reading one from a previous execution when it is
+            // submitted again (`ExecuteCommandLists`): resubmitted while the
+            // earlier group was pending, the lists before the cut never ran
+            // on an RX 6750 XT. A GPU-side wait is not enough, the patching
+            // happens at submission.
+            if i > 0 {
+                self.wait_gpu(*submitted - 1, true);
+            }
             // SAFETY: closed lists, not running (waited for above); our fence.
             let signalled = unsafe {
                 #[cfg(test)]
@@ -3639,8 +3649,9 @@
     }
 
     /// A submission naming one list twice: the repeat's prelude records into
-    /// its own allocator and list while the first is still pending, so both
-    /// run with their own barriers, and nothing waits on the CPU.
+    /// its own allocator and list, so both runs get their own barriers. The
+    /// repeat's group is submitted once the first has run (a list must not
+    /// be resubmitted while the GPU may still read it), so no gate here.
     #[test]
     fn a_list_named_twice_in_a_submission_has_two_preludes() {
         use std::sync::atomic::Ordering;
@@ -3680,20 +3691,15 @@
             )]);
         }
         list.close();
-        let gate = Gate::new(host);
         // COMMON -> RENDER_TARGET before the first run, COPY_SOURCE ->
         // RENDER_TARGET before the second: two different barriers.
-        host.execute_gated(&[&list, &list], &gate.0);
-        assert!(list.running());
-        let mut spares = 0;
-        host.timeline.each_work(|w| {
-            if w.lists.iter().any(|l| std::ptr::eq(l.0, &list)) {
-                spares += w.preludes.len();
-            }
-        });
-        assert_eq!(spares, 1, "the repeat records into its own prelude");
-        gate.release();
+        // With no spares, the repeat makes its own prelude, which goes to
+        // the spares once it has run.
+        let kept = std::mem::take(&mut *super::pool(&super::SPARE_PRELUDES));
+        host.execute(&[&list, &list]);
         host.drain();
+        let spares = std::mem::replace(&mut *super::pool(&super::SPARE_PRELUDES), kept).len();
+        assert_eq!(spares, 1, "the repeat records into its own prelude");
         let copy = crate::resource::host_copy(tex).unwrap();
         assert_eq!(copy.state.load(Ordering::Relaxed), 0x800);
         // SAFETY: a plain query.

Unit tests only, no game files. AI-assisted (Claude found the cause and wrote the fix; I ran everything on my machine).

**@⁠wwwwwwww3333333** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1828#issuecomment-7148549704) Ran this on AMD hardware. One of the PR's own tests fails there; I found why and have a small fix, tested on the same card. **Setup:** main 70564ae0 + this PR (dfac3b4, 3a85ae5; merges cleanly). RX 6750 XT (RDNA2, driver 32.0.21045.29003), Windows 11, Rust 1.98.1 MSVC. **What fails.** `host::submissions::a_repeated_list_reads_its_own_upload_memory` fails 10 of 11 runs on hardware, always with `left: [0x00000000, 0x22222222]`. It passes on WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`). The other 9 new tests pass. **Narrowing it down.** I ran a print-only diagnostic with the test's lists and `out` pre-filled with `0xEE`: - In `[list, between, list]`, `between`'s copy **never lands**: out[0] stays `0xEEEEEEEE`. - The same happens with the copies 64 or 128 bytes apart, in a 64 KiB buffer, and with `between` writing into a buffer of its own. - `[list, between]` alone, and `[list, between, third]` with a different third list, are fine. - A GPU-side `queue.Wait` on the previous group's fence before the second `ExecuteCommandLists` doesn't help, and neither does a global UAV barrier at the start of the repeat's prelude. - With the D3D12 debug layer on, it mostly passes. The debug layer changes timing. So it isn't a memory or cache problem. The lists before the cut don't run when the same list is submitted again in the next `ExecuteCommandLists` while the first group is still pending. **Why.** The `ExecuteCommandLists` docs say "the driver is free to patch the submitted command lists". They make it the application's job to ensure the GPU isn't still reading any of them from a previous execution. The repeat resubmits `list` while its first execution is pending. My best explanation, which I haven't verified inside the driver: AMD chains the lists of one call by patching their ends. Resubmitting `list` re-patches it before the GPU has read the first group, so `between`, which `list` chained to, is skipped. That would also explain why only a CPU-side wait helps: the patching happens at submission, on the CPU. **Fix.** Before a later group (the cut a repeat makes), wait on the CPU for the previous group's fence. Only submissions that name a list twice wait; every other submission stays asynchronous. The two-preludes test held the first group behind a gate and asserted that nothing waits, so with the fix it can't finish. It now runs without the gate and checks the same things: the repeat makes its own prelude (counted from the spares pool once it has run), and the final texture state is COPY_SOURCE. **Results with the fix**, same card: - `a_repeated_list_reads_its_own_upload_memory`: 10/10. - victory-gpu, whole suite: 88/88 twice. The third run failed only `draw::tests::root_views_reach_their_copy_and_read_zeros_past_it`, main's intermittent test, which fails on main alone too. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. <details><summary>Patch on top of this PR (host.rs)</summary> ```diff --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -1057,6 +1057,16 @@ let started = std::time::Instant::now(); #[cfg(feature = "diagnostics")] crate::resource::life::note(0, crate::resource::life::SUBMITTED, *submitted, 0); + // A later group starts with a list the earlier one names (a + // repeat). The driver may patch submitted lists, and the GPU must + // not be reading one from a previous execution when it is + // submitted again (`ExecuteCommandLists`): resubmitted while the + // earlier group was pending, the lists before the cut never ran + // on an RX 6750 XT. A GPU-side wait is not enough, the patching + // happens at submission. + if i > 0 { + self.wait_gpu(*submitted - 1, true); + } // SAFETY: closed lists, not running (waited for above); our fence. let signalled = unsafe { #[cfg(test)] @@ -3639,8 +3649,9 @@ } /// A submission naming one list twice: the repeat's prelude records into - /// its own allocator and list while the first is still pending, so both - /// run with their own barriers, and nothing waits on the CPU. + /// its own allocator and list, so both runs get their own barriers. The + /// repeat's group is submitted once the first has run (a list must not + /// be resubmitted while the GPU may still read it), so no gate here. #[test] fn a_list_named_twice_in_a_submission_has_two_preludes() { use std::sync::atomic::Ordering; @@ -3680,20 +3691,15 @@ )]); } list.close(); - let gate = Gate::new(host); // COMMON -> RENDER_TARGET before the first run, COPY_SOURCE -> // RENDER_TARGET before the second: two different barriers. - host.execute_gated(&[&list, &list], &gate.0); - assert!(list.running()); - let mut spares = 0; - host.timeline.each_work(|w| { - if w.lists.iter().any(|l| std::ptr::eq(l.0, &list)) { - spares += w.preludes.len(); - } - }); - assert_eq!(spares, 1, "the repeat records into its own prelude"); - gate.release(); + // With no spares, the repeat makes its own prelude, which goes to + // the spares once it has run. + let kept = std::mem::take(&mut *super::pool(&super::SPARE_PRELUDES)); + host.execute(&[&list, &list]); host.drain(); + let spares = std::mem::replace(&mut *super::pool(&super::SPARE_PRELUDES), kept).len(); + assert_eq!(spares, 1, "the repeat records into its own prelude"); let copy = crate::resource::host_copy(tex).unwrap(); assert_eq!(copy.state.load(Ordering::Relaxed), 0x800); // SAFETY: a plain query. ``` </details> Unit tests only, no game files. AI-assisted (Claude found the cause and wrote the fix; I ran everything on my machine).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:36 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/shadow.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1828#issuecomment-7149753444) <!-- victory-triage v1 head=3a85ae51fb061bab89dde825fbdf1cee7bbf3ba7 verdict=needs-rebase at=2026-11-25T01:36:56Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/shadow.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Jitheswar on GitHub · 2026-11-25 02:33 UTC · original

Closing: this was opened against main by mistake. It's #595's async-submission commit plus one commit on top, on an old base, so it can't merge on its own. The one commit (a present waits for the previous frame, not its own) is offered to #595's author as https://github.com/wbkepler/VIctory/pull/5 instead. Measured on the game, it doesn't fix the #1118 stop by itself (details on #1118 and in that PR). Sorry for the noise. AI-assisted (Claude Code).

**@⁠Jitheswar** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1828#issuecomment-7150865916) Closing: this was opened against `main` by mistake. It's #595's async-submission commit plus one commit on top, on an old base, so it can't merge on its own. The one commit (a present waits for the previous frame, not its own) is offered to #595's author as https://github.com/wbkepler/VIctory/pull/5 instead. Measured on the game, it doesn't fix the #1118 stop by itself (details on #1118 and in that PR). Sorry for the noise. AI-assisted (Claude Code).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1828
No description provided.