victory: pin shader::sources (SGD5 records + raw DXBC scan) with unit tests #468

Closed
AnastasisKon wants to merge 1 commit from upstream-pr/468 into main
AnastasisKon commented 2026-11-27 21:34:22 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T21:34:22Z.


What this changes

Refs #465.

apps/victory/src/shader.rs's sources() is the entry point behind victory shader and the pre-build, and nothing held it in place. Six unit tests over synthetic bytes pin what the survey and pre-build counts rest on:

  • empty and non-shader input has no sources, and the SGD5 magic alone is no record;
  • a container stored as is is found at its offset (@0x4) and bytes() returns those bytes;
  • a magic whose header claims more bytes than the file holds, and a magic with no header behind it, are skipped;
  • a packed record found by marker is listed as Source::Packed, its label carries offset and name (@0x2a PS_main_Wrapped), kind is what the object holds, and bytes() unpacks to the container's bytes;
  • a record whose stream is no deflate is still listed, so a run can report it corrupt, and bytes() is None;
  • an SGD5 file yields both its packed records and the containers stored as is, in that order, the second of which Container::parse accepts.

Test-only: a hand-built 0x20-byte DXBC header and a one-block stored-deflate record. No game data, no new dependencies.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass (victory 19, victory-hle 327 + native_probe 17, victory-loader 29).
  • cargo test -p victory -p victory-hle -p xtask on the arm64 host: all pass (14 / 144 + 2 / 6).
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: no warnings.
  • cargo xtask policy: 398 files ok.
  • Ran the game: not needed (test-only).

The tests are known to bite: dropping the Container::parse filter in sources() fails a_magic_whose_container_does_not_parse_is_skipped.

cargo test -p victory-gpu on this Mac: 402 passed, 10 failed, every one of them at dlopen /usr/local/lib/libmetalirconverter.dylib (Apple's Metal Shader Converter is not installed here; #379's wrapper fails fast for the same reason). Unrelated to this change, which touches no GPU code.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md: none added; the record layout the fixtures use is sgd5.rs's documented one
  • New diagnostics are behind a VICTORY_* variable and documented: none added
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5533366907 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/468). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T21:34:22Z. --- ## What this changes Refs #465. `apps/victory/src/shader.rs`'s `sources()` is the entry point behind `victory shader` and the pre-build, and nothing held it in place. Six unit tests over synthetic bytes pin what the survey and pre-build counts rest on: - empty and non-shader input has no sources, and the SGD5 magic alone is no record; - a container stored as is is found at its offset (`@0x4`) and `bytes()` returns those bytes; - a magic whose header claims more bytes than the file holds, and a magic with no header behind it, are skipped; - a packed record found by marker is listed as `Source::Packed`, its label carries offset and name (`@0x2a PS_main_Wrapped`), `kind` is what the object holds, and `bytes()` unpacks to the container's bytes; - a record whose stream is no deflate is still listed, so a run can report it corrupt, and `bytes()` is `None`; - an SGD5 file yields both its packed records and the containers stored as is, in that order, the second of which `Container::parse` accepts. Test-only: a hand-built 0x20-byte DXBC header and a one-block stored-deflate record. No game data, no new dependencies. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: all pass (victory 19, victory-hle 327 + native_probe 17, victory-loader 29). - [x] `cargo test -p victory -p victory-hle -p xtask` on the arm64 host: all pass (14 / 144 + 2 / 6). - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: no warnings. - [x] `cargo xtask policy`: 398 files ok. - [ ] Ran the game: not needed (test-only). The tests are known to bite: dropping the `Container::parse` filter in `sources()` fails `a_magic_whose_container_does_not_parse_is_skipped`. `cargo test -p victory-gpu` on this Mac: 402 passed, 10 failed, every one of them at `dlopen /usr/local/lib/libmetalirconverter.dylib` (Apple's Metal Shader Converter is not installed here; #379's wrapper fails fast for the same reason). Unrelated to this change, which touches no GPU code. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md: none added; the record layout the fixtures use is `sgd5.rs`'s documented one - [x] New diagnostics are behind a `VICTORY_*` variable and documented: none added
AnastasisKon commented 2026-11-27 21:37:59 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T21:37:59Z.


Duplicate of #467: two sessions of the same account picked up #465 and both opened a PR for it. #467 (branch vibe/shader-sources-tests-1705ac) is the one being kept — it covers the same cases plus the bare-magic ones — so I'm closing this one as superseded. The branch is left untouched; reopen if you'd rather keep this one instead.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228618552 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/468#issuecomment-7228618552). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T21:37:59Z. --- Duplicate of #467: two sessions of the same account picked up #465 and both opened a PR for it. #467 (branch vibe/shader-sources-tests-1705ac) is the one being kept — it covers the same cases plus the bare-magic ones — so I'm closing this one as superseded. The branch is left untouched; reopen if you'd rather keep this one instead.
AnastasisKon commented 2026-11-27 21:38:00 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T21:38:00Z.


Superseded by #467 (same issue #465, same author; one change per issue).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228618863 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/468#issuecomment-7228618863). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T21:38:00Z. --- Superseded by #467 (same issue #465, same author; one change per issue).

Pull request closed

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
LakshanSivakumar/Native-Victory-macOS!468
No description provided.