xshader: make vop::basic pass — ISA-exact SCC, BFE, fract/log/rsq/sqrt, u32→f32 #24
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!24
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/24/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?
@QuentinDanblon on GitHub · 2026-11-21 18:00 UTC · original
QuentinDanblon:fix/isa-exact-basic→main· +89 −42 · 5 files · 1 commits · closed without mergingLibrary / area: tombox-xshader (ALU translation)
Exports changed (exports.txt rows): none
Source of the behaviour: AMD RDNA2 ISA pseudocode and functional examples; D3D
frctable; LLVMamdgcn_fractfolding; LLVM PR #220911 (BFE width field)At
226938cthe existingtests/exec_vop/basic.rssuites fail:vop::basic::{salu_basic, vop1_basic, vop2_basic, vop3_basic}. Opaque mode (runtime inputs) never ran for salu/vop1/vop3, because constant mode failed first. Once constant mode passed, opaque mode found 3 more bugs. Several of these ops are hot in title shaders (mnemonics.txt:v_sqrt_f3258k uses,v_log_f3257k,v_rsq_f3252k,v_fract_f3228k).Translator fixes
s_lshl_b64s_bfm_b64((1<<S0[5:0])-1) << S1[5:0]in 64 bitss_addk_i32s_bfe_i32,v_bfe_i32tb_bfe_i32v: width mod 32 (ass_bfe_u32already did), width 0 → 0, offset+width ≥ 32 → arithmetic shiftv_fract_f32/f16frac()(WARP returns 0.7 for −3.7)x − floor(x)clamped to 0x3f7fffff / 0x3bff; fract(−0) = +0v_log_f32,v_rsq_f32,v_sqrt_f32log(+INF)constantlog2v_add/sub/subrev_f32precise(no extra ALU in measured DXIL; only the invalid folds are lost)v_cvt_f32_u32v_fma_mix_*tb_fmaCost (DXIL instructions, old intrinsic = 2): fract 8, log 11, rsq 10, sqrt 9, u32→f32 6, v_bfe_i32 13→12. The extra instructions are full-rate integer/select ops. This is the tradeoff to review, given the shader-cost notes in BLOCKERS.md. The results now match the ISA on every host GPU instead of depending on how that driver handles denormals and NaN in
frc/rsq/log. Wrong INF/NaN/denormal edge cases are a plausible source of post-process artifacts (bloom), but I have not checked that against a title.Test-model corrections (
basic.rs,exec.rs)GEN_NANexpectation accepts any NaN only where the ISA generates one. Propagated NaNs and every non-NaN result are still compared exactly. Mnemonics that rely on this:v_sub_f32,v_subrev_f32,v_mad_legacy_f32(INF−INF),v_fract_f32(INF),v_log/rsq/sqrt_f32(negative input).-0 + -floor(-0)gives +0, as does the D3D frc table.v_ceil_f16: the input expression evaluated to a positive denormal (0x10001). It is now the intended negative denormal.v_fma_mixhi_f16: the ISA writes only D[31:16], so the low half is kept.Tests (WARP, DXC 1.9.2609)
--test exec vop::basic: 0/4 → 4/4--test exec: 56 pass / 4 fail → 60 pass / 0 fail (1 ignored, as before)--lib8,--test opcodes22,--test synthetic7: all pass--test fixtureswas not run:analysis/shadersis not in the repo (#13).Not changed:
s_bfe_i64/u64width (LLVM PR suggests mod 64, untested);v_fma_mixlo/mixhiwith f32 multiplicands still round twice (rare difference, documented in the code).cargo test -p tombox-xshaderpassesmissingwith a note@QuentinDanblon on GitHub · 2026-11-21 18:12 UTC · original
Merge note: this PR and #22 both edit the same
CUBE_HELPERSline inhlsl.rs. #22 addstb_cmp_class16aftertb_cmp_class, and this PR rewritestb_bfe_i32. To resolve, keep this PR's version of the line and add #22'sbool tb_cmp_class16(...)line after it. I merged all of my open PRs locally in one tree (#15, #16, #18, #21, #22, #24, #25) and ran the tests there:--test exec70 passed / 0 failed (1 ignored),--lib8,--test opcodes22,--test synthetic8. I can rebase whichever PR lands second.@QuentinDanblon on GitHub · 2026-11-21 18:30 UTC · original
Overlap note: #29 (@artareias) fixes
s_lshl_b64,s_bfm_b64ands_addk_i32, a subset of this PR. This PR also coverss_bfe_i32/v_bfe_i32(width mod 32, the open question in #29),v_fract/log/rsq/sqrt,v_cvt_f32_u32andv_fma_mix, and makes all fourvop::basicsuites pass. If #29 lands first, I'll rebase and drop the duplicated hunks.@QuentinDanblon on GitHub · 2026-11-21 20:23 UTC · original
Two follow-ups.
Hardware run. I ran all my open PRs merged together with
TOMBOX_EXEC_HW=1on an RTX 5090.--test execgives 60 pass / 6 fail, against 57 pass / 9 fail on main on the same GPU. This PR fixessalu_basic,vop2_basicandvop3_basicon hardware too.The 6 that remain also fail on main, only on NVIDIA:
v_trunc/ceil/floor_f32of a NaN return 0x7fffffff instead of the input NaN quieted;v_add_nc_i16loses the destination high half;s_denorm_modeeffect;v_cmp(x)_nlg/ngt_f16: the NVIDIA driver failsCreateGraphicsPipelineStatewith E_OUTOFMEMORY;v_trig_preop_f64: denormal results come back as 0;image_get_lodprecision.I'm working on these in a follow-up stacked on this PR.
Open question on
s_bfe_i32width. This PR follows your test model: width = S1[22:16] mod 32, so width 32 gives 0. Two sources read it differently:SIInstrInfo::splitScalar64BitBFEmasks the scalar width with0x7f0000(7 bits).I can't settle it without RDNA2 hardware. If you have a measured answer, I'll align
s_bfe_i32,s_bfe_u32and the test model with it.@QuentinDanblon on GitHub · 2026-11-21 21:37 UTC · original
Superseded: after the source sync (1159c96/0fc7295), all four vop::basic suites pass on main (WARP, --test exec 70/70). The NVIDIA-only follow-ups will come in a separate PR based on main. Closing.
Pull request closed