GPU: preserve staged texture hashes after rejected partial reads #395

Open
VlREX wants to merge 2 commits from upstream-pr/395 into main
VlREX commented 2026-11-25 00:21:03 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by VlREX on 2026-11-25T00:21:03Z.


Problem

A rejected all-zero partial read updates the cached hash even though the staging data is unchanged. A subsequent fully mapped zero texture can therefore be skipped as if already staged.

Fix (updated after P2 review)

Preserve the staged hash when rejecting an all-zero partial read and reset the partial poll timestamp on the ordinary fully mapped path. Retain the original 30-frame partial read throttle regardless of guard reports: unguardable sparse blocks can be conservatively reported as written every query. Actual sparse writes may still wait for the next poll, as on upstream main. No change to the 8-frame guard policy, detiling or relay scheduling. Related to #89/#264; the link to skin artifacts is unverified.

Validation

Two Rust regression tests cover repeated sparse polling and rejected zero hashes. Executed JS model: 15,974,400 queries, zero disagreements with the expected periodic schedule. Native Rust and GPU A/B tests pending. No FPS gain claimed. No game data or new dependencies. AI-assisted (ChatGPT).

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594206086 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-25T00:21:03Z. --- ## Problem A rejected all-zero partial read updates the cached hash even though the staging data is unchanged. A subsequent fully mapped zero texture can therefore be skipped as if already staged. ## Fix (updated after P2 review) Preserve the staged hash when rejecting an all-zero partial read and reset the partial poll timestamp on the ordinary fully mapped path. Retain the original 30-frame partial read throttle regardless of guard reports: unguardable sparse blocks can be conservatively reported as written every query. Actual sparse writes may still wait for the next poll, as on upstream main. No change to the 8-frame guard policy, detiling or relay scheduling. Related to #89/#264; the link to skin artifacts is unverified. ## Validation Two Rust regression tests cover repeated sparse polling and rejected zero hashes. Executed JS model: 15,974,400 queries, zero disagreements with the expected periodic schedule. Native Rust and GPU A/B tests pending. No FPS gain claimed. No game data or new dependencies. AI-assisted (ChatGPT).
chatgpt-codex-connector[bot commented 2026-11-25 01:11:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:42:45Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 336b842ae5

ℹ️ 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:6049781093 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395#pullrequestreview-6049781093). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:42:45Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `336b842ae5` <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>
VlREX commented 2026-11-25 01:12:03 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by VlREX on 2026-11-25T00:47:09Z.


Addressed the P2 finding in 9b7b9888d4. The guard-reported-write bypass is removed, restoring the 30-frame bound during continuous partial mapping. The rejected-zero hash fix and fully-mapped reset remain. Added a repeated-query Rust regression and checked 15,974,400 model queries against the periodic schedule (zero mismatches). Native Rust/GPU tests remain pending; actual sparse writes can still wait for the next poll. @codex review

<!-- greyfinch-sync:fxceless/victory-fork:comment:7148872475 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7148872475). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-25T00:47:09Z. --- Addressed the P2 finding in 9b7b9888d4fbbd462851158476ecfe4e17e11f2f. The guard-reported-write bypass is removed, restoring the 30-frame bound during continuous partial mapping. The rejected-zero hash fix and fully-mapped reset remain. Added a repeated-query Rust regression and checked 15,974,400 model queries against the periodic schedule (zero mismatches). Native Rust/GPU tests remain pending; actual sparse writes can still wait for the next poll. @codex review
chatgpt-codex-connector[bot commented 2026-11-25 01:12:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:49:50Z.


Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 9b7b9888d4

ℹ️ 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:comment:7148923718 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7148923718). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:49:50Z. --- <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. Keep them coming! **Reviewed commit:** `9b7b9888d4` <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 01:12:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:38:13Z.


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-25T00:49:51.890580Z 9b7b988 Manual request
ℹ️ 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:7148719710 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7148719710). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:38:13Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"9b7b9888d4fbbd462851158476ecfe4e17e11f2f","has_any_findings":false,"has_unresolved_findings":false,"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-25T00:49:51.890580Z">2026-11-25T00:49:51.890580Z</relative-time> | `9b7b988` | Manual request | <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>
sawetco commented 2026-11-25 01:12:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by sawetco on 2026-11-25T01:00:14Z.


I ran the native Windows tests on 9b7b988 and checked what reaches a D3D12 texture on an RTX 5070 (621.24) and WARP. Both adapters reproduced the stale pixels with the base texture.rs from 31714de and returned the expected bytes with this PR.

The fixture uses a synthetic 256×64 RGBA8 texture backed by a 64 KiB mapping. After each call to the production Staging::refresh, it copies the staging buffer through a D3D12 texture to readback, waits for completion and checks all 65,536 bytes. Each table entry gives the byte value in the first and second 32 KiB. The two adapters agreed in every case.

Input at refresh Base PR
Entire mapping filled with 51 51 / 51 51 / 51
Clear to zero, decommit second half 51 / 51 51 / 51
Recommit second half, now entirely zero 51 / 51 00 / 00
Fill first half with A2, decommit second half again in the same frame 51 / 51 A2 / 00

The last two rows exercise both the rejected-zero hash and the partial-poll reset. The four existing texture::title_memory_tests also passed with --profile diag --features diagnostics --test-threads=1 on Windows 11 build 26300, rustc 1.100.0 MSVC. This verifies the synthetic remapping sequence. The effect on in-game character textures is still open.

AI-assisted fixture, local testing and write-up (Codex).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149106869 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7149106869). Originally posted by [sawetco](https://github.com/sawetco) on 2026-11-25T01:00:14Z. --- I ran the native Windows tests on `9b7b988` and checked what reaches a D3D12 texture on an RTX 5070 (621.24) and WARP. Both adapters reproduced the stale pixels with the base `texture.rs` from `31714de` and returned the expected bytes with this PR. The fixture uses a synthetic 256×64 RGBA8 texture backed by a 64 KiB mapping. After each call to the production `Staging::refresh`, it copies the staging buffer through a D3D12 texture to readback, waits for completion and checks all 65,536 bytes. Each table entry gives the byte value in the first and second 32 KiB. The two adapters agreed in every case. | Input at refresh | Base | PR | | --- | --- | --- | | Entire mapping filled with `51` | `51 / 51` | `51 / 51` | | Clear to zero, decommit second half | `51 / 51` | `51 / 51` | | Recommit second half, now entirely zero | `51 / 51` | `00 / 00` | | Fill first half with `A2`, decommit second half again in the same frame | `51 / 51` | `A2 / 00` | The last two rows exercise both the rejected-zero hash and the partial-poll reset. The four existing `texture::title_memory_tests` also passed with `--profile diag --features diagnostics --test-threads=1` on Windows 11 build 26300, rustc 1.100.0 MSVC. This verifies the synthetic remapping sequence. The effect on in-game character textures is still open. AI-assisted fixture, local testing and write-up (Codex).
chatgpt-codex-connector[bot commented 2026-11-25 01:12:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:42:45Z.

Code review location: crates/victory-gpu/src/texture.rs; line 677

@@ -650,11 +668,13 @@ impl Staging {
         // texture's address, so the textures take turns.
         // `VICTORY_TEXTURE_GUARD=0` hashes at every check, as before.
         static GUARD: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+        let mut guard_written = false;
         if *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
             && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true))
         {
             const HASH_EVERY: u64 = 8;
             let unwritten = last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked);
+            guard_written = last.asked != 0 && !unwritten;

P2 Badge Keep unguardable blocks subject to the polling throttle

When a sparse texture spans a 64-KiB view block with only some 4-KiB pages committed—the layout covered by writes_in_partly_committed_view_blocks_are_reported—watch::protect cannot protect the whole block and leaves it outside clean. Consequently, watch::guard conservatively reports that block on every query, and writes assigns each report a fresh journal sequence even without writes or remaps. This makes guard_written true after the first check, so the new bypass copies and hashes the entire unchanged sparse texture on every submission that samples it, rather than once per 30 frames. Distinguish these unguardable-block reports from confirmed writes, or retain bounded polling for them.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4688612141 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/395#discussion_r4688612141). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:42:45Z. **Code review location:** `crates/victory-gpu/src/texture.rs`; line 677 ~~~~diff @@ -650,11 +668,13 @@ impl Staging { // texture's address, so the textures take turns. // `VICTORY_TEXTURE_GUARD=0` hashes at every check, as before. static GUARD: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); + let mut guard_written = false; if *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0")) && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true)) { const HASH_EVERY: u64 = 8; let unwritten = last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked); + guard_written = last.asked != 0 && !unwritten; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep unguardable blocks subject to the polling throttle** When a sparse texture spans a 64-KiB view block with only some 4-KiB pages committed—the layout covered by `writes_in_partly_committed_view_blocks_are_reported`—`watch::protect` cannot protect the whole block and leaves it outside `clean`. Consequently, `watch::guard` conservatively reports that block on every query, and `writes` assigns each report a fresh journal sequence even without writes or remaps. This makes `guard_written` true after the first check, so the new bypass copies and hashes the entire unchanged sparse texture on every submission that samples it, rather than once per 30 frames. Distinguish these unguardable-block reports from confirmed writes, or retain bounded polling for them. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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/395:upstream-pr/395'
git switch 'upstream-pr/395'

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