Skip to content

Port upstream #169: tbuffer d16 loads pack two channels, normalized ends load as exactly ±1.0 - #28

Merged
DesertGamer merged 2 commits into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-169-tbuffer-d16-norm-ends
Nov 25, 2026
Merged

DesertGamer merged 2 commits into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-169-tbuffer-d16-norm-ends

Conversation

@lcg007xd-c

Copy link
Copy Markdown
Contributor

What this changes

This ports Marvisak/VIctory#169 by Dufftwt: both of its commits, cherry-picked with -x, so they keep their authorship. The upstream merge is in VIPort's history, but neither change is in the tree. In emit/lower.rs on main:

  1. tbuffer_load_format_d16_* are loaded as 32-bit. The d16 test is name.starts_with("buffer_") && name.contains("_format_d16_"), so the typed (tbuffer_) d16 loads take the 32-bit path. The first VGPR gets channel x as an f32 (the bits of 1.0, not the f16 pair (1.0, 2.0)), and the other channels are dropped. The decoder already sizes their data as d16, two channels per VGPR. The first commit packs the format path's channels for d16: integer formats keep their low 16 bits, the others become f16, as the MUBUF d16 path does. It adds tbuffer_d16_loads_pack_two_channels_per_dword.
  2. A normalized format's ends are not exactly ±1.0. UNORM and SNORM fields are divided by their largest value. A host may divide through a reciprocal and land just below 1.0; upstream measured 16_16_UNORM's 65535 loading as the half 0x3BFF instead of 0x3C00 on an RX 9070. The second commit selects exactly 1.0 for the largest value, and exactly -1.0 for an SNORM field's two lowest values, as the formats define them. It adds normalized_buffer_formats_load_their_ends_exactly.

The second commit's test uses helpers from the first, so they come together, as they did upstream. The cherry-picks did not follow the rename for valu_tests.rs, so I applied that file's hunks to crates/viport-shader/src/emit/valu_tests.rs by hand. They applied cleanly. lower.rs applied as is.

Checked

  • No game data of any kind (files, extracts, screenshots, dumps, saves): see docs/asset-policy.md
  • No binary files or archives
  • No new dependency, build.rs, git hook, .cargo config, CI change or script (or an issue explains why)
  • No download, no started program, no network connection added (or an issue explains why)
  • cargo test --workspace passes (only viport-shader --lib on Linux, see below)
  • cargo clippy --workspace --all-targets --locked -- -D warnings passes (for viport-shader, with CI: clear the clippy errors that keep main red since a3e7f17 #21 merged in locally)
  • The code I wrote is formatted with rustfmt; I did not reformat lines I did not change

What I ran

On Linux, Rust 1.98.1:

  • cargo test -p viport-shader --lib --locked: 190 passed, 0 failed, 3 ignored. This covers decoding and lowering, but not the new tests, which run on D3D12.
  • cargo clippy -p viport-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean with CI: clear the clippy errors that keep main red since a3e7f17 #21 merged in, so the new Windows tests type-check.

Not run: the two new tests in valu_tests.rs. They dispatch on the host GPU and WARP, and I have no Windows machine. The Windows CI test step should run them on WARP. Upstream ran them there and on an RX 9070 for #169.

Overlaps

#22 (v_dot8_i32_i4) and #21 (CI clippy) also edit emit/lower.rs, in other functions. I merged #21 into this branch locally with no conflict.

🤖 Generated with Claude Code

The d16 forms of the typed buffer loads return each channel as 16 bits,
two per VGPR, low half first; the decoder already sizes their data that
way. The lowering only treated `buffer_` names as d16, so a
tbuffer_load_format_d16_* went through the 32-bit path: the first VGPR
got channel x as a 32-bit value (the f32 bits of 1.0 instead of the f16
pair (1.0, 2.0)) and the other channels were dropped.

The format path now packs its channels for d16: integer formats keep
their low 16 bits, the other formats become f16 (as the MUBUF d16 path
converts them).

(cherry picked from commit c430b1d)
Buffer format loads divide a UNORM or SNORM field by its largest value.
A host may divide through a reciprocal and land just below 1.0: on an
RX 9070 (RDNA 4), 16_16_UNORM's 65535 loaded through the d16 path as the
half 0x3BFF instead of 0x3C00. The largest value now selects 1.0, and an
SNORM field's two lowest values select -1.0, as the formats define them.

(cherry picked from commit 645391b)
@lcg007xd-c
lcg007xd-c force-pushed the port/upstream-169-tbuffer-d16-norm-ends branch from 14b76d5 to 317c470 Compare November 25, 2026 21:45
@DesertGamer
DesertGamer merged commit 618e631 into DesertGamer:main Nov 25, 2026
1 check failed
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.

3 participants