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

Open
Adika713 wants to merge 1 commit from upstream-pr/24 into main
Adika713 commented 2026-11-25 19:08:40 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Adika713 on 2026-11-25T19:08:40Z.


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.

<!-- greyfinch-sync:DexNom/VIctory:issue:5497479832 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/24). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T19:08:40Z. --- 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.
andrewDoing commented 2026-11-26 23:21:58 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by andrewDoing on 2026-11-26T23:21:58Z.


Independent native Windows / RTX 5070 check at 3bbb525: used two real committed textures with GPU resources for 10,000 barrier-synchronized rounds. One thread marked the new texture via host_written() while another removed the previous sole member via forget(); a third checked both memberships after each pair. All 20,000 checks passed, and both textures were absent after their final releases. This exercises the concurrent handoff identified as untested in the PR, but is not proof of all interleavings or a gameplay timing measurement.

Verification was AI-assisted with GPT-6.2 Astra.

<!-- greyfinch-sync:DexNom/VIctory:comment:7205479928 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/24#issuecomment-7205479928). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-26T23:21:58Z. --- Independent native Windows / RTX 5070 check at `3bbb525`: used two real committed textures with GPU resources for 10,000 barrier-synchronized rounds. One thread marked the new texture via `host_written()` while another removed the previous sole member via `forget()`; a third checked both memberships after each pair. All 20,000 checks passed, and both textures were absent after their final releases. This exercises the concurrent handoff identified as untested in the PR, but is not proof of all interleavings or a gameplay timing measurement. Verification was AI-assisted with GPT-6.2 Astra.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/24:upstream-pr/24'
git switch 'upstream-pr/24'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/24'
git switch 'upstream-pr/24'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/24'
git switch 'upstream-pr/24'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/24'
git switch 'main'
git merge --squash 'upstream-pr/24'
git switch 'main'
git merge --ff-only 'upstream-pr/24'
git switch 'main'
git merge 'upstream-pr/24'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
DexNom/VIctory!24
No description provided.