feat(shader): implement image_sample_cd/_g16 variants and fix a16 gradient layout #475
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/475"
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 adriadam10 on 2026-10-03T18:04:22Z.
What
Found by the ISA sweep: 24 MIMG sample opcodes were refused, and the existing derivative path read the wrong address dwords when
a16is set.image_sample_cd*(0x68-0x6f) andimage_sample_{c_}d*_g16/image_sample_{c_}cd*_g16(0xa2-0xbb, 0xe8-0xef) are now decoded and translated (_cl,_oandc_variants included).a16,image_sample_dpacked the gradients as 16-bit. On gfx10,a16only packs the coordinates (and bias/LOD/clamp): the gradients stay 32-bit unless the opcode is_g16. For example, 2Dimage_sample_d a16is 4 gradient dwords + 1 coordinate dword, not 3 dwords. Before this fix, every such sample returned 0 on hardware-correct inputs._g16packs two gradients per dword, and each direction starts a new dword. 1D isdsdh | dsdv | s. 3D isdsdh,dtdh | drdh,pad | dsdv,dtdv | drdv,pad | s | t | r._cdpasses its gradients in the same layout as_d. The hardware computes one LOD per quad, from the gradients of the quad's first active lane. The translation reads the gradient dwords from that lane (ReadLanewithquad base + ctz(EXEC bits of the quad)), then samples with them.G16in the address flags, soGetRdnaImageAddressComponentLayoutstays a function of the flags alone.Behaviour measured on HW (RDNA2 iGPU, raw kernels)
Setup: a single-level R32F texture whose texel value is
x + 100y + 1000z, a sampler with mag = point and min = linear, and coordinates at a quarter texel. The returned value shows which dwords were read as coordinates, and its fraction (.25or.0) gives the sign of the LOD.a16gradients" layout returns 0, and so does the "no padding"_g16layout._cd: if only one lane of a quad has large gradients, the whole quad minifies only when that lane is the quad's lane 0. With lane 0 off in EXEC, the quad's next active lane decides.Builds on #395, which removes the
_cdrefusal (its commit is included here; the conflict on the same lines is resolved in this branch). This PR keeps that change and adds the per-quad LOD.Tested
Arch Linux, Radeon 660M. New execution test
ImageSampleDerivatives: 24 sample variants over 1D/2D/3D textures, expected values captured on hardware. It passes on RADV, lavapipe (Mesa 26) and the CI's lavapipe (Mesa 25.2.8). The two EXEC-masked_cdcases are skipped when the host subgroup is smaller than 32 (lavapipe), as in the other cross-lane tests.The test fails without each piece of the fix:
a16gradients;_g16without per-direction padding;_cdtreated as_d;_cdreading lane 0 of the quad instead of the first active lane (RADV).ctest(Release): everything passes exceptagc_driver_pixel_helper_laneson local RADV, which also fails onmain.The
_clvariants decode with the same layout. Their execution needs #388 (MinLod capability), so the test does not use them.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T18:04:43Z.
Progress report (
ebf29f8→559aeac)📈 GPU shader instructions: 89.37% (+2.06%, +24 implemented instructions)
✅ 24 implemented
IMAGE_SAMPLE_CDIMAGE_SAMPLE_CD_CLIMAGE_SAMPLE_CD_CL_G16IMAGE_SAMPLE_CD_CL_OIMAGE_SAMPLE_CD_CL_O_G16IMAGE_SAMPLE_CD_G16IMAGE_SAMPLE_CD_OIMAGE_SAMPLE_CD_O_G16IMAGE_SAMPLE_C_CDIMAGE_SAMPLE_C_CD_CLIMAGE_SAMPLE_C_CD_CL_G16IMAGE_SAMPLE_C_CD_CL_OIMAGE_SAMPLE_C_CD_CL_O_G16IMAGE_SAMPLE_C_CD_G16IMAGE_SAMPLE_C_CD_OIMAGE_SAMPLE_C_CD_O_G16IMAGE_SAMPLE_C_D_CL_G16IMAGE_SAMPLE_C_D_CL_O_G16IMAGE_SAMPLE_C_D_G16IMAGE_SAMPLE_C_D_O_G16IMAGE_SAMPLE_D_CL_G16IMAGE_SAMPLE_D_CL_O_G16IMAGE_SAMPLE_D_G16IMAGE_SAMPLE_D_O_G16Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:46:11Z.
Thanks, the per-quad LOD for _cd and the a16 gradient layout are great finds, and the hardware captures make the layout easy to follow. One problem with the lane read for _cd: SpirvAnalysis.cpp treats every ReadLane as a wave-uniform source (UniformSource), because v_readlane takes its lane from an SGPR. Here the lane differs per quad, and in the two-lane emission (a wave64 compute program on a host with 32-wide subgroups, state.laneCount == 2 in SpirvEmitter.cpp) SpirvFlowEmitter reuses the first half's result for every value in sharedLaneValues, so lanes 32 to 63 would sample with the gradients of the quads in lanes 0 to 31. ImageSampleDerivatives.cpp only runs wave32, so it can't catch this. Reading the gradients through a lane-varying shuffle that SpirvAnalysis does not count as uniform (or a small dedicated quad-read op) would fix it, and a wave64 compute case in the test would cover it. Also, since #389 merged, the branch conflicts with main in RdnaImageOpDecoder.cpp (the new image_sample_d_cl_o row sits next to image_sample_cd), so it needs a rebase.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:37:04Z.
Thanks, you're right about
ReadLane. Fixed and rebased onto main (theimage_sample_d_cl_orow from #389 is kept next to the _cd rows):BpermuteU32with the source lane's byte address. It is lane-varying and already listed inLaneSource, and the source lane is always inside the lane's own quad, so it never crosses a 32-lane half.Passes on RADV, local lavapipe and CI's lavapipe. One limit: this RADV still reports 64-wide subgroups even with
RADV_PERFTEST=cswave32, so I couldn't run the two-lane path locally. WithReadLaneput back, the test still passes here, so the wave64 case only catches the old version on a 32-wide host like yours.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T01:40:49Z.
Rebased on current main (after #581). The address-layout loop now advances by
isBiasComponent(flags, index) ? 32u : shape.width, so #581's own dword for the a16 bias is kept alongside this PR'sComponentShape(g16 gradients and a16 coordinates).agc_driver_image_sample_derivatives_testsand #581'sagc_driver_image_sample_bias_a16_testspass on RADV and lavapipe, full ctest green on RADV apart from the knownagc_driver_pixel_helper_lanes.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T02:02:29Z.
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.cppL131-133Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:06Z.
Thanks, and sorry I didn't come back to this after your fix on the 4th.
BpermuteU32with the address and EXEC is lane varying, so the wave64 path no longer shares the first half's gradients with lanes 32 to 63, and the source lane is still the first active lane of the quad (or the lane itself when the quad is empty). Running every case as wave64 with different quads in the upper half covers exactly what I was worried about.The rebase onto #581 looks right too: the bias component still gets its own dword under a16 (
isBiasComponentadvances 32), and for every non-a16 layoutcomponentShapegives the same offsets as main.agc_driver_image_sample_derivativesandagc_driver_image_sample_bias_a16pass here on the merged branch.PPSA21564 has no
_cd,_g16or a16 samples, but the address layout code is shared by every image sample, so I'll put this through my PPSA21564 check before merging. Ready to merge from my side otherwise.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:03:58Z.
Gated on PPSA21564: no visual or FPS change.