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

Open
github-bot wants to merge 2 commits from github-bot/gh-395 into main AGit
Owner

@⁠VlREX on GitHub · 2026-11-25 00:21 UTC · original
VlREX:virex/texture-partial-refresh → main · +97 −11 · 2 files · 2 commits · open

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).

**@⁠VlREX** on GitHub · 2026-11-25 00:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/395) `VlREX:virex/texture-partial-refresh` → `main` · +97 −11 · 2 files · 2 commits · open ## 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).
Retain the 30-frame bound regardless of conservative guard reports. Preserve rejected-zero hash correctness and reset on fully mapped reads. Add repeated-submission regression test.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:27 +00:00
Author
Owner

@⁠VlREX on GitHub · 2026-11-25 00:47 UTC · original

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

**@⁠VlREX** on GitHub · 2026-11-25 00:47 UTC · [original](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7148872475) 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
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:49 UTC · original

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".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:49 UTC · [original](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7148923718) <!-- 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:38 UTC · original · edited 2026-11-25 00:49 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:38 UTC · [original](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7148719710) · edited 2026-11-25 00:49 UTC <!-- 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>
Author
Owner

@⁠sawetco on GitHub · 2026-11-25 01:00 UTC · original

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).

**@⁠sawetco** on GitHub · 2026-11-25 01:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/395#issuecomment-7149106869) 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).
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:42 UTC · original
On crates/victory-gpu/src/texture.rs line 677 (outdated):

@@ -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 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/395#discussion_r4688612141) On `crates/victory-gpu/src/texture.rs` line 677 (outdated): ```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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/395/head:github-bot/gh-395'
git switch 'github-bot/gh-395'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-395'
git switch 'github-bot/gh-395'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-395'
git switch 'github-bot/gh-395'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-395'
git switch 'main'
git merge --squash 'github-bot/gh-395'
git switch 'main'
git merge --ff-only 'github-bot/gh-395'
git switch 'main'
git merge 'github-bot/gh-395'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.