Bound per-thread shader census records and drain them when output is unavailable #246

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

@⁠feanorsun on GitHub · 2026-11-26 12:36 UTC · original
feanorsun:fix/bound-shader-census-records → main · +156 −16 · 2 files · 1 commits · open

Refs #227

This addresses the Census list item. Thanks to @⁠kekonn for identifying both ways that shader census records could accumulate.

With VICTORY_SHADER_CENSUS enabled, each emitting thread kept every candidate until a caller requested the counts. Game runs can emit candidates without a consumer. In translate, a failed output-file open was cached, so every subsequent translation also returned before consuming its candidates.

Each thread now keeps its most recent 64 candidates in a deque. The next insertion evicts the oldest in constant time. A translation can select an earlier candidate. take searches newest first by embedded bitcode length and hash, then discards the whole batch on a hit, a miss, or a missing bitcode marker. The CLI consumes the batch before checking the cached output file. With the diagnostic disabled it returns before scanning the container, hashing bitcode, or opening a file.

Windows CPU tests

cargo test --offline --locked -j 1 -p victory-shader --lib emit::bitcode::census::tests -- --list
cargo test --offline --locked -j 1 -p victory-shader --lib emit::bitcode::census::tests -- --test-threads=1 --nocapture
cargo test --offline --locked -j 1 -p victory --bin victory translate::tests::census_ -- --list
cargo test --offline --locked -j 1 -p victory --bin victory translate::tests::census_ -- --test-threads=1 --nocapture
Suite Before the fix With the fix
Shader library (4 listed) 3 passed, 1 failed, 306 filtered. After 65 writes the queue still held 65 entries. 4 passed, 306 filtered. The queue held 64. Separate batches confirmed the first candidate was gone and the second was still selectable. Duplicate keys returned the newest matching counts.
CLI (2 listed) 1 passed, 1 failed, 21 filtered. With an existing directory as the output path, the first batch's counts (4 instructions) could be read a second time. 2 passed, 21 filtered. Neither the first batch nor a second batch survived the failed open. With a writable file, the CLI preserved the existing line and appended the full TSV row for the selected earlier candidate.

The CLI cases ran in separate test processes to isolate the cached environment switch and file. All tests used synthetic input on the CPU. git diff --check passed.

**@⁠feanorsun** on GitHub · 2026-11-26 12:36 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/246) `feanorsun:fix/bound-shader-census-records` → `main` · +156 −16 · 2 files · 1 commits · open Refs #227 This addresses the **Census list** item. Thanks to @⁠kekonn for identifying both ways that shader census records could accumulate. With `VICTORY_SHADER_CENSUS` enabled, each emitting thread kept every candidate until a caller requested the counts. Game runs can emit candidates without a consumer. In `translate`, a failed output-file open was cached, so every subsequent translation also returned before consuming its candidates. Each thread now keeps its most recent 64 candidates in a deque. The next insertion evicts the oldest in constant time. A translation can select an earlier candidate. `take` searches newest first by embedded bitcode length and hash, then discards the whole batch on a hit, a miss, or a missing bitcode marker. The CLI consumes the batch before checking the cached output file. With the diagnostic disabled it returns before scanning the container, hashing bitcode, or opening a file. ## Windows CPU tests ```powershell cargo test --offline --locked -j 1 -p victory-shader --lib emit::bitcode::census::tests -- --list cargo test --offline --locked -j 1 -p victory-shader --lib emit::bitcode::census::tests -- --test-threads=1 --nocapture cargo test --offline --locked -j 1 -p victory --bin victory translate::tests::census_ -- --list cargo test --offline --locked -j 1 -p victory --bin victory translate::tests::census_ -- --test-threads=1 --nocapture ``` | Suite | Before the fix | With the fix | | --- | --- | --- | | Shader library (4 listed) | 3 passed, 1 failed, 306 filtered. After 65 writes the queue still held 65 entries. | 4 passed, 306 filtered. The queue held 64. Separate batches confirmed the first candidate was gone and the second was still selectable. Duplicate keys returned the newest matching counts. | | CLI (2 listed) | 1 passed, 1 failed, 21 filtered. With an existing directory as the output path, the first batch's counts (4 instructions) could be read a second time. | 2 passed, 21 filtered. Neither the first batch nor a second batch survived the failed open. With a writable file, the CLI preserved the existing line and appended the full TSV row for the selected earlier candidate. | The CLI cases ran in separate test processes to isolate the cached environment switch and file. All tests used synthetic input on the CPU. `git diff --check` passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:41:32 +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/246/head:github-bot/gh-246'
git switch 'github-bot/gh-246'

Merge

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