disasm_rdna2: decode s_waitcnt with the GFX10 counter fields #693
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/699"
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 R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-22T20:52:46Z.
Change
tools/disasm_rdna2.pydecodes thes_waitcntimmediate with the wrong field layout for GFX10. It readsvmcntfromsimm16[7:4], ignores bits[15:14]and never printsexpcnt:On GFX10,
vmcntis split acrosssimm16[3:0](low 4 bits) and[15:14](high 2 bits),expcntis[6:4]andlgkmcntis[13:8]. This is the layout in LLVM 15.0.7AMDGPUBaseInfo.cpp(getVmcntBitShiftLo/WidthLo= 0/4,getVmcntBitShiftHi/WidthHi= 14/2 for major version 9 and 10,getExpcntBitShift= 4,getLgkmcntBitShift/Width= 8/6, anddecodeVmcnt=lo | hi << 4).As a result, the waits a compiler normally emits decode wrongly:
main(3b9bb1a) prints0x3f70s_waitcnt vmcnt(0)s_waitcnt vmcnt(7) lgkmcnt(63)0xc07fs_waitcnt lgkmcnt(0)s_waitcnt vmcnt(7) lgkmcnt(0)0x0070s_waitcnt vmcnt(0) lgkmcnt(0)s_waitcnt vmcnt(7) lgkmcnt(0)0xff0fs_waitcnt expcnt(0)s_waitcnt vmcnt(0) lgkmcnt(63)0x7f70s_waitcnt vmcnt(16)s_waitcnt vmcnt(7) lgkmcnt(63)The bug goes both ways. A real
vmcnt(0)is shown asvmcnt(7), and anexpcnt(0)-only wait is shown asvmcnt(0), which is a VM wait that the shader does not perform.This PR decodes the three fields with the GFX10 layout. It prints them the way
AMDGPUInstPrinter::printWaitFlagdoes: a counter at its maximum (63, 7, 63) is omitted, unless all three are at their maximum, in which case all three are printed. The change is limited to thes_waitcntbranch of the SOPP decoder. The existing golden vector7f008cbfasserted the old output (vmcnt(7) lgkmcnt(0)). Its simm16 is0x007f:vmcntis0xfin the low bits and0in the high bits (15, not 7),expcntis 7 (its maximum, so omitted) andlgkmcntis 0, so LLVM's GFX10 printer givesvmcnt(15) lgkmcnt(0), which is the new expected text.Who is affected
scan_unsupported_shaders.pyuses this decoder for.bininputs. It then passes the decoded lines topixel_aot.lower()to decide translator acceptance.pixel_aotusesvmcntto track outstanding samples (since #176), so the wrong field changes the result. Measured with the program fromtests/pixel_aot_check.pyassembly(False), with its two waits replaced by the decoder's text for their real encodings:0xc07fand0x3f70(lgkmcnt(0), thenvmcnt(0)):maingivesvmcnt(7) lgkmcnt(0)andvmcnt(7) lgkmcnt(63), andlower()rejects the shader (Unsupported pack operand, raised because the sample result is still outstanding). On this branch it is accepted, like the source text.0xff0f(expcnt(0)only, so the sample is not waited for):maingivesvmcnt(0) lgkmcnt(63)andlower()accepts the shader. On this branch it is rejected, as it is for the source text.So for
.bininputs onmain, the census can mark a shader as rejected thatlower()accepts from its source text, and can accept one that reads a sample before waiting for it. This was measured at thelower()call with the scanner's arguments, not by scanning a compiled.bin.disasm_rdna2.pixel_aotand the other*_aot.pylowerers parse assembly text from LLVM, not from this decoder. The only importers arescan_unsupported_shaders.pyandtests/rdna2_tools_check.py.s_waitcnt_vmcnt,s_waitcnt_expcnt,s_waitcnt_lgkmcntands_waitcnt_vscntprint their raw operand, as LLVM does. They are not changed.Verification
Windows 11 (build 26200), Python 3.12.10 venv from
requirements-dev.txt, branch8a891a1on3b9bb1a.New test
test_waitcnt_uses_gfx10_counter_fieldsintests/rdna2_tools_check.py. Ten encodings, each followed bys_endpgm. The test checks the assembly text, that each record is 4 bytes, and that the scanner accepts the line.llvm/test/MC/Disassembler/AMDGPU/gfx10_dasm_all.txt:0x0000,0x1234and0xc151. The last one givesvmcnt(49), so it needs the high bits.0xc1d1fromllvm/test/MC/AMDGPU/gfx10_asm_sop.s, where bit 7 is set and unused.test_llvm_comparison, needsLLVM_LIB; CI runs it on Linux. That test compares assembly text only forv_,expand memory opcodes, which is why it never caught this bug).main'sdisasm_rdna2.py: all 10 subtests fail (for example's_waitcnt vmcnt(5) lgkmcnt(1)' != 's_waitcnt vmcnt(49) expcnt(5) lgkmcnt(1)').AGENTS.md, plustests/pixel_aot_check.pywithout thebinaryargument: all exit 0.Audit (not added to the repository). The script decodes every
s_waitcntin the LLVM 15.0.7 GFX10 MC fixtures, then every simm16 value:main3b9bb1as_waitcntencodings in the GFX10 fixtures (gfx10_dasm_all.txt×3,gfx10_asm_sop.s×3) decoded differently from LLVMvmcntvalue differsexpcntwait differsvmcnt(0)but the realvmcntis not 0 (a wait that is not there)vmcnt(0)not shown asvmcnt(0)The reference for the full sweep is
decodeWaitcntandprintWaitFlag, transcribed fromAMDGPUBaseInfo.cppandAMDGPUInstPrinter.cppatllvmorg-15.0.7. The transcription reproduces the three lines LLVM prints ingfx10_dasm_all.txt. Those fixtures hold only three plains_waitcntencodings for GFX10, so the sweep is what covers the rest of the field space. The GFX10s_waitcntfixtures ingfx10_asm_sop.sgive only an encoding (operands0x0,0x1234,0xc1d1), so their expected text comes from the same transcription.Negative controls. Each mutation was applied to a scratch copy of
tools/andtests/, and the new test was run. All eight fail:vmcnthigh bits[15:14]ignoredvmcntread from[7:4](as onmain)vmcnthigh bits taken from[13:12]expcntread as 4 bits[7:4]lgkmcntread as 4 bits (pre-GFX10 width)vmcntmaximum taken as 15Open pull requests.
git merge-treewas run against the 13 open PRs that touchdisasm_rdna2.py,rdna2_tools_check.pyorscan_unsupported_shaders.py. The change adds no conflict to any of them. #624, #531 and #528 already conflict withmainin other files, and the conflicting files are the same with this branch. The branch was also merged locally with each of #693, #576 and #621, andrdna2_tools_check.pypasses in all three.Evidence and follow-up
gfx10_dasm_all.txt,gfx10_asm_sop.s, Apache-2.0 WITH LLVM-exception) or are derived from the field layout above. No game data.llvm-mcfor AMDGPU locally, because the official Windows LLVM build ships only the x86 target. The reference is the fixture bytes and text plus the transcribed LLVM source, not a local LLVM run.vmcnt[15:10],expcnt[2:0],lgkmcnt[9:4]). The decoder does not handle that layout, and this PR does not add it.pixel_aotalready accept it, includingexpcnt(N)and three counters.s_waitcnt_depctr(SOPP0x23) is still not in the SOPP table and decodes ass_sopp_23 0x<imm>. That can be a separate PR.Checklist
AI-assisted: yes. Prepared with an AI coding agent; I checked the results above.