Skip the global texture lock when no host-written textures #152

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

@⁠Adika713 on GitHub · 2026-11-25 17:25 UTC · original
Adika713:perf/host-written-fast-path → main · +101 −17 · 1 files · 1 commits · open

STATUS: opened as #146 (head TBD).

Skip the global host-written-texture lock when it is empty.

Every texture use asked HOST_WRITTEN, a global Mutex<Option<HashSet>>, whether
the texture had been written by a host copy. Most submissions have no such
textures, so that was a lock/unlock just to read an empty set. An AtomicBool
now records whether the set has anything; readers skip the lock while it is
false. Writers keep the flag in sync while holding the same mutex.

What is in it

  • HOST_WRITTEN_ANY plus is_host_written(); host_written, rewritten,
    forget, upload_first and upload use them.
  • A regression test for clearing the flag with the last texture.
  • An ignored CPU-only A/B benchmark of the old lock check and the new check.

Tested

AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11,
rustc/cargo 1.98.1. No game data; the game was not run. Isolated
CARGO_TARGET_DIR per tree.

cargo test --release -p victory-gpu --lib host_written_check_fast_path -- --ignored --nocapture --test-threads=1,
3 runs, median of 5 samples each:

  • old lock check: 11.6 / 11.3 / 11.6 ns
  • atomic check: 2.7 / 3.5 / 3.0 ns

Correctness:

  • cargo check -p victory-gpu --lib --tests --locked: exit 0.
  • cargo test -p victory-gpu --lib texture:: -- --test-threads=1: 6 passed, 0 failed, 1 ignored, 110 filtered.
  • Full victory-gpu lib, 20 serial runs with the pre-existing #102 flake skipped: 0 failed; each 111 passed, 0 failed, 5 ignored, 1 filtered.
  • cargo test --workspace --no-fail-fast --locked: no new failures; known xmem, shader and policy failures remain. victory-gpu 112 passed, 0 failed, 5 ignored.

Not tested

  • In-game FPS. No game files or paths were supplied, so this makes no claim
    about frame rate.
  • NVIDIA hardware.
  • Open PR #127 reorders first_use before the same lock in upload; if both
    changes land, that hunk needs rebasing. The fast path also benefits
    upload_first, which #127 does not touch.

AI use

AI-assisted: OpenCode, model Big Pickle. No game data.

**@⁠Adika713** on GitHub · 2026-11-25 17:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/152) `Adika713:perf/host-written-fast-path` → `main` · +101 −17 · 1 files · 1 commits · open STATUS: opened as https://git.gtahub.st/github/Belobug--VIctory-Belobug-AMD/pulls/146 (head `TBD`). Skip the global host-written-texture lock when it is empty. Every texture use asked `HOST_WRITTEN`, a global `Mutex<Option<HashSet>>`, whether the texture had been written by a host copy. Most submissions have no such textures, so that was a lock/unlock just to read an empty set. An `AtomicBool` now records whether the set has anything; readers skip the lock while it is false. Writers keep the flag in sync while holding the same mutex. **What is in it** - `HOST_WRITTEN_ANY` plus `is_host_written()`; `host_written`, `rewritten`, `forget`, `upload_first` and `upload` use them. - A regression test for clearing the flag with the last texture. - An ignored CPU-only A/B benchmark of the old lock check and the new check. **Tested** AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, rustc/cargo 1.98.1. No game data; the game was not run. Isolated `CARGO_TARGET_DIR` per tree. `cargo test --release -p victory-gpu --lib host_written_check_fast_path -- --ignored --nocapture --test-threads=1`, 3 runs, median of 5 samples each: - old lock check: **11.6 / 11.3 / 11.6 ns** - atomic check: **2.7 / 3.5 / 3.0 ns** Correctness: - `cargo check -p victory-gpu --lib --tests --locked`: exit 0. - `cargo test -p victory-gpu --lib texture:: -- --test-threads=1`: 6 passed, 0 failed, 1 ignored, 110 filtered. - Full `victory-gpu` lib, 20 serial runs with the pre-existing #102 flake skipped: 0 failed; each 111 passed, 0 failed, 5 ignored, 1 filtered. - `cargo test --workspace --no-fail-fast --locked`: no new failures; known xmem, shader and policy failures remain. `victory-gpu` 112 passed, 0 failed, 5 ignored. **Not tested** - In-game FPS. No game files or paths were supplied, so this makes no claim about frame rate. - NVIDIA hardware. - Open PR #127 reorders `first_use` before the same lock in `upload`; if both changes land, that hunk needs rebasing. The fast path also benefits `upload_first`, which #127 does not touch. **AI use** AI-assisted: OpenCode, model Big Pickle. No game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:43 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 17:36 UTC · original

Tested PR head f637727 on Bazzite Linux 45, with GE-Proton 10-34 / Wine 10.0 and vkd3d-proton 3.0.0, on an NVIDIA GeForce RTX 3090 (host driver 620.73.04). No game files were needed.

Cross-compilation of the Windows GNU victory-gpu test target succeeded. Under Proton, the targeted regression test texture::tests::host_written_flag_clears_with_the_last_texture passed (1 passed, 0 failed). The full texture:: filter also passed: 6 passed, 0 failed, 1 ignored (the synthetic CPU release benchmark), 110 filtered out.

This is a Windows test binary running through Proton on NVIDIA, not a native Windows run. I did not use the ignored benchmark for performance claims because Proton timings would not be comparable to the native Windows measurements.

**@⁠KernelSmoker** on GitHub · 2026-11-25 17:36 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/152#issuecomment-7169735472) Tested PR head `f637727` on Bazzite Linux 45, with GE-Proton 10-34 / Wine 10.0 and vkd3d-proton 3.0.0, on an NVIDIA GeForce RTX 3090 (host driver 620.73.04). No game files were needed. Cross-compilation of the Windows GNU `victory-gpu` test target succeeded. Under Proton, the targeted regression test `texture::tests::host_written_flag_clears_with_the_last_texture` passed (1 passed, 0 failed). The full `texture::` filter also passed: 6 passed, 0 failed, 1 ignored (the synthetic CPU release benchmark), 110 filtered out. This is a Windows test binary running through Proton on NVIDIA, not a native Windows run. I did not use the ignored benchmark for performance claims because Proton timings would not be comparable to the native Windows measurements.
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:43 UTC · original · reviewed

AI-assisted static review (ChatGPT); I inspected the locking path but did not run tests.

**@⁠gut0to** on GitHub · 2026-11-27 14:43 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/152#pullrequestreview-6089812178) · **reviewed** AI-assisted static review (ChatGPT); I inspected the locking path but did not run tests.
@ -171,0 +175,4 @@
/// Whether a host copy or resolve has written `resource`.
fn is_host_written(resource: usize) -> bool {
if !HOST_WRITTEN_ANY.load(Ordering::Acquire) {
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:43 UTC · original

This fast path can observe false after the resource has been inserted into HOST_WRITTEN but before HOST_WRITTEN_ANY.store(true): the writer holds the mutex across both operations, while this branch returns without taking that mutex. That contradicts the comment below and can classify a host-written texture as untouched. Could the flag be published before insertion while holding the lock, or could the false path synchronize with the writer, with a deterministic test for this interleaving?

**@⁠gut0to** on GitHub · 2026-11-27 14:43 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/152#discussion_r4720713615) This fast path can observe `false` after the resource has been inserted into `HOST_WRITTEN` but before `HOST_WRITTEN_ANY.store(true)`: the writer holds the mutex across both operations, while this branch returns without taking that mutex. That contradicts the comment below and can classify a host-written texture as untouched. Could the flag be published before insertion while holding the lock, or could the false path synchronize with the writer, with a deterministic test for this interleaving?
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/152/head:github-bot/gh-152'
git switch 'github-bot/gh-152'

Merge

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