fix(gpu): pin the texture a placed view aliases while the copy uses it #25

Open
github-bot wants to merge 1 commit from github-bot/gh-25 into main AGit
Owner

@⁠CuteBooty on GitHub · 2026-11-27 08:51 UTC · original
CuteBooty:fix/alias-pin → main · +100 −7 · 5 files · 1 commits · open

alias_of returned a bare pointer to the aliased texture after its table lock was released, and texture::alias then used it; the title can drop its last reference in between (use-after-free, or a copy from the next texture at that address). Now alias_of takes a reference under the lock and returns a guard that the two copying callers hold until the alias copy is recorded. The three callers that only ask (draw.rs bake sources, texture/ahead.rs, resource.rs host-copy levels) get is_aliased, the same lookup without a pin, so they never take and drop a reference themselves. No switch.

Original author: CwWwWwW (fxceless/victory-fork PR #1336). Held and add_ref_alive follow fxceless/victory-fork d4a528ba, which this tree did not have. The original test comes along (it needs a diagnostics build and a host GPU).

Please look hardest at is_aliased: it is my adaptation for this tree's extra callers, not part of the original PR.

cargo test -p victory-gpu on this branch: 407 passed / 2 failed / 35 ignored (the two indirect::tests named below, which fail without this change too).

Tested

RTX 3070 8 GB (driver 621.24), Ryzen 5 3600, 32 GB, Windows 11; Series S profile, 1920x1080, your launcher's settings without DLSS, built from source.

  • In the game (all four of my pull requests together, on 1010e023): five runs, 73 minutes in all, 0 logged errors, no device loss. Frame times were not slower than the unmodified tree on the same save: medians of the 5-second lines in a 37-minute run were 64 / 78 / 94 ms at 3,000-5,000 / 5,000-7,000 / 7,000-9,000 draws, against 89 / 104 / 116 ms for the unmodified tree in a 51-minute run the same evening. The routes differed, so read that as "not slower", not as a gain.
  • On c437b059 (this branch is based there; it merges cleanly onto 18a8dc26): the branch compiles (cargo check --locked -p victory --features diagnostics). cargo test --workspace --locked with all four changes: 1043 passed / 3 failed / 46 ignored; on c437b059 alone: 1034 / 3 / 46. The same three fail on both: indirect::tests::host_list_budget_starts_empty_at_each_submission, indirect::tests::warp_batch_charges_every_execution, and policy::tests::repository_passes_policy (it rejects PLAY_FRAMEGEN.bat).
  • Clippy (--workspace --all-targets -- -D warnings, with and without --all-features, --keep-going): fails on c437b059 alone and with these changes, with the same findings (31 and 30 distinct, none in the changed code); the first is victory-formats/src/texture.rs:1346.

Not tested: AMD and Intel cards, DLSS and frame generation, Series X beyond one 9-minute run.

AI-assisted: ported, checked and written up with Claude Code; the game runs were played by me.

🤖 Generated with Claude Code

**@⁠CuteBooty** on GitHub · 2026-11-27 08:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/25) `CuteBooty:fix/alias-pin` → `main` · +100 −7 · 5 files · 1 commits · open `alias_of` returned a bare pointer to the aliased texture after its table lock was released, and `texture::alias` then used it; the title can drop its last reference in between (use-after-free, or a copy from the next texture at that address). Now `alias_of` takes a reference under the lock and returns a guard that the two copying callers hold until the alias copy is recorded. The three callers that only ask (draw.rs bake sources, texture/ahead.rs, resource.rs host-copy levels) get `is_aliased`, the same lookup without a pin, so they never take and drop a reference themselves. No switch. Original author: CwWwWwW (fxceless/victory-fork PR #1336). `Held` and `add_ref_alive` follow fxceless/victory-fork d4a528ba, which this tree did not have. The original test comes along (it needs a diagnostics build and a host GPU). Please look hardest at `is_aliased`: it is my adaptation for this tree's extra callers, not part of the original PR. `cargo test -p victory-gpu` on this branch: 407 passed / 2 failed / 35 ignored (the two `indirect::tests` named below, which fail without this change too). ## Tested RTX 3070 8 GB (driver 621.24), Ryzen 5 3600, 32 GB, Windows 11; Series S profile, 1920x1080, your launcher's settings without DLSS, built from source. - **In the game** (all four of my pull requests together, on 1010e023): five runs, 73 minutes in all, 0 logged errors, no device loss. Frame times were not slower than the unmodified tree on the same save: medians of the 5-second lines in a 37-minute run were 64 / 78 / 94 ms at 3,000-5,000 / 5,000-7,000 / 7,000-9,000 draws, against 89 / 104 / 116 ms for the unmodified tree in a 51-minute run the same evening. The routes differed, so read that as "not slower", not as a gain. - **On c437b059** (this branch is based there; it merges cleanly onto 18a8dc26): the branch compiles (`cargo check --locked -p victory --features diagnostics`). `cargo test --workspace --locked` with all four changes: 1043 passed / 3 failed / 46 ignored; on c437b059 alone: 1034 / 3 / 46. The same three fail on both: `indirect::tests::host_list_budget_starts_empty_at_each_submission`, `indirect::tests::warp_batch_charges_every_execution`, and `policy::tests::repository_passes_policy` (it rejects `PLAY_FRAMEGEN.bat`). - **Clippy** (`--workspace --all-targets -- -D warnings`, with and without `--all-features`, `--keep-going`): fails on c437b059 alone and with these changes, with the same findings (31 and 30 distinct, none in the changed code); the first is `victory-formats/src/texture.rs:1346`. Not tested: AMD and Intel cards, DLSS and frame generation, Series X beyond one 9-minute run. AI-assisted: ported, checked and written up with Claude Code; the game runs were played by me. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
alias_of returned the bare pointer of the aliased texture after
TARGETS_AT's lock was gone, and texture::alias then used it; the title can
drop its last reference in between (use-after-free, or a copy from the next
texture at the same address). alias_of now takes a reference under the lock
(object::add_ref_alive) and returns a Held guard that the two copying
callers (draw.rs readable, external.rs prepare_input) keep until the alias
copy is recorded; a texture already being released is not returned.

This tree has three lookup-only callers (draw.rs bake sources,
texture/ahead.rs, resource.rs host-copy levels). They now call is_aliased,
the same lookup without a pin, so none of them takes and drops a reference
(and so none can end up freeing the texture inside its own work). No
switch: a lifetime fix with no other behaviour change. The original test
comes along (diagnostics builds with a host GPU only).

Original author: CwWwWwW (fxceless/victory-fork pull request #1336,
f8fab6fb). Ported by hand from CuteBooty/victory-8gb; Held and
add_ref_alive follow fxceless/victory-fork d4a528ba, which this tree does
not have.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:55:37 +00:00
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/25/head:github-bot/gh-25'
git switch 'github-bot/gh-25'

Merge

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