Stream shader archive scans in bounded batches #1185

Closed
github-bot wants to merge 3 commits from gh-pr/1185/head into gh-pr/1185/base
Owner

@⁠Jitheswar on GitHub · 2026-11-24 16:22 UTC · original
shader-archive-streaming → main · +833 −253 · 5 files · 3 commits · closed without merging

victory shader-info and victory translate read each input file whole and built a file-wide index before looking at any shader. On the title's shader archive that holds the whole file in memory, several hundred MB of RSS, for an offline scan.

What changes

  • apps/victory/src/shader/source.rs scans a file in 1 MiB chunks for the container and record markers. It reads three bytes of lookahead so a marker straddling a chunk edge is found once, by the chunk that owns its start. It hands the caller batches of at most 16 MiB or 1,024 sources.
  • A batch is released before the next candidate is read, so an oversized single source never stays resident while the scan reads on. The old 2 GiB cap on one encoded shader stays.
  • sgd5::read_index reads a shader database's index by seeking past the compressed shaders instead of loading them. Indexed records keep their order, names and engine hashes. A database with malformed effects is rejected, as the slice parser does, and the scan then falls back to markers.
  • shader-info and translate use it. --disasm output is unchanged.

Tests (synthetic): markers found once across chunk boundaries; indexed records preferred, with their engine hashes kept; an oversized source visited before the next candidate is read (an I/O failure is injected at the next header); large source sets visited in bounded batches.

Checked with the game's files (Grand Theft Auto VI, Xbox Series 1.0.2.1, my own dump; offline scan only, no game data in the PR): shader-info on the shader archive gives the identical summary on 940d32f and on this branch, 26,503 containers and 26,698 decoded programs. Peak RSS for that scan fell from about 417 MiB to about 41 MiB (measured on the earlier base).

Rebased onto 940d32f; upstream's new --disasm stage-I/O lines are kept. The victory app tests pass for the Windows target under Proton (14, including the four above). Windows-target clippy -D warnings is clean.

AI-assisted (Claude Code, Codex).

🤖 Generated with Claude Code

**@⁠Jitheswar** on GitHub · 2026-11-24 16:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185) `shader-archive-streaming` → `main` · +833 −253 · 5 files · 3 commits · closed without merging `victory shader-info` and `victory translate` read each input file whole and built a file-wide index before looking at any shader. On the title's shader archive that holds the whole file in memory, several hundred MB of RSS, for an offline scan. **What changes** - `apps/victory/src/shader/source.rs` scans a file in 1 MiB chunks for the container and record markers. It reads three bytes of lookahead so a marker straddling a chunk edge is found once, by the chunk that owns its start. It hands the caller batches of at most 16 MiB or 1,024 sources. - A batch is released before the next candidate is read, so an oversized single source never stays resident while the scan reads on. The old 2 GiB cap on one encoded shader stays. - `sgd5::read_index` reads a shader database's index by seeking past the compressed shaders instead of loading them. Indexed records keep their order, names and engine hashes. A database with malformed effects is rejected, as the slice parser does, and the scan then falls back to markers. - `shader-info` and `translate` use it. `--disasm` output is unchanged. **Tests (synthetic):** markers found once across chunk boundaries; indexed records preferred, with their engine hashes kept; an oversized source visited before the next candidate is read (an I/O failure is injected at the next header); large source sets visited in bounded batches. **Checked with the game's files** (Grand Theft Auto VI, Xbox Series 1.0.2.1, my own dump; offline scan only, no game data in the PR): `shader-info` on the shader archive gives the identical summary on `940d32f` and on this branch, 26,503 containers and 26,698 decoded programs. Peak RSS for that scan fell from about 417 MiB to about 41 MiB (measured on the earlier base). Rebased onto `940d32f`; upstream's new `--disasm` stage-I/O lines are kept. The `victory` app tests pass for the Windows target under Proton (14, including the four above). Windows-target clippy `-D warnings` is clean. AI-assisted (Claude Code, Codex). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:22:51 +00:00
github-bot closed this pull request 2026-11-26 04:22:51 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at c12892c: cargo test -p victory -p victory-game -p victory-shader passes, 125 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185#issuecomment-7140024444) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at c12892c: `cargo test -p victory -p victory-game -p victory-shader` passes, 125 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Jitheswar on GitHub · 2026-11-24 20:55 UTC · original

Follow-up f56f478 flushes a full batch before the scanner reads another candidate. This keeps an oversized singleton from being retained during the next candidate read. The synthetic regression injects an I/O failure at that next header and checks that the completed batch has already been visited.

I compared shader-info on the retail GTA VI Xbox Series 1.0.2.1 shader archive, using the same #1017 Linux build fixes for both builds. Both found 26,503 containers and decoded 26,698 programs. Peak process RSS was 426,856 KiB for the baseline and 41,512 KiB for the streaming branch. This was an offline scan.

Linux workspace tests passed with #1017 applied locally, and the scanner regression passed in the Windows-target test executable under Proton. AI-assisted with Codex. No game data is included.

**@⁠Jitheswar** on GitHub · 2026-11-24 20:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185#issuecomment-7144234031) Follow-up `f56f478` flushes a full batch before the scanner reads another candidate. This keeps an oversized singleton from being retained during the next candidate read. The synthetic regression injects an I/O failure at that next header and checks that the completed batch has already been visited. I compared `shader-info` on the retail GTA VI Xbox Series 1.0.2.1 shader archive, using the same #1017 Linux build fixes for both builds. Both found 26,503 containers and decoded 26,698 programs. Peak process RSS was 426,856 KiB for the baseline and 41,512 KiB for the streaming branch. This was an offline scan. Linux workspace tests passed with #1017 applied locally, and the scanner regression passed in the Windows-target test executable under Proton. AI-assisted with Codex. No game data is included.
Author
Owner

@⁠Jitheswar on GitHub · 2026-11-24 21:57 UTC · original

Rebased onto 70564ae. Streaming now honors upstream’s SGD5 tables when present, preserving record order, names and engine hashes, with marker fallback when no table parses. The standard shader survey, translation, and cache warm-up scan shader payloads in batches. The dedicated effect and pipeline-pack readers keep their existing parsing paths.

The Windows-target workspace suite under Proton added four passing synthetic scanner tests and reproduced the same 66 failures as the untouched base. The asset-policy check passed. The offline shader-info output for the retail GTA VI Xbox Series 1.0.2.1 shader archive matched upstream exactly, including 26,503 containers and 26,698 decoded programs. No game files or extracted assets are included. AI-assisted with Codex.

**@⁠Jitheswar** on GitHub · 2026-11-24 21:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185#issuecomment-7145615766) Rebased onto `70564ae`. Streaming now honors upstream’s SGD5 tables when present, preserving record order, names and engine hashes, with marker fallback when no table parses. The standard shader survey, translation, and cache warm-up scan shader payloads in batches. The dedicated effect and pipeline-pack readers keep their existing parsing paths. The Windows-target workspace suite under Proton added four passing synthetic scanner tests and reproduced the same 66 failures as the untouched base. The asset-policy check passed. The offline `shader-info` output for the retail GTA VI Xbox Series 1.0.2.1 shader archive matched upstream exactly, including 26,503 containers and 26,698 decoded programs. No game files or extracted assets are included. AI-assisted with Codex.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:39 UTC · original · edited 2026-11-25 02:24 UTC

Automated triage for the maintainers.

Recommended for a maintainer's look. shader-info, translate and the cache warm-up now read shader archives through apps/victory/src/shader/source.rs, a 1 MiB chunked marker scan that hands out bounded batches. They used to read each whole file. sgd5::read_index reads a database's index by seeking past the packed shaders, and keeps record order, names and engine hashes. The reported peak RSS drops from about 417 MiB to 41 MiB, and shader-info gives identical totals on the title's archive. It is offline tooling only. The tests cover markers across chunk edges, a preferred index, and batch bounds. Two points for the reviewer:

  • IndexCursor::skip_effect duplicates the layout effect() parses, so the two have to stay in sync.
  • translate and the warm-up no longer skip files over MAX_FILE (2 GiB), while shader-info's directory walk still does. Please confirm that difference is intended.

It overlaps translate.rs with #1017 and #1183. CI is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185#issuecomment-7148735179) · edited 2026-11-25 02:24 UTC <!-- victory-triage v1 head=6dbfe79c46bec26ad7c7b9b960b6f357e1592dbb verdict=merge-candidate at=2026-11-25T02:20:29Z --> Automated triage for the maintainers. Recommended for a maintainer's look. `shader-info`, `translate` and the cache warm-up now read shader archives through `apps/victory/src/shader/source.rs`, a 1 MiB chunked marker scan that hands out bounded batches. They used to read each whole file. `sgd5::read_index` reads a database's index by seeking past the packed shaders, and keeps record order, names and engine hashes. The reported peak RSS drops from about 417 MiB to 41 MiB, and `shader-info` gives identical totals on the title's archive. It is offline tooling only. The tests cover markers across chunk edges, a preferred index, and batch bounds. Two points for the reviewer: - `IndexCursor::skip_effect` duplicates the layout `effect()` parses, so the two have to stay in sync. - `translate` and the warm-up no longer skip files over `MAX_FILE` (2 GiB), while `shader-info`'s directory walk still does. Please confirm that difference is intended. It overlaps `translate.rs` with #1017 and #1183. CI is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 02:54 UTC · original

Independent run on Windows 10 19045, your head 6dbfe79:

  • cargo test -p victory --bins --locked: 14 passed, 0 failed, including shader::source::tests::prefers_indexed_records_and_preserves_their_engine_hashes.
  • cargo test -p victory-game --lib: 15 passed, 0 failed.

(cargo test -p victory-shader --lib fails 75 here, but that is this host having no SM 6.6 device — the same on unmodified main, tracked in #1829/#1991 — not your change. victory-shader's own dxbc tests are inside that 172 that pass.)

The chunked scan reads correct in the diff: the 3-byte lookahead means a marker straddling a 1 MiB edge is found by the chunk owning its start, each batch releases before the next source is read, and the 2 GiB per-source cap is unchanged. I have not run it against a real shader archive (I only have the title dump, and victory translate over it takes longer than a review pass); if you want that measurement, say so and I will run it here with --list and report RSS and wall time against your branch and main.

**@⁠Calvix2k** on GitHub · 2026-11-25 02:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185#issuecomment-7151336196) Independent run on Windows 10 19045, your head `6dbfe79`: - `cargo test -p victory --bins --locked`: **14 passed, 0 failed**, including `shader::source::tests::prefers_indexed_records_and_preserves_their_engine_hashes`. - `cargo test -p victory-game --lib`: **15 passed, 0 failed**. (`cargo test -p victory-shader --lib` fails 75 here, but that is this host having no SM 6.6 device — the same on unmodified `main`, tracked in #1829/#1991 — not your change. `victory-shader`'s own `dxbc` tests are inside that 172 that pass.) The chunked scan reads correct in the diff: the 3-byte lookahead means a marker straddling a 1 MiB edge is found by the chunk owning its start, each batch releases before the next source is read, and the 2 GiB per-source cap is unchanged. I have not run it against a real shader archive (I only have the title dump, and `victory translate` over it takes longer than a review pass); if you want that measurement, say so and I will run it here with `--list` and report RSS and wall time against your branch and `main`.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 03:16 UTC · original

Measured here, as offered — this is the real archive, not a synthetic file.

main 940d32f this head 6dbfe79
wall time 199.9 s 158.5 s (−20.7%)
peak working set 992.1 MB 613.4 MB (−38.2%)
programs listed 25,908 25,908

Setup: Windows 10 19045, Ryzen 7 5800X, shaders.rpf from the 1.0.2.1 dump (411,695,600 bytes), release builds of each commit into the same target dir, victory translate E:\…\shaders.rpf --list --jobs 10, peak working set sampled every 200 ms from the process.

Correctness of the scan is unchanged: the two listings have the same 25,908 lines, and the refusal summary has the same counts (195 SGPR addresses, 40 lane-mask joins, 36 descriptors read as data, 8 lane masks read as data, …); only the example program quoted for each kind differs, because the chunked scan reaches them in a different order.

Caveat: one run each, no --validate (the validator would dominate wall time and is orthogonal), and the host was otherwise idle. The 20% wall-time gain is larger than I expected for an I/O-bound scan — if it holds on a second run it is worth mentioning in the body, since the issue is framed as memory only.

**@⁠Calvix2k** on GitHub · 2026-11-25 03:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1185#issuecomment-7151755144) Measured here, as offered — this is the real archive, not a synthetic file. | | `main` `940d32f` | this head `6dbfe79` | |---|---|---| | wall time | **199.9 s** | **158.5 s** (−20.7%) | | peak working set | **992.1 MB** | **613.4 MB** (−38.2%) | | programs listed | 25,908 | 25,908 | Setup: Windows 10 19045, Ryzen 7 5800X, `shaders.rpf` from the 1.0.2.1 dump (411,695,600 bytes), release builds of each commit into the same target dir, `victory translate E:\…\shaders.rpf --list --jobs 10`, peak working set sampled every 200 ms from the process. Correctness of the scan is unchanged: the two listings have the same 25,908 lines, and the refusal summary has the same counts (195 SGPR addresses, 40 lane-mask joins, 36 descriptors read as data, 8 lane masks read as data, …); only the example program quoted for each kind differs, because the chunked scan reaches them in a different order. Caveat: one run each, no `--validate` (the validator would dominate wall time and is orthogonal), and the host was otherwise idle. The 20% wall-time gain is larger than I expected for an I/O-bound scan — if it holds on a second run it is worth mentioning in the body, since the issue is framed as memory only.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1185
No description provided.