Skip to content

victory-shader: emit zero for padding halves in f16 pixel input interpolation - #1291

Closed
bartikele wants to merge 1 commit into
Marvisak:mainfrom
bartikele:shader-packed-input-padding-half
Closed

bartikele wants to merge 1 commit into
Marvisak:mainfrom
bartikele:shader-packed-input-padding-half

Conversation

@bartikele

Copy link
Copy Markdown
Contributor

In Lower::interp, when lowering an _f16 interpolation of a 16-bit pixel input and half(...) returns None (a padding half with no matching SigElement, e.g. the 4th half of a 3-component packed f16 input), emit 0 (self.s.m.i32(0)) instead of failing with a packed input half no element holds.

This matches the existing mode == 1 (flat dword) branch in Lower::interp, which already uses .unwrap_or(z) for padding halves.

Adds unit test emit::tests::reading_a_packed_input_padding_half_yields_zero (including dxil.dll validation).

Tested with:

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings
  • cargo test -p victory-shader --locked

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Independent verification of \94dbc0a\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (including
    eading_a_packed_input_padding_half_yields_zero\ with live \dxil.dll\ validation)
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Clean, minimal 1-line fix in \emit/lower.rs:5543\ with a targeted end-to-end \dxil.dll-validated test.

AI-assisted; synthetic tests only, no game files.

@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown

Heads-up on the overlap: this is the same failure site and motivation as #621 (fix/packed-input-explicit-row2, stacked on #592), so the two PRs collide at lower.rs:5543. The difference is the semantics of the zero, and it matters for correctness.

What this PR does: every None from half() in the _f16 branch becomes zero — regardless of why the half is missing.

What #592 + #621 do instead, and why: #592's body documents why a blanket zero was rejected there ("Why not just read 0"): the diagnostic showed a large share of the failing reads are halves 4–7 next to a 4-channel first row, i.e. the second row's real data that the metadata left out (row2 == row). Reading those as zero silently replaces real interpolated values. fiestorra's probe on the retail pack quantified the split (comment on #592): of 1,048 failing half-reads, 828 have a named second row that is shorter than the read (the case your test fixture exercises, and the one #621 zeroes), but 220 have no partner row in the metadata at all — under this PR those 220 read zero instead of the adjacent row that #592's inferred pairing supplies, which is exactly the silent-data-loss case #592 argued against.

So the stacked pair covers both shapes with the distinction preserved: #592 supplies the omitted second row, and #621 reads zero only for undeclared trailing halves of an explicitly named second row (packing padding), keeping the inferred-partner case strict. #621 carries a synthetic regression for that distinction, plus a DXV-accepted hardware readback (RTX 4090/Wine) and an independent Windows run with a 19-minute live world test.

If the maintainer prefers this simpler one-liner, it would be good to make the trade-off explicit in the body: it re-opens the 220-read class that #592 closes, with zeros where the neighboring row holds real data. Otherwise this duplicates #621 and probably closes in favor of the stack. AI-assisted (Kimi).

@muhammed-aksoy

Copy link
Copy Markdown

I tested 94dbc0a together with #1285 (e34f8c3) on ffe310e. Windows cargo test --locked -p victory-shader -- --test-threads=1 passed 124 tests with zero failures and one ignored at local merge 6d40e1b, with the Windows SDK DXIL validator configured. This covers the padding-half test alongside the SDWA fixtures. AI-assisted.

@adamdotpy

Copy link
Copy Markdown

Reviewed at head 94dbc0a (worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:

1. The change is right and now consistent with the flat path. In the v_interp_* lowering (lower.rs:5543), the packed-f16 path read half(self, h + high)? and refused with "a packed input half no element holds" when the signature row doesn't provide that half. That half is padding of a pack2 attribute, and the input assembler zero-fills undeclared components — the same mode == 1 flat path right below already did .unwrap_or(zero) for both halves. The PR makes the f16 path do the same (unwrap_or_else(|| i32(0))), so packed and flat interpolation now agree instead of one refusing.

2. Verified here. The new reading_a_packed_input_padding_half_yields_zero builds a PS with a packed f16 input (mask 0b0011, pack2), interpolates attr0.y high half (v_interp_p1ll_f16 / v_interp_p2_f16) and exports — emit succeeds and the DXIL passes dxil.dll validation when present (it ran here, no skip). cargo test -p victory-shader --lib padding_half 1 passed; full lib 121 passed / 0 failed / 1 ignored.

3. Checks: cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings clean; cargo build --release -p victory builds; rustfmt --edition 2024 --check — lower.rs shows only main's 3 pre-existing hunks, mod.rs has one new hunk in the added test code (mod.rs:811; main's 671 is pre-existing). Cosmetic only, CI has no fmt job.

4. Note, not a defect: the test pins that emit succeeds and validates, not the emitted zero on the GPU — the zero-fill behavior itself is asserted by inspection of the unwrap_or_else arm. A run_cases-style readback of the interpolated padding half would pin it on hardware if you want that; the flat path's existing behavior is the precedent either way. This turns a refusal into a translation for shaders reading padding halves, which matches how undeclared attribute components read on the console.

Nothing found that would block this.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump, and the shader tests on Ada

Result: +117 programs over main, 0 lost.

Offline. I merged head 94dbc0a onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,841 with this PR.

Failure on main Gained
emit: a packed input half no element holds 117

All 117 are among the programs that #1402 gains through #176. This PR and the packed-half PRs measured in #1247 (#176, #621, #592, 117 programs each) look like one set.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

@sinan-cmyk

Copy link
Copy Markdown

Stacked on #1402: no change

Result: 0 gained, 0 lost, and no failure reason changes on top of #1402. On main this PR gained 117 programs. #1402 already gains the same 117 through #176.

The merge with #1402 conflicts in one hunk of emit/mod.rs, where both sides only add tests. I kept both. cargo test --locked -p victory-shader --lib on the merge: 138 passed, 0 failed.

Method: victory translate --validate --list on shaders.rpf (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs), against #1402 at 2310409. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
Code tree of fxceless/victory-fork 4e17478 (all rendering work by its author and
the VIctory contributors) with, on top:
- AMD fixes: skip of 39f0e9aeb156a61c, 32-lane programs per half wave and NaN/Inf
  filter, configurable texture upload queue, VIctory Marvisak#1599
- upstream VIctory Marvisak#334 (buffer-state tracking) and Marvisak#1271 (globally coherent glc UAVs)
- fork PRs Marvisak#95, Marvisak#71, Marvisak#32, Marvisak#86; VIctory Marvisak#1696, Marvisak#1338, Marvisak#1291, Marvisak#1732
- DirectStorage page lists read at the title's submit (analysis by JappertjeV, klbf-lab#3)
- offline pipeline pre-build that saves as it goes and skips driver-crashing pipelines
- Series S plane composition, VICTORY_FFX_SIMPLE, scripted keys in release builds
- docs/klbf/skip-amd.txt: AMD skip list used for our runs
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

Turns the refusal 'a packed input half no element holds' into a silent 0. With main's corrected first-fit packing rule no title pixel shader reads a padding half (4,773 of 4,773 map), so the change only hides a wrong packing model; the padding's real content is whatever the previous stage exported, not 0.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
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