Skip the empty host-written texture lock on reads #24

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

@⁠Adika713 on GitHub · 2026-11-25 19:08 UTC · original
Adika713:perf/dexnom-host-written → main · +114 −13 · 1 files · 1 commits · open

Skip the global texture lock when no host-written textures exist.

Every texture use checked HOST_WRITTEN, a mutex-protected set. In the common
case that set is empty, so the check took a global lock just to find nothing.
An AtomicBool now records whether the set holds anything; readers return
immediately while it is false and take the lock only when it is true. Writers
set and clear the flag while holding the same lock.

What is in it

  • HOST_WRITTEN_ANY atomic flag, kept in sync with HOST_WRITTEN under its
    mutex.
  • is_host_written() used by host_wrote() and upload_from().
  • A regression test for clearing the flag with the last texture, and an
    ignored CPU-only A/B benchmark.

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. BCPack format tables were installed locally with
Initialize-FormatTables.ps1 and were not committed.

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

  • lock: 11.6 / 12.1 / 28.0 ns (third run noisy)
  • atomic: 1.0 / 1.0 / 3.0 ns

Correctness:

  • cargo check -p victory-gpu --lib --tests --locked: exit 0.
  • cargo test -p victory-gpu --lib host_written_tests -- --test-threads=1:
    1 passed, 0 failed, 1 ignored, 191 filtered.
  • Full victory-gpu lib, 20 serial runs: 0 failed; each 189 passed,
    0 failed, 4 ignored, 0 filtered.
  • cargo test --workspace --no-fail-fast --locked: 0 failed suites.

Not tested

  • In-game FPS. No game files or paths were supplied, so this makes no claim
    about frame rate.
  • NVIDIA hardware.
  • Concurrent first insertion and last removal on different threads; the flag
    is written only while the HOST_WRITTEN mutex is held.

AI use

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

**@⁠Adika713** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/DexNom/VIctory/pull/24) `Adika713:perf/dexnom-host-written` → `main` · +114 −13 · 1 files · 1 commits · open Skip the global texture lock when no host-written textures exist. Every texture use checked `HOST_WRITTEN`, a mutex-protected set. In the common case that set is empty, so the check took a global lock just to find nothing. An `AtomicBool` now records whether the set holds anything; readers return immediately while it is false and take the lock only when it is true. Writers set and clear the flag while holding the same lock. **What is in it** - `HOST_WRITTEN_ANY` atomic flag, kept in sync with `HOST_WRITTEN` under its mutex. - `is_host_written()` used by `host_wrote()` and `upload_from()`. - A regression test for clearing the flag with the last texture, and an ignored CPU-only A/B benchmark. **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`. BCPack format tables were installed locally with `Initialize-FormatTables.ps1` and were not committed. `cargo test --release -p victory-gpu --lib host_written_check_fast_path -- --ignored --nocapture --test-threads=1`, 3 runs, median of 5 samples: - lock: **11.6 / 12.1 / 28.0 ns** (third run noisy) - atomic: **1.0 / 1.0 / 3.0 ns** Correctness: - `cargo check -p victory-gpu --lib --tests --locked`: exit 0. - `cargo test -p victory-gpu --lib host_written_tests -- --test-threads=1`: 1 passed, 0 failed, 1 ignored, 191 filtered. - Full `victory-gpu` lib, 20 serial runs: 0 failed; each 189 passed, 0 failed, 4 ignored, 0 filtered. - `cargo test --workspace --no-fail-fast --locked`: 0 failed suites. **Not tested** - In-game FPS. No game files or paths were supplied, so this makes no claim about frame rate. - NVIDIA hardware. - Concurrent first insertion and last removal on different threads; the flag is written only while the `HOST_WRITTEN` mutex is held. **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:31:59 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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