Repository navigation
fix(shader): s_lshlN_add SCC and s_bfe_[iu]32 fields past bit 31 - #525
Conversation
s_lshl1..4_add_u32 never wrote SCC; hardware sets it when the shifted-out
bits or the add carry are non-zero. s_bfe_i32/u32 went through
OpBitField{S,U}Extract, which RADV gets wrong when the width runs past
bit 31; build the field from shifts instead.
Adds an execution test for 38 SOP2 opcodes with hardware-captured results.
Co-Authored-By: Claude <noreply@anthropic.com>
92be392 to
03760d9
Compare
|
Rebased on current main: the only Windows failure was |
|
Thanks. I re-checked the rebased head; the commit is the same as before and merges cleanly onto current main. The SCC fix matches the RDNA2 ISA pseudocode for On the bfe half: main's s_bfe is on a very hot path in every title, so I'll run it through my PPSA21564 check before merging. After that it's ready to merge from my side. |
|
Gated on PPSA21564: no visual or FPS change. |
Takes upstream's merged versions of our boykopovar#586 boykopovar#611 boykopovar#612 boykopovar#505 boykopovar#490 boykopovar#619 boykopovar#503 boykopovar#627 boykopovar#628 boykopovar#618 and drops astrobot's local copies, plus gate-batch-3 (boykopovar#469 boykopovar#500 boykopovar#504 boykopovar#509 boykopovar#510 boykopovar#514 boykopovar#525 boykopovar#526 boykopovar#528), round o/p (boykopovar#617 boykopovar#620 boykopovar#621 boykopovar#622 boykopovar#623 boykopovar#624 boykopovar#501 boykopovar#508 boykopovar#629 boykopovar#630 boykopovar#631). Conflicts: - SpirvAnalysis.hpp/.cpp, SpirvBufferAccess.cpp: upstream's boykopovar#586/boykopovar#612. The 64-bit LDS atomics keep the full array (f27d6e5 no longer needed). - SpirvMemoryInstructions.cpp: upstream's constant slot plus offset; astrobot's split-wave append/consume kept. - GuestTextureResource.cpp, TextureTiling.cpp and their tests: upstream's boykopovar#490/boykopovar#503 (astrobot had no other change there). - MaskedSelect.cpp test, ShaderMemory.cpp LDS test: upstream's. - State.cpp: upstream's boykopovar#505 export count and boykopovar#469 null pixel program; astrobot's depth export rejection and depth target model kept. - Pipeline.cpp: upstream's pipeline key; astrobot's depth attachment and blend check (a trailing unused attachment stays valid, as colorGapPipelineTests expects). - Draw.cpp, Recorder.cpp, ShaderResources.cpp: astrobot's (renderPassKey with depth, moved sample functions, residency maintenance), which already hold the merged boykopovar#505/boykopovar#628/boykopovar#490 changes. - ShaderInputState.cpp: both register sets. - State.hpp: the duplicate exportIndex member from the auto-merge removed. - CMakeLists.txt: astrobot's test list (a superset of upstream's). - tests/Graphics.cpp: upstream's CompactedExportTests replaces astrobot's inline copy; tests/Recorder.cpp: upstream's viewPastLastMipTests added.
What
Execution test for 38 SOP2 opcodes that no test ran yet, plus fixes for two bugs it found:
s_lshl1/2/3/4_add_u32never wrote SCC. On hardware SCC = 1 when the 64-bit(S0 << N) + S1doesn't fit in 32 bits, so bits shifted out of S0 count as well as the add carry.s_bfe_i32/s_bfe_u32usedOpBitFieldSExtract/OpBitFieldUExtractwithcount = min(width, 32 - offset). That input is valid SPIR-V (offset + count <= 32), but RADV (Mesa 26.2.4) returns the field as if the width werewidth & 31when it runs past bit 31. Example:s_bfe_i32of0xbde5c099, offset 23, width 37 gives0xfffffffbon RADV and0xffffff7bon hardware and lavapipe. The field is now built from shifts (extractBits32: shift right by the offset, then shift left and back right by32 - min(width, 32), with width 0 giving 0), the waysBfeU64already does it. Every shift amount stays below 32.Opcodes in the test:
s_add_i32,s_sub_i32,s_subb_u32,s_min/max_{i32,u32},s_cselect_b64,s_or/xor/andn2/orn2/nand/nor/xnor_b64,s_xor/andn2/orn2/nor/xnor_b32,s_lshl_b64,s_lshr_b32/b64,s_ashr_i32/i64,s_bfm_b32/b64,s_bfe_i32/u32/u64,s_absdiff_i32,s_lshl1..4_add_u32,s_pack_{ll,lh,hh}_b32_b16,s_mul_hi_{u32,i32}.s_bfe_i64is left out because #234 adds it.Behaviour measured on HW
Radeon 660M (gfx1035, same SALU as gfx1013), 2048 rows of edge and random operands, all 38 opcodes, 100% match with a Python model:
s_absdiff_i32: absolute value of the wrapped 32-bit difference, so0x43892dfcvs0x960d5a8fgives0x52842c93.s_bfe_i32: the field is taken from the arithmetic shift of S0, so a width past bit 31 repeats the sign bit.s_lshlN_add_u32: SCC comes from the unmasked shift, as described above.s_bfm_*,s_pack_*,s_mul_hi_*ands_cselect_b64leave SCC unchanged.The test runs one wave of 32 lanes. A loop reads each lane's operands into SGPRs with
v_readlane_b32, runs the opcodes, and writes the results and SCC back withv_writelane_b32. SCC is packed withs_addc_u32 acc, acc, accafter each op. Each lane stores 64 dwords, compared against the hardware values on 32 rows picked to cover SCC 0/1, zero and negative results, shift amounts >= 32 and bfe widths 0, < 32 and > 32 - offset.Tested
Linux,
agc_driver_scalar_sop2_testson RADV (Radeon 660M), local lavapipe and CI's lavapipe (Mesa 25.2.8): passes. Without the fix it fails: on RADV and lavapipe for the SCC part, on RADV only for the bfe part (lavapipe handles the native extract right). Each piece of the bfe construction (arithmetic first shift,min(width, 32), width-0 select) and of the SCC (shifted-out bits, carry) was mutated separately and the test caught every mutation. Full Release ctest: all pass exceptagc_driver_pixel_helper_lanes, which also fails onmainon this RADV.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)