GPU: alias copies before a list's first touch go to its prelude, once per source write (VICTORY_ALIAS_ONCE=1) #1013

Open
shawshanker18 wants to merge 2 commits from upstream-pr/1015 into main
shawshanker18 commented 2026-11-25 16:18:25 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by shawshanker18 on 2026-11-25T16:18:25Z.


What

VICTORY_ALIAS_ONCE=1 (off by default). The title writes R9G9B9E5 targets as R32_UINT and reads them through views placed in the same memory (crate::texture::alias). Every host list that read such a view copied the texture again through a buffer, even when nothing had written the source since the last copy.

With the switch:

  • A list that needs an alias copy before it touches the source or the placed texture leaves the copy to its prelude. Preludes are recorded at submission, in the queue's order, with both textures already in the copy states the list starts with.
  • Each submission gets a number. Lists note the host copies they put in a writing state (render target, UAV, depth write, stream out, copy or resolve destination).
  • A prelude leaves a copy out if it already ran in a submission after the source's last write.
  • Copies later in a list (after the list wrote or read the source itself) stay inline, exactly as before.

Assumption: only these copies write the placed texture's host copy (aliased views are never uploaded from title memory, see crate::draw::readable).

Measured

RTX 4050 Laptop (6 GB), Ryzen 7 7735HS, Series X, lit world, on 9376fd6 plus the window, 1080p display mode, copy-queue fetch and rehash-runs switches:

ms/frame fps
without 358 2.8
VICTORY_ALIAS_ONCE=1 333 3.0

Before the switch the timing run showed 78 alias copies a frame (26-31 ms of the card's time). With it: 26 made and 20 left out a frame in preludes, the rest inline. The picture looked the same (lit prison yard, same lighting in recordings with and without).

Checks

  • Rebased onto current main (3973179): cherry-picks cleanly, builds (--profile diag --features diagnostics).
  • cargo test -p victory-gpu --lib: 175 passed, 1 failed (indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields), which fails the same way on unmodified 3973179.
  • cargo clippy reports only lints in files this PR does not touch (also on main).

No game data.

<!-- greyfinch-sync:fxceless/victory-fork:issue:5494945324 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015). Originally posted by [shawshanker18](https://github.com/shawshanker18) on 2026-11-25T16:18:25Z. --- ## What `VICTORY_ALIAS_ONCE=1` (off by default). The title writes R9G9B9E5 targets as R32_UINT and reads them through views placed in the same memory (`crate::texture::alias`). Every host list that read such a view copied the texture again through a buffer, even when nothing had written the source since the last copy. With the switch: - A list that needs an alias copy **before it touches the source or the placed texture** leaves the copy to its prelude. Preludes are recorded at submission, in the queue's order, with both textures already in the copy states the list starts with. - Each submission gets a number. Lists note the host copies they put in a writing state (render target, UAV, depth write, stream out, copy or resolve destination). - A prelude **leaves a copy out if it already ran in a submission after the source's last write**. - Copies later in a list (after the list wrote or read the source itself) stay inline, exactly as before. Assumption: only these copies write the placed texture's host copy (aliased views are never uploaded from title memory, see `crate::draw::readable`). ## Measured RTX 4050 Laptop (6 GB), Ryzen 7 7735HS, Series X, lit world, on `9376fd6` plus the window, 1080p display mode, copy-queue fetch and rehash-runs switches: | | ms/frame | fps | |---|---|---| | without | 358 | 2.8 | | `VICTORY_ALIAS_ONCE=1` | 333 | 3.0 | Before the switch the timing run showed 78 alias copies a frame (26-31 ms of the card's time). With it: 26 made and 20 left out a frame in preludes, the rest inline. The picture looked the same (lit prison yard, same lighting in recordings with and without). ## Checks - Rebased onto current `main` (`3973179`): cherry-picks cleanly, builds (`--profile diag --features diagnostics`). - `cargo test -p victory-gpu --lib`: 175 passed, 1 failed (`indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`), which fails the same way on unmodified `3973179`. - `cargo clippy` reports only lints in files this PR does not touch (also on `main`). No game data.
chatgpt-codex-connector[bot] commented 2026-11-25 16:23:18 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T16:23:18Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb0d6489d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:fxceless/victory-fork:review:6061089663 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015#pullrequestreview-6061089663). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-25T16:23:18Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `eb0d6489d8` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-25 17:08:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T16:23:22Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T16:23:20.804174Z eb0d648 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7167900327 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015#issuecomment-7167900327). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T16:23:22Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"eb0d6489d897705177434cd344697e59a9363031","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T16:23:20.804174Z">2026-11-25T16:23:20.804174Z</relative-time> | `eb0d648` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-25 17:08:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T16:23:18Z.

Code review location: crates/victory-gpu/src/host.rs; line 6367

@@ -6294,7 +6347,37 @@ impl HostList {
             (real != *first)
                 .then(|| transition(&copy.texture, host_state(real), host_state(*first)))
         }));
-        if barriers.is_empty() && syncs.is_empty() {
+        // Alias copies (`crate::texture::alias_once`): this submission gets
+        // a number; a copy runs unless it ran in a submission after the
+        // source's last write; then this list's writes are marked.
+        type Run = (ID3D12Resource, ID3D12Resource, std::sync::Arc<crate::texture::Through>);
+        let aliases: Vec<Run> = {
+            let wanted = self.aliases.lock().unwrap_or_else(|e| e.into_inner());
+            let written = self.written.lock().unwrap_or_else(|e| e.into_inner());
+            let mut marks = ALIAS_WRITES.lock().unwrap_or_else(|e| e.into_inner());
+            let marks = marks.get_or_insert_with(Default::default);
+            let mut run = Vec::new();
+            if !wanted.is_empty() || !written.is_empty() {
+                marks.seq += 1;
+                let seq = marks.seq;
+                for a in wanted.iter() {
+                    let source = std::sync::Arc::as_ptr(&a.source) as usize;
+                    let key = (source, a.source.texture.as_raw() as usize, a.to.as_raw() as usize);
+                    let last_write = marks.written.get(&source).copied().unwrap_or(0);
+                    let fresh = marks.copied.get(&key).is_some_and(|&at| last_write < at);

P2 Badge Scope alias marks to each resource generation

When VICTORY_ALIAS_ONCE=1 and aliased textures are churned, these process-global marks are never removed (texture::forget only evicts THROUGH). If a new source and placed texture reuse the old addresses, the old copied timestamp can satisfy last_write < at, causing the new pair's first copy to be skipped and its view to contain stale or undefined contents. Retire marks with their resources or include a non-reused generation in the key.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4697647081 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015#discussion_r4697647081). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T16:23:18Z. **Code review location:** `crates/victory-gpu/src/host.rs`; line 6367 ~~~~diff @@ -6294,7 +6347,37 @@ impl HostList { (real != *first) .then(|| transition(&copy.texture, host_state(real), host_state(*first))) })); - if barriers.is_empty() && syncs.is_empty() { + // Alias copies (`crate::texture::alias_once`): this submission gets + // a number; a copy runs unless it ran in a submission after the + // source's last write; then this list's writes are marked. + type Run = (ID3D12Resource, ID3D12Resource, std::sync::Arc<crate::texture::Through>); + let aliases: Vec<Run> = { + let wanted = self.aliases.lock().unwrap_or_else(|e| e.into_inner()); + let written = self.written.lock().unwrap_or_else(|e| e.into_inner()); + let mut marks = ALIAS_WRITES.lock().unwrap_or_else(|e| e.into_inner()); + let marks = marks.get_or_insert_with(Default::default); + let mut run = Vec::new(); + if !wanted.is_empty() || !written.is_empty() { + marks.seq += 1; + let seq = marks.seq; + for a in wanted.iter() { + let source = std::sync::Arc::as_ptr(&a.source) as usize; + let key = (source, a.source.texture.as_raw() as usize, a.to.as_raw() as usize); + let last_write = marks.written.get(&source).copied().unwrap_or(0); + let fresh = marks.copied.get(&key).is_some_and(|&at| last_write < at); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Scope alias marks to each resource generation** When `VICTORY_ALIAS_ONCE=1` and aliased textures are churned, these process-global marks are never removed (`texture::forget` only evicts `THROUGH`). If a new source and placed texture reuse the old addresses, the old `copied` timestamp can satisfy `last_write < at`, causing the new pair's first copy to be skipped and its view to contain stale or undefined contents. Retire marks with their resources or include a non-reused generation in the key. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Proudnoob4 commented 2026-11-25 18:05:13 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Proudnoob4 on 2026-11-25T17:39:34Z.


Tested in-game on Windows 10 Pro (22H2), Intel i5-13600K (6P+8E), RTX 4080 16 GB (driver 621.01, Series X profile), 420 s run in the prison cell scene (ca8829f + #1014 + #1015 + #1016 + #1029 + #1032 stacked, compared against our 600 s 465b94f run with the same base switches VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_COPY_PLAIN=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_JOIN_PARTS=1 VICTORY_BACK_OWN_VIEW=1 VICTORY_INDIRECT_GATHER=1 plus VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_GROUP_SYNC=2 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024).

VICTORY_ALIAS_ONCE=1 tail steady state in the cell scene:

  • lias copies in preludes per frame (VICTORY_ALIAS_ONCE=1): 26.0 made, 20.0-20.2 left out (source not written since) (~44% of prelude alias copies skipped cleanly).
  • Clean visual match ( rame-2048.png), stacked run hit 8.50 fps / 117.0 ms median (mean 8.31, max 9.80).

AI-assisted (Gemini 4 Hydrogen).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7169817619 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015#issuecomment-7169817619). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-25T17:39:34Z. --- Tested in-game on Windows 10 Pro (22H2), Intel i5-13600K (6P+8E), RTX 4080 16 GB (driver 621.01, Series X profile), 420 s run in the prison cell scene (ca8829f + #1014 + #1015 + #1016 + #1029 + #1032 stacked, compared against our 600 s 465b94f run with the same base switches VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_COPY_PLAIN=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_JOIN_PARTS=1 VICTORY_BACK_OWN_VIEW=1 VICTORY_INDIRECT_GATHER=1 plus VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_GROUP_SYNC=2 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024). VICTORY_ALIAS_ONCE=1 tail steady state in the cell scene: - lias copies in preludes per frame (VICTORY_ALIAS_ONCE=1): 26.0 made, 20.0-20.2 left out (source not written since) (~44% of prelude alias copies skipped cleanly). - Clean visual match ( rame-2048.png), stacked run hit 8.50 fps / 117.0 ms median (mean 8.31, max 9.80). AI-assisted (Gemini 4 Hydrogen).
shawshanker18 commented 2026-11-25 20:09:25 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by shawshanker18 on 2026-11-25T19:21:57Z.


Rebased onto d510ee4 (the conflict was in HostList::prelude; the gather records and the alias copies now both run there), and the Codex finding is fixed. Each alias mark now holds weak references to its source and placed host copies. While a mark lives, the allocation behind its address can't be freed and handed to a new copy, so a new pair can't inherit an old pair's mark. Marks of copies that are gone are swept once there are more than 4,096.

cargo test -p victory-gpu --lib: 181 passed. The one failure, warp_budget_saturates_without_wraparound_and_preserves_draw_fields, fails the same way on main.

@Proudnoob4 thanks for the in-game run on the 4080: the 26 made / 20 left out per frame matches what I measured on a 4050.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7172193887 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015#issuecomment-7172193887). Originally posted by [shawshanker18](https://github.com/shawshanker18) on 2026-11-25T19:21:57Z. --- Rebased onto `d510ee4` (the conflict was in `HostList::prelude`; the gather records and the alias copies now both run there), and the Codex finding is fixed. Each alias mark now holds weak references to its source and placed host copies. While a mark lives, the allocation behind its address can't be freed and handed to a new copy, so a new pair can't inherit an old pair's mark. Marks of copies that are gone are swept once there are more than 4,096. `cargo test -p victory-gpu --lib`: 181 passed. The one failure, `warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, fails the same way on `main`. @Proudnoob4 thanks for the in-game run on the 4080: the 26 made / 20 left out per frame matches what I measured on a 4050.
Dathinel commented 2026-11-28 04:51:03 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-28T04:51:03Z.


I reproduced an output difference at a30b03e5 with a synthetic 4×4 R32_UINT source and a placed R9G9B9E5 view at the same address. The test-only commit adds one ignored test on top of this PR.

After the first alias read copies 0x11, an explicit CopyTextureRegion writes 0x77 to the view. A direct D3D12 readback confirms that write. On the next alias read, all 64 bytes are 0x11 with the switch off and 0x77 with it on. Rewriting the source updates the view in both modes. This exercises the assumption about other writers to the destination. Which value the console would return remains unverified.

To reproduce on Windows, run the following on the test commit in PowerShell:

foreach ($mode in '0', '1') {
    $env:VICTORY_ALIAS_ONCE = $mode
    cargo test --locked -p victory-gpu --lib --features diagnostics resource::tests::alias_copy_after_independent_destination_write -- --ignored --exact --nocapture
}

The assertion compares against the switch-off behavior and is expected to fail for mode 1. AI-assisted test and analysis.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7234298135 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1015#issuecomment-7234298135). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-28T04:51:03Z. --- I reproduced an output difference at `a30b03e5` with a synthetic 4×4 R32_UINT source and a placed R9G9B9E5 view at the same address. The [test-only commit](https://github.com/Dathinel/victory-4gb/commit/c90edc00dc29285444b478d4823b3fadcdb1d2b3) adds one ignored test on top of this PR. After the first alias read copies 0x11, an explicit CopyTextureRegion writes 0x77 to the view. A direct D3D12 readback confirms that write. On the next alias read, all 64 bytes are 0x11 with the switch off and 0x77 with it on. Rewriting the source updates the view in both modes. This exercises the assumption about other writers to the destination. Which value the console would return remains unverified. To reproduce on Windows, run the following on the test commit in PowerShell: ```powershell foreach ($mode in '0', '1') { $env:VICTORY_ALIAS_ONCE = $mode cargo test --locked -p victory-gpu --lib --features diagnostics resource::tests::alias_copy_after_independent_destination_write -- --ignored --exact --nocapture } ``` The assertion compares against the switch-off behavior and is expected to fail for mode 1. AI-assisted test and analysis.
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/1015:upstream-pr/1015'
git switch 'upstream-pr/1015'

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