fix(shader): give the a16 bias of image samples its own address dword #581
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/581"
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?
Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-04T23:30:57Z.
What
With
a16, the MIMG address layout packed the first coordinate into the upper half of the bias dword. On hardware the bias is a half that occupies a full dword, and the coordinates start in the next one:image_sample_b2D a16bias,s | tbias,pad | s,timage_sample_b_cl2D a16bias,s | t,clampbias,pad | s,t | clampimage_sample_b_o2D a16offset | bias,s | toffset | bias,pad | s,tSo
image_sample_b,image_sample_b_cl,image_sample_b_o,image_sample_b_cl_oand the biased gathers read their coordinates from the wrong halves whenevera16is set. With a compare the layout was already right, because the 32-bit reference realigned it.GetRdnaImageAddressComponentLayoutnow advances a full dword past the bias. The bias itself is still read as a half from the low 16 bits. Withouta16nothing changes.Source: LLVM
AMDGPULegalizerInfo.cpp,packImage16bitOpsToDwords("Special handling of bias when A16 is on. Bias is of type half but occupies full 32-bit."), and the expected code inllvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.sample.a16.dim.ll:sample_b_2disimage_sample_b v[0:3], v[0:1]withv1 = {s, t},sample_b_cl_2dis[v0, v1, v3].This touches the same helper as #475 (a16 gradients), which leaves the bias packed as on main. The two changes are independent; whichever lands second needs a small rebase.
Tested
Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA RTX 5080. No title run.
New execution test
agc_driver_image_sample_bias_a16: a compute shader samples a 16x16 mip chain withimage_sample_b,image_sample_b_o(two offsets) andimage_sample_b_cl, alla16, on 32 threads with distinct coordinates. The unused upper half of the bias dword holds another coordinate, so reading it shows. The bias is 0: outside pixel shaders the recompiler samples at an explicit LOD, so the bias value is not what this test covers.image_sample_b_clruns only on devices withshaderResourceMinLod.image_sample_b a16: thread 0 component 1 is 8.000000, expected 3ctest(Release): 214/214 passedNot tested on AMD hardware.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:44:12Z.
Thanks, good find. I checked it with LLVM's own code generation for gfx1013:
sample_b_2dwith a16 puts the bias alone in v0 and{s, t}in v1,sample_b_cl_2duses[v0, v1, v3], andsample_b_o_2duses offset, bias, then{s, t}, so the bias always takes a whole dword. With a compare the layout comes out the same as before, as you say, and without a16 nothing changes. The fix covers every opcode with the bias flag, the gathers included.The test shaders disassemble (llvm-mc, gfx1013) to the loads, the three
image_sample_bforms with offsets (1, 2) and (-1, -2), andimage_sample_b_cl, and putting a different coordinate in the upper half of the bias dword is a nice way to make the old packing visible.agc_driver_image_sample_bias_a16passes here on NVIDIA, and on main's code it fails exactly as in the description ("thread 0 component 1 is 8.000000, expected 3").PPSA21564 has no a16 image samples, so this doesn't change anything in my runs. The overlap with #475 is only textual, since bias and gradients never appear together. Ready to merge from my side.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T23:46:08Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cppL241