Repository navigation
fix(shader): address ds_append and ds_consume on LDS by the instruction offset alone - #523
Conversation
…on offset alone On LDS the counter is at the instruction offset. The emitter added M0[31:16] to it and required the offset to be below M0[15:0], which is the GDS base and a size no other LDS access reads. The GDS path is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, this is right. AMD's machine-readable ISA (RDNA1, RDNA2, RDNA3) puts the LDS counter at the instruction offset, and Mesa agrees in practice: ACO emits The new test fails on main here with |
|
@oneandonlydean measured on RDNA2 hardware (gfx1035), confirming the fix: on LDS, |
|
Checked against gfx1035 hardware (M0 plays no part on LDS), build + full ctest on RADV, and the new test fails without the change; merging. |
What
ds_appendandds_consumeon LDS updated the wrong dword, or nothing at all, depending on M0.The emitter computed the counter address as
M0[31:16] + offsetand requiredoffset + 3 < M0[15:0]for both data shares. On LDS the counter is at the instruction offset: M0 holds the base only for GDS. With this change the LDS path uses the instruction offset alone and is bounded by the LDS allocation, like every other LDS access in the emitter. The GDS path is unchanged.Source: AMD's machine-readable ISA specification (RDNA1, RDNA2 and RDNA3 agree),
DS_APPEND/DS_CONSUME: "Add (count_bits(exec_mask)) to the value stored in DS memory at (M0.base + instr_offset) if GDS, or at instr_offset if LDS. Return the pre-operation value to VGPRs."The specification does not describe an M0 size limit on LDS, and LLVM's
ldsRequiresM0Init()is false from GFX9 on, so theM0[15:0]check is dropped for LDS. Not measured on hardware.Test
agc_driver_ds_append_consume, the first test of these two instructions: one wave32 compute shader, counters at fixed LDS offsets written by lane 0. It checks the value returned to every lane, the counter afterwards, and that the dword atM0.base + offsetis left alone, for:ds_appendandds_consumewith all 32 lanes active andM0 = 0x0040ffffds_appendandds_consumewith EXEC = low 16 lanes andM0 = 0x00400000(size 0): inactive lanes keep their destination registerIt is skipped on devices whose subgroups are narrower than the wave, as
agc_driver_ds_permuteis. GDS is not covered: a GDS binding cannot be created onmain.Tested
Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA (32-lane subgroups), full
ctest: 184/184 pass.agc_driver_ds_append_consumefails withlane 0 ds_append result is 5000, expected 1000(the dword atM0.base + offsetwas used).M0[15:0]check kept on LDS it fails withlane 0 masked ds_append result is 0, expected 3000.No title was run.
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