Skip to content

Shaders: second rows of packed 16-bit pixel inputs - #592

Closed
SAitken91 wants to merge 1 commit into
Marvisak:mainfrom
SAitken91:shader/packed-input-partner-rows
Closed

SAitken91 wants to merge 1 commit into
Marvisak:mainfrom
SAitken91:shader/packed-input-partner-rows

Conversation

@SAitken91

Copy link
Copy Markdown
Contributor

Pixel inputs that pack two 16-bit rows per dword (pack2) failed when their metadata leaves the second row out (row2 = row). With no second row, reading any of its halves failed with "a packed input half no element holds". That blocked 172 programs in shaders.rpf, mostly ped and mirror-reflection pixel shaders.

Change

  • New half_input_partners. It finds the missing second row the way the output side already does (half_outputs): the next 16-bit row of the input signature that no input entry names, taken in row order. Rows the metadata does give are taken first, so they aren't handed out twice.
  • The partner is used only when pack2 is set and row2 = row. An explicit row2 is used as before.

Why not just read 0

I tried that first, and it would have validated more programs. A diagnostic showed the failing reads were halves 4–7 with a 4-channel first row, which is the second row's data, not padding. Reading 0 would have hidden real values, so I didn't do it.

Results

victory translate --validate shaders.rpf: vertex/pixel validated 12172 → 12289. 6 programs whose metadata does name a second row still stop at this error. That looks like a separate case, and it's left as is.

Testing

  • cargo test -p victory-shader: 70 passed, including the new packed_pixel_inputs_find_their_second_row. Clippy and rustfmt are clean.
  • Not exercised at runtime. The pairing rule assumes the pixel signature lists 16-bit rows in the order the vertex side packs them, as the output side already assumes.

This is independent of #539, #554, #563, #565, #569 and #571.

Written with the help of Claude (AI).

🤖 Generated with Claude Code

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech 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.

Tested and verified on Windows 11 x64 (D3D12 WARP + Hardware).

  • Tested unit test packed_pixel_inputs_find_their_second_row, validating that row pairing logic correctly identifies the partner 16-bit signature element for packed inputs when
    ow2 == row.
  • Confirms fix resolves the 172 blocked shaders in shaders.rpf that emitted � packed input half no element holds.
  • cargo test -p victory-shader: 70 passed, 0 failed.
  • cargo clippy -p victory-shader --lib -- -D warnings: 0 warnings.
  • cargo xtask policy: 151 files clean.

@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I have the same local v1.0.2.1 shader archive and will investigate the 6 remaining explicit-row2 cases as a follow-up to this PR, rather than changing this branch. I’ll first reproduce them on 7139712 and inspect only the signature metadata and failing half indices needed to distinguish the case.

If the cause is separable, I’ll add a focused synthetic regression test and open a small follow-up PR stacked on this head. I’ll report counts and metadata only, without shader contents or extracted data. AI-assisted (Kimi).

@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Opened the follow-up as #621, stacked on this head: #621

The explicit-row2 padding fix turns all 6 remaining failures into validated modules: VS/PS emitted 12,389 → 12,395, validated 12,289 → 12,295, with 6 gained and 0 lost across 25,889 matched labels. The inferred-partner case remains strict, and the new synthetic test covers that distinction. AI-assisted (Kimi).

@ghost ghost mentioned this pull request Nov 24, 2026
@fuzeofficlal

fuzeofficlal commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Hardware readback on 7139712 with a synthetic full-screen draw. The VS supplies three distinct TEXCOORD rows, and the translated PS reads both halves of packed channels 0 and 2. The VS and emitted PS passed the Windows SDK DXIL validator (1.8.2502.11).

Build Implicit row2 = row Explicit row2 = 2
d2a4bae Translation refused with a packed input half no element holds 16/16 pixels matched [0.125, 0.25, -5, -4]
7139712 16/16 pixels matched the adjacent row, [0.125, 0.25, 1.25, 2.5] 16/16 pixels matched [0.125, 0.25, -5, -4]

The results matched on the RTX 5090 (32.0.16.1656) and Radeon iGPU (32.0.21042.62). This covers the inferred pairing and the explicit control for this constant-varying fixture. The explicit padding cases are tracked in #621.

The same fixture also passed on #176 at f0e7745 after the triage comparison. Both adapters matched 16/16 pixels for the inferred row and the explicit control.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17:

  • Translation failures: 3,733 on main -> 3,616 with this PR (-117, all pixel). "a packed input half no element holds" drops 172 -> 6. The freed programs mostly stop next at "a lane mask read as data" (206 -> 227) and "a 64-bit image atomic" (653 -> 663).
  • Emitted: vertex+pixel 12,284 -> 12,401 (+117, all validated), matching your count; compute and mesh unchanged.
  • Validation: 185 modules rejected on both; no program that validated on main fails now.

AI-assisted.

Pixel inputs packing two 16-bit rows per dword (pack2) whose metadata
leaves the second row out (row2 = row) had no second row, so reading
its halves failed: "a packed input half no element holds". The second
row is now found as the output side finds it (half_outputs): the next
16-bit row of the input signature that no input entry names, taken in
row order, after the rows the metadata does give.

translate --validate on shaders.rpf: vertex/pixel 12172 -> 12289
validated; 6 programs whose metadata names a second row still stop
there.

Co-Authored-By: Claude Opus 5.5 <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.

@SAitken91
SAitken91 force-pushed the shader/packed-input-partner-rows branch from 7139712 to 35bf153 Compare November 24, 2026 08:45
@catminou4

Copy link
Copy Markdown
Contributor

Heads-up on the stack: #621 is stacked on this PR — its body says "Stacked on #592 at 35bf153; only 7e5c7c8 is new here", and since its base is main with 2 commits, merging #621 as-is would land both this change and the explicit-padding follow-up together.

I reviewed and approved #621 after rebasing it onto current main locally: merges cleanly, cargo test -p victory-shader --locked → 98 passed / 0 failed (macOS arm64). The combined diff keeps this PR's pairing logic (packed_input_half/half_input_partners) intact.

Also noting #176 (Yaekai) is an independent implementation of the same root fix (pairing pack2 fp16 inputs whose metadata leaves row2 == row), with several reviews already. So the maintainer has two routes: merge #592+#621 as a stack, or compare against #176. Either way this PR's content is covered by my #621 approval if the stack lands first.

@dpalacios69

Copy link
Copy Markdown
Contributor

Independent check on Linux, merged onto current main (ffe310e) in a scratch branch: textually clean, cargo test -p victory-shader --locked passes (97 passed, 0 failed, 1 ignored, the new test included), cargo clippy -p victory-shader --lib has no warnings. --all-targets shows only the two unused-import warnings in emit/mod.rs that main already has on Linux. No GPU run. AI-assisted; no game data.

@pablogonz12

Copy link
Copy Markdown
Contributor

Measured on Linux (RX 9070 XT, RADV/Mesa 26.3.1, GE-Proton11-14, vkd3d-proton master), head 35bf153 merged onto our tree:

  • full archive under Wine (26,503 containers): vertex+pixel 13144 -> 13271 (+127), compute 2228 and mesh 8395 unchanged; "a packed input half no element holds" 166 -> 0.
  • the released programs fail later (a lane mask read as data 281 -> 310 and similar), which looks like the expected next class, not a regression.
  • offline world set (751) unchanged at 684; all 684 SPIR-V valid (dxil-spirv + spirv-val); cargo test -p victory-shader --lib 114 pass, only the known failure.
    Not tested: in-game on this branch; native Windows.

@fiestorra

fiestorra commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

An independent count of what this blocks, measured on main ffe310e with my own copy of package 1.0.2.1 (title build b99f876b74d4a77f03af5f878223b27bd647b5c35a79d5decd9f716504239e93), on a second machine. Command: victory translate <shaders.rpf> --validate --list.

  • 166 distinct pixel programs carry this reason (167 report lines: 1 program's report prints across two physical lines, which repeat a count by lines without meaning 167 programs). No other stage is affected.
  • By family: 49 PS_MirrorPedTextured_Eight, 45 PS_PedTextured_Eight_Decals, 28 PS_PedTexturedCutOutTint_Zero, 12 PS_DeferredPedTexturedNC_Packed, 10 PS_PedAlphaPrepass_Fire, 10 PS_PedAlphaTransmission_Fire, 10 PS_Textured_Eight_Fire, 1 PS_DeferredTexturedStdFireColor, 1 PS_DeferredTexturedStdFireNC. Your "mostly ped and mirror-reflection pixel shaders" matches the top of this list.
  • I do not get 172, and I can't close the 6-program difference. Two candidates: the line-vs-program counting above, and main having moved since you measured. Worth settling before a fix lands so the before/after number means the same thing twice.

What the code path allows, reading emit/lower.rs: the reason is produced at exactly one place, lower.rs:5543, reached only through the _f16 branch (lower.rs:5511, lower.rs:5541-5543), and every None comes from packed_half (lower.rs:291-307) or from the non-packed branch at lower.rs:5522. That gives four routes:

  1. half index >= na but < a_halves — padding inside the first row's own extent.
  2. row2 == row, so no partner row is offered (lower.rs:5508).
  3. half index >= extent(b) — the named partner row declares fewer channels than the interpolation reads.
  4. fp16 set, pack2 clear, and the attribute asks for the upper half (lower.rs:5522, high decoded at gfx10/fields.rs:565).

Routes 2 and 3 are what #176, #592 and #621 describe, and I read #176 and #592 as the same pairing fix described twice (half_inputs and half_input_partners), so I don't know which one is intended. Route 1 with an inferred partner is the one #592's "why not just read 0" argument is about. Route 4 I don't see in any of the three. I cannot tell how my 166 split across the routes without printing each program's declared rows and channels.

One thing that may help whoever implements #621: this same function already reads a missing half as zero for a flat input. In the mode == 1 branch, lower.rs:5547-5549 builds self.s.m.i32(0) and applies half(self, h)?.unwrap_or(z) for both halves, while the _f16 branch refuses the identical None. So "the padding reads as zero" is already the behaviour of one of the two paths, and the difference between them is only which one the program asks for. Also measured on the same run: the neighbouring refusals of this function never fire on this package — a 16-bit read of a 32-bit input, 32-bit interpolation of a 16-bit input, one input interpolated two ways, an input the signature lacks, a non-provoking vertex value and pull-model interpolation are all 0 — while the first half of an interpolation (lower.rs:5555) is 29, which is a separate gap.

If any of #176, #592 or #621 lands, I can run the same census before and after on a clean worktree and report which families unlock and how many, the way I did for #878.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

Following up on my count with a probe that says which missing-half case each read actually hits. The probe is local and small: a guarded eprintln! at the one failure site (emit/lower.rs:5543, enabled by an environment variable) that prints the row, channel, high flag, the half index being asked for, pack2, the partner row, and the extent of both rows as the signature was built. Same commit (ffe310e), same copy of the package, nothing else changed. As a control I re-ran the whole pack with the probe in place: the census's own totals are byte-for-byte the same as without it (emit 3436, I/O 207, resources 360, validator 162, this reason 166), so the probe is not changing what gets refused.

First, a correction to my own note. The 167th line is not a wrapped report. The census ends with one line per reason, shaped <count> <label>: <reason> (e.g. <one example program>), and that line itself matches a search for the reason text. The census publishes its own table: it states 166 for this reason, which is the figure I gave. Per-reason numbers are best read from that footer; counting lines for a reason comes out one higher for every reason.

With the probe, the 166 programs make 1048 failing half-reads, and they land on exactly two of the four routes I listed:

Nothing landed on the other two routes. No read asked for a half in the padding of its own row (want >= na and want < a_halves), no read referenced an input row missing from the built signature, and no read was the upper half of an fp16 input without pack2. So on this package there are only two shapes, and by reads the named-but-short partner is about four times as common as the absent partner.

Two limits, stated plainly. These are reads, not programs: a program makes several such reads, and the lowering has no program name in scope, so I cannot say how the 166 split between the two cases or which families sit on which side. And this is a pre-fix number. My reading of the three changes is that once this PR lands, the 220 should disappear and the 828 should be what is left standing - which would make the remaining question exactly #621's. I can measure that on the merged result the same way I did for #878 and #877, on a clean worktree, before and after.

Written with an AI assistant.

@Halfect Halfect left a comment

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.

Independent verification of 35bf153 merged onto current main ffe310e (clean merge; only crates/victory-shader/src/emit/lower.rs, +87/−1), Windows 11, rustc 1.98.1 (x86_64-pc-windows-msvc):

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

Code read on the merged tree: half_input_partners mirrors the output-side half_outputs convention — the next 16-bit signature row that no input entry names and no explicit row2 already claims, in row order — and the partner is consulted only under pack2 && row2 == row, so flat inputs and explicitly paired rows are untouched. The test's assignments (0→1, 3→4, explicit 5→6 left alone) match that rule, and @fiestorra's probe (220 partner-absent reads vs 828 named-but-short) lines up with what this PR covers versus what remains for #621.

One observation, not blocking: the partner map is rebuilt per packed-half read. Signatures are small, so the cost is negligible, and caching it would complicate lifetimes for no measurable gain.

Disclosure: my #621 is stacked on this head, so I have an interest in it landing; this is still an independent check of the merge with current main, which the existing runs don't cover (Linux, macOS, or the older 7139712 head).

CPU-only; no GPU run, no game data. AI-assisted (Kimi).

simnJS pushed a commit to MiamiGame/XTP that referenced this pull request Nov 24, 2026
Pixel inputs packing two 16-bit rows per dword (pack2) whose metadata
leaves the second row out (row2 = row) had no second row, so reading
its halves failed: "a packed input half no element holds". The second
row is now found as the output side finds it (half_outputs): the next
16-bit row of the input signature that no input entry names, taken in
row order, after the rows the metadata does give.

XTP adaptation: the hunks of emit/lower.rs went to emit/lower/input.rs
(S0b), the upstream unit test with them. Added: an end-to-end test of a
pixel program reading channel 1 of the second row through
v_interp_p1ll_f16/v_interp_p2_f16, translated and validated, and still
refused past that row's halves.

Survey (shaders.rpf, any host, every translation validated; this commit
alone): see the next commit's message for the pair with #621.

Ported from Marvisak/VIctory#592 (head 35bf1530542f9a463a233d14394e8c6734ae0958) by SAitken91
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
#592's second-row inference is already here (a823dfb, half_inputs), so
its half_input_partners is left out. #621's packed_input_half is ported
onto half_inputs: when the metadata names the packed row's partner, a
16-bit read of a half no element holds is the packing's padding, read
as 0.0; with an inferred partner it still refuses.

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Second rows of packed 16-bit pixel inputs: superseded by main's first-fit packing rule (packed_half in emit/lower.rs, 13091f6), which needs no partner row.

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
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
Shaders: Honor fetch-inactive and bound-control on masked row permutations
Fayberr added a commit to Fayberr/Victory-United 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.