GPU recomp: fix PS interp ints, wave op EXEC zeroing, ALU edge cases, and BVH det underflow #107
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!107
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/107/head"
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?
@raylitebull on GitHub · 2026-11-23 11:17 UTC · original
raylitebull:fix/recomp-alu-interp-and-wave-ops→main· +381 −35 · 3 files · 1 commits · merged 2026-11-23 11:32 UTCSummary
Fixes 8 RDNA2 recompiler & BVH correctness bugs in
crates/xcl/src/gpu/recomp/emit.rsandcrates/xcl/src/gpu/bvh.rs:v_interp_mov_f32/v_interp_p2_f32corrupting integer PS inputs (emit.rs):asuint((float)xi.a{slot}[{chan}])toasuint(xi.a{slot}[{chan}])sonointerpolation uint/intPS inputs preserve their exact bit patterns instead of undergoing integer-to-float conversion beforeasuint.ds_swizzle_b32/ds_bpermute_b32not zeroing inactive source lanes (emit.rs):select(lanebit_at(exec_lo, eh, src_lane), t, 0u)after lane exchange so inactive source lanes (EXEC[src] == 0) return0per RDNA2 ISA across native wave32, native wave64, andsplit_wave64.v_ldexp_f32overflow/underflow/NaN on large exponents (emit.rs):ldexp(x, (float)(int)b)(x * exp2(b), which fails for|b| >= 127,0 * Inf, andInf * 0) with a bit-exact IEEE-754ldexp_f(float x, int n)helper handling|n| >= 127,±0,±Inf,NaN, and subnormals.32-bit literal (
code == 255) placement inf64instructions (emit.rs):f64: boolthroughcode64/read64so 32-bit literals populate the upper 32 bits ({0u, lit}) for*_f64ops while preserving{lit, 0u}for 64-bit integer/bitmask ops.v_cvt_pknorm_i16_f32NaN &fmt_encodeSNORM NaN / 11-11-10 unsigned float sign loss (emit.rs):isnan(f)to0.0fbefore clamping incvt_norm_i16_f32and SNORMfmt_encode(instead ofclamp(NaN, -1, 1)yielding-1.0f/-32767).f <= 0.0fto0uand preserved NaN encoding (0x7E0u/0x3F0u) in 11/10-bit unsigned floatfmt_encode(previously negative floats had their sign bit stripped and became positive).Signed bitfield extract (
s_bfe_i64,s_bfe_i32,v_bfe_i32) logical shift (emit.rs):((int64_t)v) >> o/((int)v) >> o) before sign extension so extractions crossing the MSB (o + w > 32/64orw >= 64) sign-extend properly.v_cmp_class_f16destroying f16 sNaN (emit.rs):abs(& 0x7FFFu) andneg(^ 0x8000u) bitwise directly on the 16-bit half beforefclass16, avoiding thef16tof32/f32tof16round-trip that quieted sNaN (0x7C01) to qNaN (0x7E00).BVH triangle intersection
det * detunderflow/overflow (bvh.rs,emit.rs):(i + j) * det <= det * detwith sign-based barycentric comparisons in both Rustbvh::triangle_hitand HLSLbvh_intersect, preventing false hits on small triangles (|det| < 1.08e-19) and overflow on large triangles (|det| > 1.84e19).Testing
ps_interp_preserves_integer_and_float_inputsgpu_ds_swizzle_and_bpermute_zero_inactive_lanesgpu_ldexp_f32gpu_f64_literal_high_wordgpu_pknorm_i16_f32_nan_and_fmt_encode_snorm_ufloatgpu_signed_bfe_arithmetic_shiftgpu_cmp_class_f16_preserves_snantriangle_hit_small_and_large_det_avoids_underflow_and_overflow32.0.32015.2008(GPU wave/recompiler tests verified on AMD only).origin/main(c85cd6f):cargo build --workspaceandcargo test --workspace -- --test-threads=4pass with 0 failures and 0 new warnings.- v_interp_mov_f32 / v_interp_p2_f32: use asuint(xi.a{slot}[{chan}]) directly instead of casting through float, preserving uint/int PS inputs - ds_swizzle_b32 / ds_bpermute_b32: zero results when the source lane is inactive in EXEC (native wave32/64 and split_wave64) - v_ldexp_f32: replace HLSL ldexp() with bit-exact ldexp_f() handling |n| >= 127, +-0, +-inf, NaN, and subnormals - f64 32-bit literal (code 255): place literal in high 32 bits for f64 ops while keeping low 32 bits for integer/bitmask ops - v_cvt_pknorm_i16_f32 & fmt_encode: map NaN to 0 for SNORM conversions, clamp <= 0 to 0 and preserve NaN for 11/10-bit unsigned float formats - s_bfe_i64 / s_bfe_i32 / v_bfe_i32: arithmetic-shift before sign extension so o + w > width and w >= 64 preserve the sign bit - v_cmp_class_f16: apply abs/neg bitwise on the 16-bit half so sNaN is not quieted by an f32 round-trip - bvh::triangle_hit & HLSL bvh_intersect: replace det * det comparison with sign-based barycentric test to avoid underflow/overflow@ivall on GitHub · 2026-11-23 11:32 UTC · original
Merged. On the retail shader pack it still translates 26 698 / 26 698 programs in full, and DXC on every 150th record (179 variants) gives 0 errors. Checked on Windows 11 with an RX 9070:
cargo test --workspacegreen with the retail samples (shader pack, console DLLs, texture archive), lib tests also withXCL_SPLIT_WAVE64=1; Unicorn Overlord runs with #107–#109 merged. Thanks!@ivall on GitHub · 2026-11-23 12:33 UTC · original
Heads-up: one part of this PR is reverted in
58309b9– it broke XDefiant's title-screen text (bisected on an RX 9070 with a warm DXIL cache:668f550draws it,c813f08= this merge alone does not).The part:
v_interp_mov_f32/v_interp_p2_f32of int / uint PS inputs as a bit copy (asuint(xi.aN[c])). That is what the ISA does, but XDefiant's UI pixel shader reads itsRenderType(anint4input) this way and compares it with 1 / 2 (v_cmpx_eq_u32). With the bits, the text takes those branches – RenderType 1 samples the font withimage_sample_d, 2 takes fourimage_sample_lztaps at offsets built fromds_swizzlederivatives – and draws nothing; with the old converted value (never 1 or 2) it takes the default branch and the text is drawn. So the bit copy is probably right and something in those two branches is wrong (gradients / derivatives); I tried a helper-lane-awareballotfor pixel shaders and leavingds_swizzlesources unzeroed – neither brought the text back. Notes in HANDOFF ("XDefiant's UI text: the #107 regression"). If you want to dig in, the shader is the UI PS with inputsIO2_UI_UserBig0,IO4_UI_UserSmall0,IO6_UI_RenderType0(int4),IO7_Gfx_Color0.