Shaders: pack 16-bit channels in tbuffer_load_format_d16_{x,xy,xyz,xyzw} #351

Open
AscilCH wants to merge 1 commit from upstream-pr/351 into main
AscilCH commented 2026-11-24 23:49:48 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T23:49:48Z.


Problem

In crates/victory-shader/src/emit/lower.rs, tbuffer_load_format_d16_{x,xy,xyz,xyzw} was miscompiled:

  1. let d16 = name.starts_with("buffer_") && name.contains("_format_d16_"); evaluated to false for tbuffer_load_format_d16_*.
  2. In the if let Some(f) = *format branch, format_load returned 32-bit channels and wrote them into v[reg + 0..count] without 16-bit packing. Because gfx10::fields::data_dwords only allocates count.div_ceil(2) destination VGPRs for _format_d16_, channels 0–1 received 32-bit values instead of packed 16-bit pairs, and channels 2–3 were silently dropped.

Fix

  • Set d16 for both buffer_ and tbuffer_ _format_d16_ opcodes.
  • When d16 is true in if let Some(f) = *format, pack pairs of channels into each destination VGPR (low half first; high half 0 for odd channel counts):
    • Numeric::Uint: clamp to 0..=0xFFFF (UMin).
    • Numeric::Sint: clamp to -32768..=32767 (IMax/IMin) and mask & 0xFFFF.
    • Float/norm/scaled formats: convert via dx.op.legacyF32ToF16.
  • Add emit::valu_tests::tbuffer_load_format_d16_packs_float_and_int_channels testing 16_16_16_16_FLOAT (xyzw and xyz), 16_16_FLOAT (missing Z=0/W=1 defaults), 8_8_8_8_UINT, 8_8_8_8_SINT, 32_32_32_32_UINT clamping, and 32_32_32_32_SINT clamping.

Verification

  • cargo test -p victory-shader --locked tbuffer_load_format_d16_packs_float_and_int_channels: passed (hardware D3D12 + WARP + dxil.dll)
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593803722 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/351). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T23:49:48Z. --- ## Problem In `crates/victory-shader/src/emit/lower.rs`, `tbuffer_load_format_d16_{x,xy,xyz,xyzw}` was miscompiled: 1. `let d16 = name.starts_with("buffer_") && name.contains("_format_d16_");` evaluated to `false` for `tbuffer_load_format_d16_*`. 2. In the `if let Some(f) = *format` branch, `format_load` returned 32-bit channels and wrote them into `v[reg + 0..count]` without 16-bit packing. Because `gfx10::fields::data_dwords` only allocates `count.div_ceil(2)` destination VGPRs for `_format_d16_`, channels 0–1 received 32-bit values instead of packed 16-bit pairs, and channels 2–3 were silently dropped. ## Fix - Set `d16` for both `buffer_` and `tbuffer_` `_format_d16_` opcodes. - When `d16` is true in `if let Some(f) = *format`, pack pairs of channels into each destination VGPR (low half first; high half 0 for odd channel counts): - `Numeric::Uint`: clamp to `0..=0xFFFF` (`UMin`). - `Numeric::Sint`: clamp to `-32768..=32767` (`IMax`/`IMin`) and mask `& 0xFFFF`. - Float/norm/scaled formats: convert via `dx.op.legacyF32ToF16`. - Add `emit::valu_tests::tbuffer_load_format_d16_packs_float_and_int_channels` testing `16_16_16_16_FLOAT` (`xyzw` and `xyz`), `16_16_FLOAT` (missing Z=0/W=1 defaults), `8_8_8_8_UINT`, `8_8_8_8_SINT`, `32_32_32_32_UINT` clamping, and `32_32_32_32_SINT` clamping. ## Verification - `cargo test -p victory-shader --locked tbuffer_load_format_d16_packs_float_and_int_channels`: passed (hardware D3D12 + WARP + `dxil.dll`) - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic tests only, no game data.)*
BTekV4 commented 2026-11-25 01:12:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by BTekV4 on 2026-11-25T00:48:43Z.


Tested this PR on top of 31714de (i.e. after yesterday's 3bff182 and 31714de merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with A pressed by a script so the world actually loads (~5000 draws/frame, 150 s).

Result: no measurable change on this title. missing-shader 10, pipeline-refused 7, mesh-pipeline-refused 1 — identical to the same build without this PR.

  • baseline (main + #376): a8826150ef94847a
  • this PR (main + #376 + PR): 764d42becfba870b

The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the a whole-wave section step the simulation does not follow (15 occurrences) and a lane mask exchanged where not every lane runs (15) failures are gone. What remains is:

  • 7× a descriptor read only as data (pixel)
  • 1× a descriptor's address or format read as data
  • 1× a lane mask exchanged where not every lane runs
  • 1× a lane mask holding lanes elsewhere read as data
  • 7× pipeline-refused, all E_INVALIDARG (0x80070057) on compute pipelines

So this may be superseded — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does).

Two practical notes:

  1. Against 31714de this PR conflicts only in crates/victory-shader/src/emit/valu_tests.rs (a test file); the functional code applies cleanly, so a rebase is trivial.
  2. Same-run context and the full shader-diag.jsonl (34k records, 11.8 MB) are in #394.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7148901729 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/351#issuecomment-7148901729). Originally posted by [BTekV4](https://github.com/BTekV4) on 2026-11-25T00:48:43Z. --- Tested this PR on top of `31714de` (i.e. after yesterday's `3bff182` and `31714de` merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with `A` pressed by a script so the world actually loads (~5000 draws/frame, 150 s). **Result: no measurable change on this title.** `missing-shader` 10, `pipeline-refused` 7, `mesh-pipeline-refused` 1 — identical to the same build without this PR. - baseline (`main` + #376): `a8826150ef94847a` - this PR (`main` + #376 + PR): `764d42becfba870b` The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the `a whole-wave section step the simulation does not follow` (15 occurrences) and `a lane mask exchanged where not every lane runs` (15) failures are gone. What remains is: - 7× `a descriptor read only as data` (pixel) - 1× `a descriptor's address or format read as data` - 1× `a lane mask exchanged where not every lane runs` - 1× `a lane mask holding lanes elsewhere read as data` - 7× `pipeline-refused`, all `E_INVALIDARG (0x80070057)` on compute pipelines So this may be **superseded** — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does). Two practical notes: 1. Against `31714de` this PR conflicts **only** in `crates/victory-shader/src/emit/valu_tests.rs` (a test file); the functional code applies cleanly, so a rebase is trivial. 2. Same-run context and the full `shader-diag.jsonl` (34k records, 11.8 MB) are in #394.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/351:upstream-pr/351'
git switch 'upstream-pr/351'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/351'
git switch 'upstream-pr/351'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/351'
git switch 'upstream-pr/351'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/351'
git switch 'main'
git merge --squash 'upstream-pr/351'
git switch 'main'
git merge --ff-only 'upstream-pr/351'
git switch 'main'
git merge 'upstream-pr/351'
git push origin 'main'
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
fxceless/victory-fork!351
No description provided.