Shaders: pair packed fp16 pixel inputs with unlisted signature rows #176

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

@⁠Yaekai on GitHub · 2026-11-24 01:07 UTC · original
Yaekai:feat/shader-half-inputs → main · +132 −7 · 1 files · 2 commits · closed without merging

In crates/victory-shader/src/emit/lower.rs, pixel shader inputs with fp16 and pack2 set sometimes leave PsInput.row2 == PsInput.row even when a second 16-bit signature row is packed into the trailing channels of the same hardware attribute (for example, row 0 with row2 == 0 packing unlisted row 1, or row 3 with row2 == 3 packing unlisted row 6). Previously, interp() treated row2 == row as having no partner (None), causing emit: a packed input half no element holds.

This mirrors the existing half_outputs pairing logic for pixel inputs via a new half_inputs helper:

  • Collects all 16-bit (half && kind == 0) signature rows not named as i.row by any PsInput and not explicitly claimed as i.row2 (where i.row2 != i.row).
  • For each fp16 PsInput in row order: uses i.row2 when i.row2 != i.row, and otherwise pairs pack2 entries with the next available unlisted 16-bit signature row > i.row.
  • Adds a unit test packed_half_inputs_pair_unlisted_rows covering explicit row2 preservation and unlisted-row fallback.

Verification

  • cargo test -p victory-shader — 70/70 passed.
  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower.rs — clean.
  • victory translate --validate on shaders.rpf (26,084 programs): reduced emit: a packed input half no element holds from 172 → 6, increasing complete VS/PS shaders from 12,316 → 12,433 emitted (+117) and 12,208 → 12,325 dxil.dll-validated (+117, 100% validation pass rate, 0 new validator errors).
**@⁠Yaekai** on GitHub · 2026-11-24 01:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/176) `Yaekai:feat/shader-half-inputs` → `main` · +132 −7 · 1 files · 2 commits · closed without merging In `crates/victory-shader/src/emit/lower.rs`, pixel shader inputs with `fp16` and `pack2` set sometimes leave `PsInput.row2 == PsInput.row` even when a second 16-bit signature row is packed into the trailing channels of the same hardware attribute (for example, `row 0` with `row2 == 0` packing unlisted `row 1`, or `row 3` with `row2 == 3` packing unlisted `row 6`). Previously, `interp()` treated `row2 == row` as having no partner (`None`), causing `emit: a packed input half no element holds`. This mirrors the existing `half_outputs` pairing logic for pixel inputs via a new `half_inputs` helper: - Collects all 16-bit (`half && kind == 0`) signature rows not named as `i.row` by any `PsInput` and not explicitly claimed as `i.row2` (where `i.row2 != i.row`). - For each `fp16` `PsInput` in row order: uses `i.row2` when `i.row2 != i.row`, and otherwise pairs `pack2` entries with the next available unlisted 16-bit signature row `> i.row`. - Adds a unit test `packed_half_inputs_pair_unlisted_rows` covering explicit `row2` preservation and unlisted-row fallback. ### Verification - `cargo test -p victory-shader` — 70/70 passed. - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower.rs` — clean. - `victory translate --validate` on `shaders.rpf` (26,084 programs): reduced `emit: a packed input half no element holds` from **172 → 6**, increasing complete VS/PS shaders from **12,316 → 12,433 emitted (+117)** and **12,208 → 12,325 `dxil.dll`-validated (+117, 100% validation pass rate, 0 new validator errors)**.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:28 +00:00
github-bot closed this pull request 2026-11-26 03:53:28 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:19 UTC · original

Tested a823dfb on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the 1 test this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#issuecomment-7118989016) Tested `a823dfb` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the 1 test this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
Author
Owner

@⁠Yaekai on GitHub · 2026-11-24 01:47 UTC · original

Thanks for the review @⁠raffclar! Addressed all three points in f0e7745:

  1. Clarified row2 == row: added comments explaining that in the console's PsInput table, row2 repeats row when no distinct partner row is named.
  2. Duplicates: deduplicated halves by i.row keeping the first fp16 entry (matching the previous .find() behaviour) so duplicates neither overwrite earlier entries nor consume an extra free partner row.
  3. Bounding fallback partners: restricted fallback selection to r > i.row && r < next_fp16 (the next fp16 input row) so an earlier unpaired fp16 input cannot steal a later fp16 input's partner, while still allowing 32-bit PsInput rows in between (e.g. row 3 pairing with unlisted row 6 across 32-bit rows 4–5).

Added unit test coverage for both duplicate rows and the next_fp16 bound (cargo test -p victory-shader: 70/70 passed) and re-verified victory translate --validate on shaders.rpf (still 172 → 6, +117 VS/PS emitted & dxil.dll-validated, 0 new validator errors).

**@⁠Yaekai** on GitHub · 2026-11-24 01:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#issuecomment-7119452826) Thanks for the review @⁠raffclar! Addressed all three points in `f0e7745`: 1. **Clarified `row2 == row`**: added comments explaining that in the console's `PsInput` table, `row2` repeats `row` when no distinct partner row is named. 2. **Duplicates**: deduplicated `halves` by `i.row` keeping the **first** `fp16` entry (matching the previous `.find()` behaviour) so duplicates neither overwrite earlier entries nor consume an extra free partner row. 3. **Bounding fallback partners**: restricted fallback selection to `r > i.row && r < next_fp16` (the next `fp16` input row) so an earlier unpaired `fp16` input cannot steal a later `fp16` input's partner, while still allowing 32-bit `PsInput` rows in between (e.g. `row 3` pairing with unlisted `row 6` across 32-bit rows 4–5). Added unit test coverage for both duplicate rows and the `next_fp16` bound (`cargo test -p victory-shader`: 70/70 passed) and re-verified `victory translate --validate` on `shaders.rpf` (still **172 → 6**, **+117** VS/PS emitted & `dxil.dll`-validated, 0 new validator errors).
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 08:43 UTC · original

Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines created on an AMD RX 9070, Adrenalin, Windows 11; dxil.dll from SDK 10.0.26100), against main 1f858b0. Counts are emitted / validated / pipelines.

VS/PS "packed input half no element holds"
main 12272 / 12172 / 12272 172
#621 12395 / 12295 / 12395 0
#176 12389 / 12289 / 12389 6
#592 12389 / 12289 / 12389 6

#621 clears all 172 (+123 validated pixel programs); #176 and #592 give identical results (+117, 6 left). CS and MS unchanged in all three.

**@⁠slint6614-dev** on GitHub · 2026-11-24 08:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#issuecomment-7126491524) Measured on the full retail shader pack (26,503 containers) with `victory translate --validate --pipelines` (pipelines created on an AMD RX 9070, Adrenalin, Windows 11; dxil.dll from SDK 10.0.26100), against main 1f858b0. Counts are emitted / validated / pipelines. | | VS/PS | "packed input half no element holds" | |---|---|---| | main | 12272 / 12172 / 12272 | 172 | | #621 | 12395 / **12295** / 12395 | 0 | | #176 | 12389 / 12289 / 12389 | 6 | | #592 | 12389 / 12289 / 12389 | 6 | #621 clears all 172 (+123 validated pixel programs); #176 and #592 give identical results (+117, 6 left). CS and MS unchanged in all three.
Author
Owner

@⁠justlovett0 on GitHub · 2026-11-24 18:48 UTC · original

Verified + integrated. Stack: main ffe310e + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals.

Packed fp16 pixel-input pairing merged (runtime kept; a lower.rs test-module conflict resolved to our tests). No regressions; compute emission 493/560.

AI use: Qwen Code; local measurements. No game data posted.

**@⁠justlovett0** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#issuecomment-7141180179) **Verified + integrated.** Stack: main `ffe310e` + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals. Packed fp16 pixel-input pairing merged (runtime kept; a lower.rs test-module conflict resolved to our tests). No regressions; compute emission 493/560. AI use: Qwen Code; local measurements. No game data posted.
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 01:10 UTC · original · edited 2026-11-24 01:12 UTC
On crates/victory-shader/src/emit/lower.rs line 352 (outdated):

@@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti
         .collect()
 }
 
+/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's
+/// partner is `row2` when distinct from `row`, else the next 16-bit row of the
+/// signature that no input entry names or claims as `row2`, taken in row order.
+fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> {
+    let StageIo::Ps {
+        inputs: entries, ..
+    } = io
+    else {
+        return HashMap::new();
+    };
+    let mut free: Vec<u8> = inputs
+        .iter()
+        .filter(|e| e.half && e.kind == 0)
+        .filter_map(|e| u8::try_from(e.row?).ok())
+        .filter(|&r| {
+            !entries
+                .iter()
+                .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r))
+        })
+        .collect();
+    free.sort_unstable();
+    free.dedup();
+    let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect();
+    halves.sort_by_key(|i| i.row);
+    halves
+        .into_iter()
+        .map(|i| {
+            let b = if !i.pack2 {

Do you really mean row2 == row == "no partner given" in the console format? Just needs clarifying this is pretty hard to read. Maybe a small STE100 comment on a line before the method chaining

**@⁠raffclar** on GitHub · 2026-11-24 01:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#discussion_r4674204327) · edited 2026-11-24 01:12 UTC On `crates/victory-shader/src/emit/lower.rs` line 352 (outdated): ```diff @@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti .collect() } +/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's +/// partner is `row2` when distinct from `row`, else the next 16-bit row of the +/// signature that no input entry names or claims as `row2`, taken in row order. +fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> { + let StageIo::Ps { + inputs: entries, .. + } = io + else { + return HashMap::new(); + }; + let mut free: Vec<u8> = inputs + .iter() + .filter(|e| e.half && e.kind == 0) + .filter_map(|e| u8::try_from(e.row?).ok()) + .filter(|&r| { + !entries + .iter() + .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r)) + }) + .collect(); + free.sort_unstable(); + free.dedup(); + let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect(); + halves.sort_by_key(|i| i.row); + halves + .into_iter() + .map(|i| { + let b = if !i.pack2 { ``` Do you really mean row2 == row == "no partner given" in the console format? Just needs clarifying this is pretty hard to read. Maybe a small STE100 comment on a line before the method chaining
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 01:13 UTC · original
On crates/victory-shader/src/emit/lower.rs line 363 (outdated):

@@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti
         .collect()
 }
 
+/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's
+/// partner is `row2` when distinct from `row`, else the next 16-bit row of the
+/// signature that no input entry names or claims as `row2`, taken in row order.
+fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> {
+    let StageIo::Ps {
+        inputs: entries, ..
+    } = io
+    else {
+        return HashMap::new();
+    };
+    let mut free: Vec<u8> = inputs
+        .iter()
+        .filter(|e| e.half && e.kind == 0)
+        .filter_map(|e| u8::try_from(e.row?).ok())
+        .filter(|&r| {
+            !entries
+                .iter()
+                .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r))
+        })
+        .collect();
+    free.sort_unstable();
+    free.dedup();
+    let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect();
+    halves.sort_by_key(|i| i.row);
+    halves
+        .into_iter()
+        .map(|i| {
+            let b = if !i.pack2 {
+                None
+            } else if i.row2 != i.row {
+                Some(i.row2)
+            } else {
+                free.iter()
+                    .position(|&r| r > i.row)
+                    .map(|idx| free.remove(idx))
+            };
+            (i.row, (i.pack2, b))
+        })
+        .collect()

Also what about dupes. The old code used the first one and now this uses the last for dupes. Also each duplicate takes up a free row so later input can run out of partners.

**@⁠raffclar** on GitHub · 2026-11-24 01:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#discussion_r4674228783) On `crates/victory-shader/src/emit/lower.rs` line 363 (outdated): ```diff @@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti .collect() } +/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's +/// partner is `row2` when distinct from `row`, else the next 16-bit row of the +/// signature that no input entry names or claims as `row2`, taken in row order. +fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> { + let StageIo::Ps { + inputs: entries, .. + } = io + else { + return HashMap::new(); + }; + let mut free: Vec<u8> = inputs + .iter() + .filter(|e| e.half && e.kind == 0) + .filter_map(|e| u8::try_from(e.row?).ok()) + .filter(|&r| { + !entries + .iter() + .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r)) + }) + .collect(); + free.sort_unstable(); + free.dedup(); + let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect(); + halves.sort_by_key(|i| i.row); + halves + .into_iter() + .map(|i| { + let b = if !i.pack2 { + None + } else if i.row2 != i.row { + Some(i.row2) + } else { + free.iter() + .position(|&r| r > i.row) + .map(|idx| free.remove(idx)) + }; + (i.row, (i.pack2, b)) + }) + .collect() ``` Also what about dupes. The old code used the first one and now this uses the last for dupes. Also each duplicate takes up a free row so later input can run out of partners.
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 01:14 UTC · original
On crates/victory-shader/src/emit/lower.rs line 358 (outdated):

@@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti
         .collect()
 }
 
+/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's
+/// partner is `row2` when distinct from `row`, else the next 16-bit row of the
+/// signature that no input entry names or claims as `row2`, taken in row order.
+fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> {
+    let StageIo::Ps {
+        inputs: entries, ..
+    } = io
+    else {
+        return HashMap::new();
+    };
+    let mut free: Vec<u8> = inputs
+        .iter()
+        .filter(|e| e.half && e.kind == 0)
+        .filter_map(|e| u8::try_from(e.row?).ok())
+        .filter(|&r| {
+            !entries
+                .iter()
+                .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r))
+        })
+        .collect();
+    free.sort_unstable();
+    free.dedup();
+    let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect();
+    halves.sort_by_key(|i| i.row);
+    halves
+        .into_iter()
+        .map(|i| {
+            let b = if !i.pack2 {
+                None
+            } else if i.row2 != i.row {
+                Some(i.row2)
+            } else {
+                free.iter()
+                    .position(|&r| r > i.row)

You should only use a free row that comes before the next named input row

**@⁠raffclar** on GitHub · 2026-11-24 01:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#discussion_r4674233239) On `crates/victory-shader/src/emit/lower.rs` line 358 (outdated): ```diff @@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti .collect() } +/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's +/// partner is `row2` when distinct from `row`, else the next 16-bit row of the +/// signature that no input entry names or claims as `row2`, taken in row order. +fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> { + let StageIo::Ps { + inputs: entries, .. + } = io + else { + return HashMap::new(); + }; + let mut free: Vec<u8> = inputs + .iter() + .filter(|e| e.half && e.kind == 0) + .filter_map(|e| u8::try_from(e.row?).ok()) + .filter(|&r| { + !entries + .iter() + .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r)) + }) + .collect(); + free.sort_unstable(); + free.dedup(); + let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect(); + halves.sort_by_key(|i| i.row); + halves + .into_iter() + .map(|i| { + let b = if !i.pack2 { + None + } else if i.row2 != i.row { + Some(i.row2) + } else { + free.iter() + .position(|&r| r > i.row) ``` You should only use a free row that comes before the next named input row
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 01:15 UTC · original
On crates/victory-shader/src/emit/lower.rs line 358 (outdated):

@@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti
         .collect()
 }
 
+/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's
+/// partner is `row2` when distinct from `row`, else the next 16-bit row of the
+/// signature that no input entry names or claims as `row2`, taken in row order.
+fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> {
+    let StageIo::Ps {
+        inputs: entries, ..
+    } = io
+    else {
+        return HashMap::new();
+    };
+    let mut free: Vec<u8> = inputs
+        .iter()
+        .filter(|e| e.half && e.kind == 0)
+        .filter_map(|e| u8::try_from(e.row?).ok())
+        .filter(|&r| {
+            !entries
+                .iter()
+                .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r))
+        })
+        .collect();
+    free.sort_unstable();
+    free.dedup();
+    let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect();
+    halves.sort_by_key(|i| i.row);
+    halves
+        .into_iter()
+        .map(|i| {
+            let b = if !i.pack2 {
+                None
+            } else if i.row2 != i.row {
+                Some(i.row2)
+            } else {
+                free.iter()
+                    .position(|&r| r > i.row)

Otherwise an earlier input can take a free row that really belongs to a later input. Causes wrong row to be read or fails

**@⁠raffclar** on GitHub · 2026-11-24 01:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/176#discussion_r4674237603) On `crates/victory-shader/src/emit/lower.rs` line 358 (outdated): ```diff @@ -319,6 +322,47 @@ fn half_outputs(io: &StageIo, outputs: &[SigElement]) -> HashMap<u8, (bool, Opti .collect() } +/// Pixel inputs of 16-bit values (see [`Lower::half_inputs`]): a packed row's +/// partner is `row2` when distinct from `row`, else the next 16-bit row of the +/// signature that no input entry names or claims as `row2`, taken in row order. +fn half_inputs(io: &StageIo, inputs: &[SigElement]) -> HashMap<u8, (bool, Option<u8>)> { + let StageIo::Ps { + inputs: entries, .. + } = io + else { + return HashMap::new(); + }; + let mut free: Vec<u8> = inputs + .iter() + .filter(|e| e.half && e.kind == 0) + .filter_map(|e| u8::try_from(e.row?).ok()) + .filter(|&r| { + !entries + .iter() + .any(|i| i.row == r || (i.fp16 && i.pack2 && i.row2 != i.row && i.row2 == r)) + }) + .collect(); + free.sort_unstable(); + free.dedup(); + let mut halves: Vec<_> = entries.iter().filter(|i| i.fp16).collect(); + halves.sort_by_key(|i| i.row); + halves + .into_iter() + .map(|i| { + let b = if !i.pack2 { + None + } else if i.row2 != i.row { + Some(i.row2) + } else { + free.iter() + .position(|&r| r > i.row) ``` Otherwise an earlier input can take a free row that really belongs to a later input. Causes wrong row to be read or fails

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!176
No description provided.