Skip to content

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

Closed
Yaekai wants to merge 2 commits into
Marvisak:mainfrom
Yaekai:feat/shader-half-inputs
Closed

Yaekai wants to merge 2 commits into
Marvisak:mainfrom
Yaekai:feat/shader-half-inputs

Conversation

@Yaekai

@Yaekai Yaekai commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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).

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
halves
.into_iter()
.map(|i| {
let b = if !i.pack2 {

@raffclar raffclar Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
};
(i.row, (i.pack2, b))
})
.collect()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
Some(i.row2)
} else {
free.iter()
.position(|&r| r > i.row)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@DaviTostes

Copy link
Copy Markdown

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

No game data used.

Yaekai added a commit to Yaekai/VIctory that referenced this pull request Nov 24, 2026
@Yaekai

Yaekai commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

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).

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…listed signature rows) into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…d-to-end test

fix/packed-half ports upstream Marvisak#176, which integrate/shaders already
merged: its lower.rs is identical to the integration's, so that copy is
kept. What it adds is the end-to-end test of a pixel program whose
packed fp16 input has row2 == row (partner on the unlisted row 6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Ortomanic pushed a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
Ortomanic added a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
PR Marvisak#176's half_inputs pairs a packed fp16 input with an unlisted signature
row; the zero of 'a 16-bit interpolation of a packed padding half reads
zero' stays as the last fallback.
@upipibi upipibi mentioned this pull request Nov 24, 2026
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…entrics)

By AntoninMichelq. Conflicts and what was kept:

- emit/lower.rs (the interpolation's packing): Marvisak#176's `half_inputs`
  lookup, with the PR's `total` closure after it.
- io.rs: Marvisak#179's `Halves` made on demand
  (`halves.get_or_insert_with(|| Halves::new(p))`), with the PR's
  `push_pair`; both sides' tests.
- emit/mod.rs (the PR's test helper `pixel`): Marvisak#566's per-lane argument
  of `resource::track` and Marvisak#223's `Target` argument of `emit`; the
  helper still fails on resources, then I/O, then structure.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@slint6614-dev

Copy link
Copy Markdown

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.

Ortomanic pushed a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
Ortomanic added a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
PR Marvisak#176's half_inputs pairs a packed fp16 input with an unlisted signature
row; the zero of 'a 16-bit interpolation of a packed padding half reads
zero' stays as the last fallback.
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…isak#306 Marvisak#333 Marvisak#105 Marvisak#288 Marvisak#343 Marvisak#353 Marvisak#326 Marvisak#259 Marvisak#179 Marvisak#176 Marvisak#226 Marvisak#286)

Conflicts:
- emit/lower.rs: shader-opcodes and shader-tracking each keyed heap
  handles by the resource properties (a tuple vs two flattened words);
  the same key, shader-tracking's form and comment kept. Lowered's
  test-only fields, test imports and tests of both sides kept.
- emit/wave.rs: tests of both sides kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Halfect Halfect left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU-only re-check of f0e7745, merged onto current main ffe310e locally. No GPU execution and no game data used.

Merge state. GitHub shows the PR as dirty; the only conflict with ffe310e is in the test module of emit/lower.rs, where this PR and main both appended tests at the end. Keeping both sides resolves it; production code merges cleanly. The PR adds no resource::track call, so it is not affected by #801.

Verification on the merged tree (Windows, rustc 1.98.1):

  • packed_half_inputs_pair_unlisted_rows: passed.
  • CPU-only library suite (skipping diff_tests, valu_tests, waterfall_tests, stub_pipeline_is_created): 98 passed, 0 failed, 1 ignored.
  • cargo clippy --locked -p victory-shader --lib --tests -- -D warnings: clean.
  • cargo xtask policy: 154 files ok.

@raffclar's three threads are addressed at this head (they show as outdated but were never resolved):

  1. Readability: the doc comment now states the console's PsInput table repeats row in row2 when no distinct partner is named.
  2. Duplicates: seen.insert(i.row) keeps the first fp16 entry per row, matching the old .find() behaviour, so a duplicate row neither overwrites nor consumes an extra free partner row; the second half of the test covers exactly this.
  3. Free-row stealing: the fallback only takes a free row r with i.row < r < next_fp16, so an earlier unpaired input cannot take a row that belongs to a later fp16 input; the test asserts row 0 does not steal row 3 from row 2.

One behavioural check I ran while reading: for a non-pack2 fp16 input with an explicit row2 != row, the old code passed Some(row2) through while this head stores None. This is a no-op in practice: the only consumer of the partner is packed_half, and it is reached only when pack2 is set (the !pack2 arm uses (attribute.row, h / 2) and never reads the partner).

Context for the maintainer's choice between this and #592+#621: the full-pack measurement by @slint6614-dev shows this PR and #592 are result-identical (+117 validated, 6 remaining explicit-row2 stops). Those 6 are the explicit-second-row padding case handled by #621, which is orthogonal to the pairing rule here and can be rebased onto whichever base lands first.

AI-assisted (Kimi); the builds and test runs are from this machine.

Yaekai added a commit to Yaekai/VIctory that referenced this pull request Nov 24, 2026
@Yaekai
Yaekai force-pushed the feat/shader-half-inputs branch from f0e7745 to eb5ac94 Compare November 24, 2026 14:44
@Yaekai
Yaekai force-pushed the feat/shader-half-inputs branch from eb5ac94 to 7027809 Compare November 24, 2026 15:18
@justlovett0

Copy link
Copy Markdown

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.

MamaLeVrai added a commit to MamaLeVrai/VIctory that referenced this pull request Nov 24, 2026
…with the resolution of its conflicts with Marvisak#176 and Marvisak#1293

Marvisak#453 evaluates the halves of an interpolation on their own when i or j is
computed (SV_Barycentrics, Interp::Weighted). Marvisak#1293 (in the stack) follows
plain v_mov_b32 copies to find the barycentric of a pair, and Marvisak#176 (in the
stack) pairs packed 16-bit pixel inputs through half_inputs. The conflicts
were in io.rs (the pairing), emit/lower.rs (the interpolation lowering and
two spots of the phi and helper code) and emit/shader.rs (the feature
bits). See the pull request text for how each was resolved.

Marvisak#1293's test interpolation_follows_agreeing_phis_and_rejects_mismatched_or_modified_copies
asserted that a computed i (a phi of i and j, a negated copy) is refused;
with Marvisak#453 it is supported as a Weighted pair, so those two assertions now
expect Weighted halves.

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(391 passed, 6 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MamaLeVrai added a commit to MamaLeVrai/VIctory that referenced this pull request Nov 24, 2026
…with the resolution of its conflicts with Marvisak#176 and Marvisak#1293

Marvisak#453 evaluates the halves of an interpolation on their own when i or j is
computed (SV_Barycentrics, Interp::Weighted). Marvisak#1293 (in the stack) follows
plain v_mov_b32 copies to find the barycentric of a pair, and Marvisak#176 (in the
stack) pairs packed 16-bit pixel inputs through half_inputs. The conflicts
were in io.rs (the pairing), emit/lower.rs (the interpolation lowering and
two spots of the phi and helper code) and emit/shader.rs (the feature
bits). See the pull request text for how each was resolved.

Marvisak#1293's test interpolation_follows_agreeing_phis_and_rejects_mismatched_or_modified_copies
asserted that a computed i (a phi of i and j, a negated copy) is refused;
with Marvisak#453 it is supported as a Weighted pair, so those two assertions now
expect Weighted halves.

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(391 passed, 6 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Jarrrk pushed a commit to Jarrrk/VIctory that referenced this pull request Nov 24, 2026
A descriptor dword read only as data no longer stops the program: when no
instruction uses it, the table's range names its kind (eight dwords is an
image, else a structured or raw buffer), and an SMEM buffer load of a
descriptor reads it as a raw buffer view. A constant buffer's descriptor
read as data stays refused.

Pixel inputs of packed 16-bit values now pair each packed row with its
unlisted partner row, as the console's input table does, instead of
refusing a packed input half no element holds.

Ported from Marvisak/VIctory Marvisak#1067, Marvisak#953 and Marvisak#176.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak Marvisak closed this Nov 24, 2026
alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
…ith the unlisted signature row

A pack2 fp16 pixel input with row2 == row (attr1 row 3 mask 0x3 in the 180
pixel shaders failing with "a packed input half no element holds") is two
dwords of halves: dword 0 holds its own half2 row, dword 1 the partner, a
16-bit row of the input signature that no input entry names (row 6 there,
the gap between rows 5 and 7), as half_outputs pairs them on the vertex
side. interp() took row2 == row as "no partner", so dword 1's halves found
no element.

Ports half_inputs from upstream PR Marvisak#176 ("pair packed fp16 pixel inputs
with unlisted signature rows", by Yaekai, both commits incl. its review
follow-up) onto this branch, and adds an end-to-end test that translates a
pixel program with that stage data (inputs, input_addr 4866,
db_shader_control 80) and a signature with half2 rows 3 and 6, reading
attr1.x high, attr1.y and attr1.y high through v_interp_p1ll_f16 /
v_interp_p2_f16. Without the port it fails with the same error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants