Copy back render targets of listed kinds, and the water's kinds by default (rivers and pools no longer push the player out) #4675

Closed
github-bot wants to merge 1 commit from github-bot/gh-4674 into main AGit
Owner

@⁠cadfan on GitHub · 2026-12-01 01:31 UTC · original
cadfan:fix/4533-render-target-copy-back → main · +101 −4 · 5 files · 1 commits · closed without merging

Fixes #4534

What it changes

What was wrong. On the console the CPU sees what the GPU wrote. Here, a texture the card writes is copied back into title memory only if its kind is in VICTORY_TEXTURE_BACK and a shader wrote it through unordered access. Render targets were never copied back.

The game's water reads textures like that on the CPU. A read watch (the separate PR #4676, VICTORY_READ_WATCH=1) found these reads:

  • A 256x256 R8_UNORM render target around the player (256x256f61). It is read about ten times a second, from two places in the title's code (+0x50313d2 and +0x203345d). With the target copied back, it holds 128 where the water is calm, and it dropped to 124 at a splash. Without it, the title read memory the card's drawing never reached.
  • Twelve compute-written lookup tables, read only while the player enters a river: 2048x128f62 and 4096x64f62 (R8_UINT), and 4096x64f57 (R16_UINT). Their kinds were not in the list, so the title read zeros.
  • 64x64f50 (R8G8_UINT), read once.

The result was the "strong current" in #4534. The player was pushed out of rivers and pools, the car was too, and Bret's pickup flipped in the river in Veteran Hunted.

What this does.

  • A draw that renders into a target, or a clear of one, now asks for the copy-back the same way an unordered-access write does (HostList::target_written, from draw.rs and clear_rtv). It applies only to kinds in VICTORY_TEXTURE_BACK.
  • VICTORY_TEXTURE_BACK_TARGETS=0 turns the render-target copy-back off, to compare against the old behaviour.
  • The default list adds the five kinds above to the ocean's four: 256x256f61,64x64f50,2048x128f62,4096x64f62,4096x64f57.

Why this fixes it. The water code uses these textures to decide how water pushes on the player and vehicles. The ripple map sits at 128 in calm water and moves away from 128 where something disturbs it (124 at a splash). Before, the title never saw what the card drew into that map, so calm water didn't read as calm, and the lookup tables read as zeros. Our reading is that this produced the steady outward push. Now, when a list that wrote one of these textures finishes, it is copied back and tiled into title memory in the console's layout, as for the ocean. The title reads calm water and real table data, at most a frame late.

Related to #3363, but not the same. #3363 also copies back a render target, but only one: the 960x536 linear phone-photo target (render_target_wanted checks for that kind and a linear layout). The water's target isn't let through, so #3363 doesn't fix this. Here, any listed kind is copied back. The two PRs touch a few of the same lines in draw.rs, host.rs and list.rs, so whichever merges second needs a rebase.

Cost. Lists that write one of these kinds now copy it back when they close. The texture readback is 64 KiB for the target and 256-512 KiB for each table. The tables are written only around the time the player enters water.

How it was tested

  • GPU and profile: RTX 5080, Windows 11. Series X profile, 2560x1440 output, DLSS Performance, DLSS frame generation 2x. No ray tracing.
  • Before (v2026.11.26 and the 2026-11-30 builds, clips and logs on #4534): wading or diving into Kelly River pushed the player back out. Cars were pushed out too. In Veteran Hunted, Bret's pickup flipped crossing the river.
  • After:
    • On 0b353a75 (main of 2026-11-30 plus #3043 and #3487), with these kinds set through VICTORY_TEXTURE_BACK:
      • Walking into Kelly River worked. The player swam with the dive prompt, then swam back to the bank.
      • A car was driven into the river and back out.
      • In Veteran Hunted, the pickup drove across the river and out the far bank. The mission went on.
      • The game exited cleanly (exit=0).
      • The read watch's log for that run shows the target holding 128. Apart from the target (copied back here), no texture the title read was left uncopied.
    • On this branch (a3c670a8), with VICTORY_TEXTURE_BACK=1 so the new default kinds apply (the log lists all nine): I walked into Kelly River, swam, dived under and came back up, then swam and waded back to the bank. I wasn't pushed out. The game exited cleanly (exit=0), and the frame rate was the same as in the earlier runs. I started Veteran Hunted on this commit, but stopped before the river crossing.
    • Clips of these runs are in my comment on #4534.
  • Not tested:
    • A dive from the Kelly River North bridge still killed the player on impact. The water under that bridge is shallow, with sandbanks, so this may be the game's own fall damage. A control jump into deep inland water hasn't been done.
    • The phone-photo target (#3363's case) wasn't tried.
  • Wave sizes: no shader changes.
  • cargo test passed for the crates it touches: yes, apart from tests that also fail on main:
    • On this commit, cargo test -p victory-gpu --lib -- a_cleared_target_of_a_kind a_rewritten_back_texture passes on the RTX 5080. The new test clears a 256x256 R8_UNORM target and checks every texel in title memory is 128.
    • With VICTORY_TEXTURE_BACK_TARGETS=0, the new test fails as it should (texture_back_count 0, expected 1).
    • cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features: clean.
    • cargo test --workspace --locked --no-fail-fast: everything passes except victory-hle's xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it. That test fails the same way on main (7d93ee07) when the crate runs as a whole, and passes alone. Open PR #2439 covers it.
    • On an earlier full run, two other timing tests failed once each and then passed 3 times out of 3 alone, on main and on this branch: pipeline::make::a_pipeline_made_ready_is_the_one_the_title_gets, and card_steps::shared_scratch_eliminates_flight_settle_end_to_end (#2741).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. I searched for: VICTORY_TEXTURE_BACK, texback, read watch, 4533, "render target copy back" and "river current". Related: #3363 (photo-only render-target copy-back, see above); #3524 (deduplicates texbacks); #4464 (HOST_WRITTEN_AT and remaps). None of them covers this.
**@⁠cadfan** on GitHub · 2026-12-01 01:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4674) `cadfan:fix/4533-render-target-copy-back` → `main` · +101 −4 · 5 files · 1 commits · closed without merging Fixes #4534 ## What it changes **What was wrong.** On the console the CPU sees what the GPU wrote. Here, a texture the card writes is copied back into title memory only if its kind is in `VICTORY_TEXTURE_BACK` **and** a shader wrote it through unordered access. Render targets were never copied back. The game's water reads textures like that on the CPU. A read watch (the separate PR #4676, `VICTORY_READ_WATCH=1`) found these reads: - **A 256x256 R8_UNORM render target around the player** (`256x256f61`). It is read about ten times a second, from two places in the title's code (`+0x50313d2` and `+0x203345d`). With the target copied back, it holds 128 where the water is calm, and it dropped to 124 at a splash. Without it, the title read memory the card's drawing never reached. - **Twelve compute-written lookup tables, read only while the player enters a river**: `2048x128f62` and `4096x64f62` (R8_UINT), and `4096x64f57` (R16_UINT). Their kinds were not in the list, so the title read zeros. - **`64x64f50` (R8G8_UINT)**, read once. The result was the "strong current" in #4534. The player was pushed out of rivers and pools, the car was too, and Bret's pickup flipped in the river in Veteran Hunted. **What this does.** - A draw that renders into a target, or a clear of one, now asks for the copy-back the same way an unordered-access write does (`HostList::target_written`, from `draw.rs` and `clear_rtv`). It applies only to kinds in `VICTORY_TEXTURE_BACK`. - `VICTORY_TEXTURE_BACK_TARGETS=0` turns the render-target copy-back off, to compare against the old behaviour. - The default list adds the five kinds above to the ocean's four: `256x256f61,64x64f50,2048x128f62,4096x64f62,4096x64f57`. **Why this fixes it.** The water code uses these textures to decide how water pushes on the player and vehicles. The ripple map sits at 128 in calm water and moves away from 128 where something disturbs it (124 at a splash). Before, the title never saw what the card drew into that map, so calm water didn't read as calm, and the lookup tables read as zeros. Our reading is that this produced the steady outward push. Now, when a list that wrote one of these textures finishes, it is copied back and tiled into title memory in the console's layout, as for the ocean. The title reads calm water and real table data, at most a frame late. **Related to #3363, but not the same.** #3363 also copies back a render target, but only one: the 960x536 linear phone-photo target (`render_target_wanted` checks for that kind and a linear layout). The water's target isn't let through, so #3363 doesn't fix this. Here, any listed kind is copied back. The two PRs touch a few of the same lines in `draw.rs`, `host.rs` and `list.rs`, so whichever merges second needs a rebase. **Cost.** Lists that write one of these kinds now copy it back when they close. The texture readback is 64 KiB for the target and 256-512 KiB for each table. The tables are written only around the time the player enters water. ## How it was tested - **GPU and profile:** RTX 5080, Windows 11. Series X profile, 2560x1440 output, DLSS Performance, DLSS frame generation 2x. No ray tracing. - **Before** (v2026.11.26 and the 2026-11-30 builds, clips and logs on #4534): wading or diving into Kelly River pushed the player back out. Cars were pushed out too. In Veteran Hunted, Bret's pickup flipped crossing the river. - **After:** - **On `0b353a75`** (main of 2026-11-30 plus #3043 and #3487), with these kinds set through `VICTORY_TEXTURE_BACK`: - Walking into Kelly River worked. The player swam with the dive prompt, then swam back to the bank. - A car was driven into the river and back out. - In Veteran Hunted, the pickup drove across the river and out the far bank. The mission went on. - The game exited cleanly (`exit=0`). - The read watch's log for that run shows the target holding 128. Apart from the target (copied back here), no texture the title read was left uncopied. - **On this branch** (`a3c670a8`), with `VICTORY_TEXTURE_BACK=1` so the new default kinds apply (the log lists all nine): I walked into Kelly River, swam, dived under and came back up, then swam and waded back to the bank. I wasn't pushed out. The game exited cleanly (`exit=0`), and the frame rate was the same as in the earlier runs. I started Veteran Hunted on this commit, but stopped before the river crossing. - Clips of these runs are in my comment on #4534. - **Not tested:** - A dive from the Kelly River North bridge still killed the player on impact. The water under that bridge is shallow, with sandbanks, so this may be the game's own fall damage. A control jump into deep inland water hasn't been done. - The phone-photo target (#3363's case) wasn't tried. - **Wave sizes:** no shader changes. - **`cargo test` passed for the crates it touches:** yes, apart from tests that also fail on `main`: - On this commit, `cargo test -p victory-gpu --lib -- a_cleared_target_of_a_kind a_rewritten_back_texture` passes on the RTX 5080. The new test clears a 256x256 R8_UNORM target and checks every texel in title memory is 128. - With `VICTORY_TEXTURE_BACK_TARGETS=0`, the new test fails as it should (`texture_back_count` 0, expected 1). - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features`: clean. - `cargo test --workspace --locked --no-fail-fast`: everything passes except `victory-hle`'s `xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`. That test fails the same way on `main` (`7d93ee07`) when the crate runs as a whole, and passes alone. Open PR #2439 covers it. - On an earlier full run, two other timing tests failed once each and then passed 3 times out of 3 alone, on `main` and on this branch: `pipeline::make::a_pipeline_made_ready_is_the_one_the_title_gets`, and `card_steps::shared_scratch_eliminates_flight_settle_end_to_end` (#2741). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. I searched for: `VICTORY_TEXTURE_BACK`, `texback`, `read watch`, `4533`, "render target copy back" and "river current". Related: #3363 (photo-only render-target copy-back, see above); #3524 (deduplicates texbacks); #4464 (`HOST_WRITTEN_AT` and remaps). None of them covers this.
Only textures written through unordered access were copied back into title
memory. The title's CPU also reads a render target: its water reads a 256x256
R8_UNORM target around the player (128 where the water is calm) from two
places in its code, and, entering a river, twelve compute-written tables
(2048x128 and 4096x64 R8_UINT, 4096x64 R16_UINT). It found memory nothing had
written, and rivers and pools pushed the player and vehicles out like a strong
current; the Veteran Hunted mission could not cross its river.

A draw into a target, or a clear of one, now asks for the copy-back as a
compute write does, for the kinds in VICTORY_TEXTURE_BACK
(VICTORY_TEXTURE_BACK_TARGETS=0: not targets). The default list adds the five
kinds above (and 64x64 R8G8_UINT, read once) to the ocean's four.

Fixes #4533

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ASPnbv2evYgtuSvV5azeHT
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 01:35:50 +00:00
github-bot closed this pull request 2026-12-01 18:36:56 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:35 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4674#issuecomment-7321181762) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

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/trustno1-coder--VIctory-NVIDIA!4675
No description provided.