Repository navigation
GPU recomp: fix PS interp ints, wave op EXEC zeroing, ALU edge cases, and BVH det underflow - #107
Conversation
…, and BVH det underflow
- 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
|
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: |
…gain (#107 regression) Bisected on XDefiant (warm DXIL cache): 668f550 draws the title screen's text, c813f08 (#107 alone) does not. #107 made v_interp_mov_f32 / v_interp_p2_f32 of an int / uint input a bit copy (what the ISA does). XDefiant's UI pixel shader reads its RenderType (an int input) that way and compares it with 1 / 2: with the bits the text takes those branches (image_sample_d of the font / four image_sample_lz taps at offsets from ds_swizzle derivatives) and draws nothing; with the converted value it takes the default branch and draws the text (red – whether that is the console's colour is not known). Those branches are the open bug; tried and not it: a helper-lane-aware ballot in pixel shaders, not zeroing ds_swizzle sources. #107's test checks the conversion now. The survey takes XCL_DXC_ARGS (comparing DXC optimisation levels). HANDOFF: the regression, the RenderType finding, DXC compile-time measurements; the cold-cache note corrected (the text missing for good was this regression).
|
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: The part: |
Summary
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.