Shaders: 16-bit gradient samples (_g16) and a16 independently, in decoding and lowering (#1116) #2372
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2372
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2372"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@KainanP on GitHub · 2026-11-25 12:09 UTC · original
KainanP:fix/image-g16-derivatives→main· +1457 −80 · 4 files · 4 commits · openFixes #1116.
This builds on #1209 and puts both halves of #1116 in one PR, as the triage comment on the issue asked. The first two commits are #1209's (
e32b53e,351a162) cherry-picked unchanged, with @geiyiliyabumo kept as author. The third commit is mine. If #1209 lands first, this PR shrinks to that one commit.Problem
On RDNA2,
a16and the_g16opcodes are independent.a16packs the coordinates and the LOD/clamp two per VGPR._g16packs the derivatives two per VGPR, and each direction starts a new VGPR. LLVM's GFX10 assembler tests (llvm/test/MC/AMDGPU/gfx10_asm_mimg.s, llvmorg-20.1.8) show this. For 2D,image_sample_d … a16takesv[0:4](5 VGPRs) andimage_sample_d_g16takes[v0, v2, v4, v5](4). For 3D,image_sample_d … a16takes 8 andimage_sample_d_g16takes[v0, v2, v3, v5, v6, v7, v8](7).On
main(940d32f):image_addr_dwordspacks gradients whenevera16is set and never for_g16.Lower::imagereads gradients as f16 undera16. Animage_sample_dwith a16 and 32-bit gradients samples the wrong level and the wrong texel (measured below: 4000 instead of 3066)._g16sample is refused by name.a16gradients of 1D and 3D images are refused.Change
image_addr_dwordspacks gradients only for_g16.Lower::imagereads the offset, bias and compare words whole, gradients byg16, and coordinates and LOD/clamp bya16. It mapsimage_sample_d_g16.crates/victory-shader/src/emit/lower.rs, +14 −11):_g16opcode is matched by its name without the suffix, soimage_sample_d_cl_g16lowers the wayimage_sample_d_cldoes (sampleGradwith the clamp). Before, its_clcheck looked at the full name, so the clamp was never read._ocheck also uses that name, so_o_g16forms work once an_ogradient form is lowered (#1687)._g16ones start a VGPR per direction (grad_regs).image_sample_c_d_g16, …) stay refused by name, asimage_sample_c_dalready is: SM 6.6 has noSampleCmpGrad.Tests
New test
emit::valu_tests::gradient_samples_of_16_bits, using hand-encoded MIMG words (encoding cross-checked against the LLVM test file above):image_sample_d,_d_cl,_d_g16and_d_cl_g16on a 2D texture, each with and without a16 (8 programs). Each is lowered, validated withdxil.dll, and run on the hardware adapter and on WARP.1000n + 64y + x. The sampler is point.image_sample_dwith a16,_d_g16, and_d_g16with a16 are translated and validated only, because the test host has no 3D view.image_sample_c_d_g16must be refused.lower_cs32is split so thattry_lower_cs32returns the lowering error. There are no other test-helper changes.Per-case results (RTX 4060 and WARP give the same values):
mainimage_sample_dimage_sample_da16image_sample_d_g16(± a16)image_sample_d_climage_sample_d_cla16image_sample_d_cl_g16(± a16)_da16 /_d_g16a16_d_g16The test fails on
main(image_sample_d_g16 is not supported) and on #1209 alone (image_sample_d_cl_g16 is not supported).Validation
Windows 11, Rust 1.98.1, RTX 4060 (default adapter) and WARP,
dxil.dllfrom SDK 10.0.26100.0.main940d32fcargo test --workspace --locked --no-fail-fast(RTX)VICTORY_WARP=1 cargo test --workspace --locked --no-fail-fastcargo test --workspace --all-features --locked --no-fail-fastcargo clippy --workspace --all-targets --locked -- -D warnings(and--all-features)cargo xtask policyThe +22 tests are #1209's 21
fields.rstests and the new one. The failures are the same tests onmainon this machine, so they come before this change:victory-gpudynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views(the NVIDIA heap-size cap, #1835), and on RTXstride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. Under WARP the last one fails together withpermutes_read_the_lane_named_and_zero_from_lanes_left_out, which are hardware-only checks.Not measured
fields.rshalf alone. Avictory translate --validatecount before and after would show whether any programs use_g16or a16 gradients. If someone with a dump can run it, that would help._g16: the reads come from #1209 and are not covered by a GPU test here.image_sample_cd*_g16(0xE8–0xEF): not in the decoder's opcode table.image_sample_cditself is not lowered either.AI use
The change, the test and this description were written with Claude Code (Claude Opus 5.5). All results above come from runs on my machine. No game data was used.
🤖 Generated with Claude Code
@steven-seagull27 on GitHub · 2026-11-25 13:17 UTC · original
I ran the 3D gradient cases on PR head
1f99fa7with a synthetic 16×8×32 volume. A point sampler reads a texel tagged with its mip and position. I varied 16/32-bit derivatives, 16/32-bit coordinates, the active derivative direction, and the minimum LOD clamp. All 16 volume readbacks matched on each adapter. The eight existing 2D cases also matched on each.As a sensitivity check, I deliberately made the 3D
_g16lowering take Z from the unused high half of its VGPR. The first unclamped_g16case then returned 30200 instead of 10934 on both devices. The patch below contains only the test and the volume-texture support in the test host.The regression can be cherry-picked onto this PR. Test commit
The test ran with synthetic shaders and textures. Cube sampling and in-game behavior remain open.
AI-assisted with Codex.
@KainanP on GitHub · 2026-11-25 13:26 UTC · original
@steven-seagull27 thanks — the 3D readbacks were the part this PR couldn't run (the test host had no volume view). Your commit is now on the branch as
3c7c10f, cherry-picked with your authorship.gradient_samples_of_16_bitspasses with it on an RTX 4060 Laptop (driver 32.0.16.1047) and on WARP 10.0.26100.9818, and clippy-D warningsstays clean on victory-shader.AI use: Claude Code (Claude Opus 5.5).
@steven-seagull27 on GitHub · 2026-11-25 13:32 UTC · original
Thanks for integrating the volume test and checking it on the 4060. I cherry-picked the cube test onto your updated head
3c7c10fand reran it on both devices. A 32×32 point-sampled cube tags each texel with its face, mip and position. I tested all six faces, 16/32-bit derivatives, 16/32-bit face operands and minimum LOD on/off. The active derivative alternates between dPdx and dPdy across faces.On +X the unclamped sample returned 2162 (mip 2, texel 2,5). On −Z with minimum LOD 3 it returned 53065 (mip 3, texel 1,2). As a sensitivity check on the earlier head
1f99fa7, deliberately taking the low half for both packed derivative components caused 12/48 mismatches on each adapter. Those were exactly the unclamped_g16cases, including +X reading 1325 instead of 2162.The uninstrumented cube and volume regressions both passed together on the updated head. Cube test commit
This covers synthetic cube samples with an isotropic point sampler and zero LOD bias.
@Marvisak on GitHub · 2026-11-25 14:52 UTC · original
Automated triage for the maintainers.
Merge candidate. Makes
a16(coordinates, LOD/clamp) and the_g16opcodes (derivatives, one VGPR per direction) independent, inimage_addr_dwords(crates/victory-shader/src/gfx10/fields.rs) and inLower::image(emit/lower.rs, via the newaddr_at), and lowersimage_sample_d_g16/_d_cl_g16. Inmain,a16packs gradients and_g16is refused. I checked the VGPR counts against the cited public evidence (LLVM's GFX10 assembler tests: 2Dimage_sample_da16 = 5 VGPRs,_d_g16= 4; 3D 8 and 7). I also checked that offset, bias and compare words are still read whole, and that_cl/_onow test the name without_g16. The GPU test samples a tagged mip chain on hardware and WARP; contributed volume and cube readbacks are in the thread (the volume one is on the branch).Notes for the maintainer: the branch carries #1209's two commits (with their author), including its ~1,100-line
fields.rsdecoder test module, so it supersedes #1209. Effect on the title's shaders has not been measured.CI:
checkpassing.Generated by Claude Code
@oni-swr on GitHub · 2026-11-25 15:00 UTC · original
Independent Windows verification (software WARP only, no hardware GPU in the final runs)
3c7c10f922a4db981599570540b5fd2f097ff1af;origin/main:940d32f69b22265690a0b5a15d6ded572ba33baf(merge base = origin/main;git merge-treeclean)VICTORY_D3D12_WARP=1andVICTORY_WARP=1(the latter is what victory-shader's testHost::newreads; the path isEnumWarpAdapter, Microsoft Basic Render Driver 0x1414; the tests do not print the adapter id).Results:
cargo test -p victory-shader --lib --locked -- --test-threads=1: 267 passed, 2 failed, 3 ignored. Passing includevalu_tests::gradient_samples_of_16_bits(2D and the 3D volume cases),diff_tests::cube_gradients_pick_the_leveland allgfx10::fields::tests(includingimage_address_dwords).synthetic_tests::gathers_at_a_level_match_the_hardwareandsynthetic_tests::permutes_read_the_lane_named_and_zero_from_lanes_left_out. They are in files this PR does not touch and fail identically onorigin/mainunder WARP (verified there), so they are not caused by this PR.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.cargo xtask policy:asset policy: 182 files ok.Diff review of
lower.rs: theaddr_at(base, half, k)helper reads each address component from the right VGPR, anda16(coordinates, LOD, clamp, bias) and_g16(gradients, one VGPR per direction with an odd last gradient alone in the low half) are now independent. The offset, bias and compare words are still read whole,_cl/_oare tested on the name without_g16, and the old "16-bit gradients of a 1D or 3D image" refusal is gone. I found no logic issues. I did not run the separate cube readback fromsteven-seagull27's branch (it is not on this head); only the cube test already in the tree. The VGPR counts rest on the cited LLVM assembler tests, not on hardware here.Environment notes: the Windows SDK 10.0.19041
dxil.dllcrashes these SM 6.6 tests on WARP (STATUS_ACCESS_VIOLATION, also on main); a current dxil.dll avoids it. An earlier attempt of mine set onlyVICTORY_D3D12_WARP, which victory-shader's tests ignore, so their "hardware" pass briefly ran on the physical adapter before that crash; all results above are from the laterVICTORY_WARP=1runs.Verified by Claude Code (Claude Sonnet 5.5), an AI assistant, on behalf of a maintainer.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 03:25 UTC · original
I reproduced the mip-query regression noted in the closing review of #1209. 2d45b56 is one commit directly on
3c7c10f. It uses the existing a16 operand reader for the mip passed togetDimensions.The same synthetic Windows/WARP fixture reads dimensions from an 8×4 texture with three mips. On
3c7c10f, packed operands0x12340001and0x56780002both return0×0. With the fix they return4×2and2×1. The 32-bit and zero-padded a16 controls pass in both builds. Six paired runs agreed.The fixture also passes on upstream
63bcca4and when the patched branch is merged onto it. The exact branch passed all 30 VALU and 21 field tests, strict shader Clippy, and policy. The merged tree passes the mip query, gradient readback, and all 21 field tests.Please retain the follow-up's Git author if you cherry-pick. If you fold this fix or test into another commit, please include:
Co-authored-by: andrewpozdnakov7-jpg [email protected]
AI-assisted with Codex. Synthetic texture and shader.
@steven-seagull27 on GitHub · 2026-11-26 03:45 UTC · original
I checked @andrewpozdnakov7-jpg’s mip-query fix on RTX 5080 (621.40), Windows WARP (10.0.26100.10068), and WARP 1.0.22. I used an 8×4 texture with three mip levels and added high-half patterns at level 0 as well as levels 1 and 2. Each build also ran the existing 2D and volume tests and our six-face cube regression.
3c7c10f2d45b56All three adapters agreed. Unpacked and zero-padded controls passed on the PR head. For packed a16 operands
0xffff0000,0xffff0001, and0xffff0002, it returned0×0each time. With the fix the same queries returned8×4,4×2, and2×1. I’d include the author’s commit when taking this PR. Original follow-up · Cube regressionAI-assisted with Codex. Synthetic textures and shaders.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.