Skip to content

Shaders: fix GFX10 independent a16/g16 gradient dword packing in fields.rs with 21 tests - #1209

Closed
geiyiliyabumo wants to merge 2 commits into
Marvisak:mainfrom
geiyiliyabumo:test/shader-gfx10-fields
Closed

geiyiliyabumo wants to merge 2 commits into
Marvisak:mainfrom
geiyiliyabumo:test/shader-gfx10-fields

Conversation

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Summary

Closes #1116

Full verification details and change notes are documented in #1116 (commit bcce91f, based on main ffe310e).

 crates/victory-shader/src/gfx10/fields.rs | 1155 ++++++++++++++++++++++++++++-
 1 file changed, 1151 insertions(+), 4 deletions(-)

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check on edited files: PASS
  • cargo xtask policy: PASS (zero game files/data)
  • cargo clippy --all-targets --locked -- -D warnings (default + --features diagnostics where applicable): PASS
  • Targeted & crate unit/GPU tests: PASS

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

@shortselow-byte

Copy link
Copy Markdown

Tested at head bcce91f (on main ffe310e): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT. gfx10::fields 21 passed; workspace 363 passed, 0 failed; both clippy runs (default and --all-features) clean; cargo xtask policy ok.

The a16 rule here matches what I found independently from LLVM's GFX10 assembler tests (gfx10_asm_mimg.s): image_sample_d 2D a16 → 5, 3D a16 → 8, image_sample_cd_cl 2D a16 → 6, image_sample_c_d_o 2D_ARRAY a16 → 8 (details in a comment on #318, which packs gradients under a16 the other way).

The lower.rs follow-up you mention exists on my fork, since I can't open PRs here: shortselow-byte/VIctory@6fab60c on branch shader/gfx10-operand-size-tests. It adds image_address(k, whole, a16) (offset, bias, compare and gradients take a VGPR each; with a16 the coordinates and LOD/mip go two per VGPR), reads gradients as f32, and has a unit test. With only its lower.rs part applied on top of this PR (keeping your fields.rs), image_addresses_after_whole_dwords passes, the workspace has 364 passed, 0 failed, and both clippy runs are clean. Not run against the title.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Heads-up on a silent miscompilation hazard if fields.rs is updated without updating the consumer in crates/victory-shader/src/emit/lower.rs:

  1. image_sample_d with a16 = true (g16 = false) reads the wrong VGPRs in Lower::image: Once image_addr_dwords sizes 2D image_sample_d ... a16 to 5 VGPRs (4 full-dword f32 gradients + 1 packed f16 coordinate dword), Lower::image still indexes both gradients and coordinates through addr_val(first + ...) using *a16 (k / 2) and passes the gradients through legacyF16ToF32. That reinterprets the low/high 16 bits of the f32 dh gradients as f16, and reads v2 (dvx bits) as the (u, v) texture coordinates instead of v4!
  2. image_sample_d_g16 and whole-dword prefix (_o) with a16: Lower::image does not yet match "image_sample_d_g16", and indexing offset_word (_o) through addr_val(0) when a16 = true masks off its upper 16 bits. Splitting addr_at(base, half, k) so 0..first stays full dwords, gradients unpack from first and first + grad_regs by g16, and coordinates unpack from first + 2 * grad_regs by *a16 keeps decoding and lowering aligned.

Verified across all four (a16, g16) combinations with dxil.dll validation and anisotropic 4x4 quadrant/gradient GPU readback on RTX 5090 and WARP — reference commit if you want to fold the emit/lower.rs side into this PR: fuzeofficlal@d4022c4

LAKSHYA-cmd-tech added a commit to LAKSHYA-cmd-tech/VIctory that referenced this pull request Nov 24, 2026
…-cube-shaders

Shaders: fix GFX10 independent a16/g16 gradient fields and cube gradients (Marvisak#1209, Marvisak#563)
@geiyiliyabumo

Copy link
Copy Markdown
Contributor Author

Thanks @shortselow-byte and @fuzeofficlal for verifying the RDNA2 \�16/_g16\ rule and flagging the \emit/lower.rs\ consumer mismatch!

Folded the \Lower::image\ fix into this PR so decoding and lowering stay aligned:

  • Split \�ddr_at(base, half, k)\ so whole-dword prefixes (_o\ offset word, _b\ bias, _c\ compare ref, \image_get_resinfo\ mip) always read full dwords even when \�16\ is set.
  • Match \image_sample_d_g16\ alongside \image_sample_d, unpacking \dh\ from \ irst\ and \dv\ from \ irst + grad_regs\ using \g16\ (leaving \image_sample_d ... a16\ gradients as full-dword \ 32).
  • Unpack coordinates and explicit LOD from \ irst + 2 * grad_regs\ using *a16.

Re-verified \gfx10::fields\ (21/21 passed), \emit::lower\ (11/11 passed), \cargo clippy -p victory-shader --all-targets -- -D warnings, and \cargo xtask policy.

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

@rezioliver-collab

Copy link
Copy Markdown

I ran an offline A/B comparison of ffe310e and bcce91f on Windows 11 with Rust 1.98.1 (MSVC) and dxil.dll 1.8.2502.11. I ran victory translate --validate --list --jobs 1 twice per revision against the same local shaders.rpf.

Each run processed 26,503 containers and validated 21,724 shaders (12,155 vertex/pixel, 1,417 compute, and 8,152 mesh). All 25,889 listed outcomes matched by archive offset and stage across the four runs, with zero validation gains or losses.

I also ran the same four synthetic 2D image_addr_dwords cases on both revisions. A16-only went from 3 to the expected 5 dwords, and G16-only went from 6 to the expected 4. Both control cases passed on both revisions. All 21 gfx10::fields tests passed on bcce91f, and cargo xtask policy passed on both commits.

These results cover the original fields.rs change at bcce91f, before the Lower::image follow-up.

AI use : Assisted by GPT 6.2 Sol.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at bcce91f: cargo test -p victory-shader passes, 141 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I ran the same synthetic 2D texture fixture against bcce91fa689cb817671872c2ed930208df3fc9df and the current ae0b48e6daf7dbbad8c5d8af504726f5efac1bf4 on WARP. At bcce91f, image_sample_d with A16 coordinates returned red values [1.0, 1.0] instead of [5.5, 7.0]. At ae0b48e, both values matched for all four A16/G16 combinations. The sampler uses linear magnification and point minification, so the readback checks the coordinates and whether the gradients select the intended filter.

The test-only commit is directly on ae0b48e. With it, the shader suite on WARP passed 142 tests with one ignored. Microsoft DXIL validation, strict shader Clippy and cargo xtask policy passed.

@geiyiliyabumo

Copy link
Copy Markdown
Contributor Author

Thanks @andrewpozdnakov7-jpg for the independent A/B verification on ae0b48e across all four A16/G16 combinations with DXIL validation!

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. This makes a16 and g16 independent for image gradients. image_addr_dwords (gfx10/fields.rs) packs gradients only for _g16 forms, and Lower::image reads whole-dword prefixes (offset, bias, compare, mip) unpacked, gradients by g16, and coordinates and LOD by a16. It also maps image_sample_d_g16. The evidence is in the PR thread: LLVM's GFX10 assembler tests give image_sample_d 2D a16 as 5 dwords, and a WARP readback matches all four a16/g16 combinations after the lowering fix. An A/B over 21,724 shaders showed no validation changes. The new indexing agrees with main's op table (bias only on image_sample_b, gathers unchanged). CI passes. Please put the LLVM reference in the description or a short comment. This takes a different approach from #318, which packs gradients under a16, so only one of them should land.


Generated by Claude Code

@geiyiliyabumo

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto \main\ (\ccfb029), preserving cube 2D-per-direction gradients, \image_sample_d_cl, and \op == 81\ level-query coordinate count alongside independent \�16/\g16\ unpacking. \cargo test -p victory-shader --locked fields::tests, \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings, and \cargo xtask policy\ all pass.

@catminou4 catminou4 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.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

165 passed / 0 failed / 2 ignored. GFX10 independent a16/g16 gradient dword packing fixed in field… — +21 new tests, the largest test addition in the old backlog; gradient packing is exactly the kind of subtle encoding that needs this coverage.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
…dword packing in fields.rs with 21 tests
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing as a duplicate of #2372, which carries this PR's two commits unchanged (identical patch ids) and adds the lowering of image_sample_d_cl_g16, removes the then-stale refusal of 16-bit gradients on 1D and 3D images, and adds a GPU readback test. The rule itself is right: a16 leaves gradients at 32 bits on a target with G16. One thing to carry over to #2372: under a16 this now reads image_get_resinfo's mip as a whole dword, where main correctly takes the low 16 bits.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
… changed, leave the texture's state as the list left it, and land with no remap under way

Gone through again after fxceless/victory-fork issue Marvisak#1209 (RTX 3050
laptop: with the copy back the boat moves, then the process dies reading
null in VCRUNTIME, called from the title's own code, three times):

- A landing wrote the whole span of the texture's console layout back,
  with the bytes it had read before tiling where no subresource lies
  (padding, the tail, a texture the title placed inside the span). Bytes
  the title wrote there in between were rolled back. Only the runs that
  the tiled texels changed are written now (runs under 64 bytes apart
  joined); the per-frame KB counts those.
- The copy moved the texture to the copy-source state and left it there;
  a later list whose shaders reach it by index without naming it found it
  so. The list's own state is put back after the copy, and a read state
  that holds the copy's needs no barrier (fxceless pull request Marvisak#1170).
- The texture to buffer read-backs now land with the runtime held off its
  remapping, as the texture copies do: a page found there stays there
  until the row is written.

Checked and sound: a failed or null Map returns before any pointer is
used; the read-back buffer and the host texture are held by the list until
it is reset, which is after its landing; a release, a new texture at the
same memory or a remap takes the copy's ticket, and the landing checks it
under the tickets' lock; copy_mapped writes nothing where the destination
is not there at every exit (the processor's copy hands faults to the
kernel's, and a failed kernel copy into memory not all mapped returns);
levels and layers of no bytes cannot occur (a level has at least one
texel, a span of none is not tracked). Tests on the software adapter: a
texture released between close and run (its copy is dropped, nothing
lands) and the state after the copy; a host test that a copy into memory
that went writes nothing and does not fault.

The crash in Marvisak#1209 is in the title's code; whether the rolled-back bytes
were its cause is not known.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: fix GFX10 independent a16/g16 gradient dword packing in fields.rs with 21 tests

8 participants