Shaders: check the constant-colour container's layout and hash on every host #262

Closed
SkippySteve wants to merge 2 commits from upstream-pr/262 into main
SkippySteve commented 2026-11-24 01:53:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T01:53:34Z.


constant_color() in victory-shader's emit tests builds a pixel shader container but was only called by the two #[cfg(windows)] tests (stub_pipeline_is_created, constant_color_validates). Off Windows it was dead code, so cargo test/cargo clippy --all-targets -p victory-shader on Linux warned:

warning: function `constant_color` is never used
   --> crates/victory-shader/src/emit/mod.rs:450:8

This PR combines two fixes for that warning (it supersedes #258):

  1. Keep the helper on every host and use it there. Gating constant_color() with #[cfg(windows)] (#258's approach) would have hidden the warning, but left the container untested off Windows. Instead, a new test runs on every host: constant_color_is_a_well_formed_container. It checks what D3D12 and the validator look at before they read the bitcode:

    • the container parses with dxbc::Container, and its size field equals its length
    • the parts are the ones a pixel shader carries, in order: SFI0 ISG1 OSG1 PSV0 HASH DXIL
    • the DXIL part starts with the program header
    • the digest is container::hash of the bytes after it

    It needs neither D3D12 nor dxil.dll.

  2. Import hygiene from #258. bitcode::Attr and shader::Shader are used only by constant_color(), so their imports move from the test module into the helper.

The change is tests only: no runtime code changes.

Testing (Linux)

  • cargo test -p victory-shader: 57 passed (was 56)
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean (it failed before because of the warning)
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean
  • cargo fmt -p victory-shader --check, cargo xtask policy: clean
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572809342 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/262). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T01:53:34Z. --- `constant_color()` in `victory-shader`'s emit tests builds a pixel shader container but was only called by the two `#[cfg(windows)]` tests (`stub_pipeline_is_created`, `constant_color_validates`). Off Windows it was dead code, so `cargo test`/`cargo clippy --all-targets -p victory-shader` on Linux warned: ``` warning: function `constant_color` is never used --> crates/victory-shader/src/emit/mod.rs:450:8 ``` This PR combines two fixes for that warning (it supersedes #258): 1. **Keep the helper on every host and use it there.** Gating `constant_color()` with `#[cfg(windows)]` (#258's approach) would have hidden the warning, but left the container untested off Windows. Instead, a new test runs on every host: `constant_color_is_a_well_formed_container`. It checks what D3D12 and the validator look at before they read the bitcode: - the container parses with `dxbc::Container`, and its size field equals its length - the parts are the ones a pixel shader carries, in order: `SFI0 ISG1 OSG1 PSV0 HASH DXIL` - the `DXIL` part starts with the program header - the digest is `container::hash` of the bytes after it It needs neither D3D12 nor `dxil.dll`. 2. **Import hygiene from #258.** `bitcode::Attr` and `shader::Shader` are used only by `constant_color()`, so their imports move from the test module into the helper. The change is tests only: no runtime code changes. ### Testing (Linux) - `cargo test -p victory-shader`: 57 passed (was 56) - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean (it failed before because of the warning) - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean - `cargo fmt -p victory-shader --check`, `cargo xtask policy`: clean
upstream-sync closed this pull request 2026-11-24 06:52:06 +00:00
SkippySteve commented 2026-11-24 06:55:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T02:32:40Z.


Folded into #326 to keep the PR count down. The commits are unchanged there.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120247858 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/262#issuecomment-7120247858). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T02:32:40Z. --- Folded into #326 to keep the PR count down. The commits are unchanged there.

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
Marvisak/VIctory!262
No description provided.