startup: lower v_ldexp_f32 to ldexp32 in gfx2hlsl (Refs #2618) #2913
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2913
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2913"
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?
@Holastor on GitHub · 2026-11-26 19:29 UTC · original
Holastor:fix/gfx2hlsl-v-ldexp-f32→main· +397 −6 · 4 files · 3 commits · merged 2026-11-27 04:19 UTCChange
Refs #2618
RDNA 2 VOP3A instruction
v_ldexp_f32computes exact binary32 scaling by2^deltaon a float value and signed 32-bit integer exponent. Whilepixel_aot.pyalready lowers it via the bitwise IEEE-754 helperldexp32(preserving signed zero, subnormals, infinity, and NaN independently of driver FTZ modes),gfx2hlsl.pypreviously lacked lowering forv_ldexp_f32, causing translation refusals across pipelines that encounter this instruction.ldexp32()to the common shader preamble inPipeline.common().Stage.op_v_ldexp_f32()lowering toldexp32(), accepting float input modifiers onsrc0(negation, absolute value) and output modifiers (such asclamp), while validating and decodingsrc1as a signed 32-bit integer exponent.Stage.f()as(-(-0.5))when the float representation begins with-to avoid the HLSL pre-decrement syntax (--0.5).src1in disassembly and assembly text.v_ldexp_f32_e32, SDWA, DPP, and unusedsrc2or modifier bits in VOP3 machine-code encodings.tests/startup_gfx2hlsl_ldexp_check.pyverifying helper parity withtools/pixel_aot.py, translation correctness across operand combinations, refusal of unencoded forms, and negative controls against mutants.Verification
Commit
78d7a404, based on upstream/main at6ee878d8. Windows 11, Python 3.14.v_ldexp_f32emitsldexp32with expected HLSL expressions across float source modifiers onsrc0(negation, absolute value, combined), exponent formats onsrc1(inline integer, negative inline integer, SGPR/user data, VGPR), and output modifiers (clamp,mul:2).-s4,-v2,|s4|,abs(s4)) are rejected.0x100000000) are rejected._e32, SDWA, DPP forms) are rejected.src2bits.op_v_ldexp_f32, translation raisesUnsupported('v_ldexp_f32').Pipeline.common(), definition parity againsttools/pixel_aot.pyfails.v_ldexp_f32word decodes, parses, and lowers cleanly throughStage.Evidence and follow-up
tests/cmake/startup_gfx2hlsl_ldexp.cmake,tests/checks/python-linux/startup_gfx2hlsl_ldexp.txt.AI-assisted.
@Leyukaka on GitHub · 2026-11-26 20:02 UTC · original
Review of head
3b17c83a, by reading the diff against main6ee878d8(not run).The
ldexp32arithmetic reads as correct:sign | 0x7f800000.tools/pixel_aot.py.Three points:
gfx2hlsl.pycopy ofldexp32.tests/startup_gfx2hlsl_ldexp_check.pyis a substring check of the emitted HLSL or of a refusal message.check_real_cache_sampleis skipped unless a localout/file exists.-s4.ldexp32.pixel_aot.pycopy is executed bytests/pixel_fp32_vulkan_check.py, but nothing ties the two copies together. An equality check against that body, or a compiled and executed call of the helper, would close this._lower()sends_dpptodpp(), which only refusesVOP3_ONLY_VEC_U.dpp_pair()then ends withself.lower(base, ...), which now findsop_v_ldexp_f32. By reading,v_ldexp_f32_dpp v0, v1, v2 quad_perm:[1,1,3,3] row_mask:0xf bank_mask:0xfin a straight-line pixel stage afters_wqmis accepted. This is text input only:v_ldexp_f32is VOP3-only on gfx10, so the disassembler never produces it. Adding it to the refusal next toVOP3_ONLY_VEC_Uwould keep the handler from accepting a form the hardware has no encoding for.src0(sources 241, 243, 245, 247) goes throughf()as(--0.5), which should fail to compile rather than give a wrong value. This handler inherits it, and no test covers it.AI-assisted.
@Holastor on GitHub · 2026-11-26 20:14 UTC · original · edited 2026-11-26 20:16 UTC
Thank you for the thorough review and catch!
Addressed all three points in commit
4276e725:check_helper_parity()intests/startup_gfx2hlsl_ldexp_check.pyasserting exact definition parity betweenPipeline.common()andtools/pixel_aot.py(with a mutant negative control), as well as pure-Python execution of the bitwise IEEE-754 arithmetic across the edge cases (+/-0, +/-inf, NaN, overflow, underflow, and subnormal 2^-150 tie-to-even rounding).v_ldexp_f32toStage.dpp()refusals next toVOP3_ONLY_VEC_U, ensuring that anyv_ldexp_f32_dpptext forms (including quad-swaps) are rejected early. Added test coverage incheck_refusals().Stage.f(), parenthesized negated negative float literals as(-(-0.5))when the float representation begins with-, avoiding the--0.5pre-decrement syntax in HLSL. Added test coverage incheck_translations().@MasterDomino on GitHub · 2026-11-26 20:19 UTC · original · requested changes
Review of head
4276e725onmain6ee878d8, with local runs. I started on3b17c83a. The notes below cover both commits.Environment: Windows 11 build 26300.9974, Python 3.13 (
out/pe-env), Windows SDK 10.0.26100 FXC and DXC.What passes
3b17c83a, andstartup_gfx2hlsl_ldexp_check.pyexits 0 on4276e725.tests/startup_gfx2hlsl_*_check.pyrun on4276e725, because thef()/halff()negation change is shared by every float handler. 130 pass. The other two,export_null_drawandmul24_align_draw, need the CTest arguments and exit 1 the same way onmainwhen run bare.ldexp32body is line-for-line identical totools/pixel_aot.py. Extracted with acsentry that calls it, it compiles withfxc /T cs_5_0anddxc -T cs_6_0. The newcheck_helper_parity()now pins that.3b17c83a,v_ldexp_f32_dpp v0, v1, v2 quad_perm:[1,1,3,3] row_mask:0xf bank_mask:0xfwas accepted through the pair path, which was @Leyukaka's point 2.4276e725adds it to thedpp()refusal, so that is fixed.(-(...))change only changes output that began with--, which never compiled, so it cannot change a previously valid translation.3b17c83a. I took a copy of a local cache with results stripped and rangfx2hlsl.py --pendingwithX2W_FXC=(translation only), once withmainand once with the PR. 4,088 records each:mainok)v_ldexp_f32v_ldexp_f32refusals)ok, now refusedThe 31 records now stop at their next instruction: 15 at a wave operation, 6
s_nand_b*, 4s_lshl*_add_u*, 2 descriptor, and 1 each ofv_mul_f*,v_fmac_f*,s_or_b*ands_load. No record finishes yet, but nothing regresses.Change requested (still open on
4276e725)check_real_cache_samplereads a local title shader request and commits its cache key. It opensout/startup/shader_cache/req_<key>.aattests/startup_gfx2hlsl_ldexp_check.py:225, and the description names the same key. The project accepts only source-built or synthetic fixtures (AGENTS.md "Hard rules"), and on every other machine, CI included, the check silently does nothing. Please remove the function and its call, and take the key out of the description. If you want the decode path covered, a source-built VOP3v_ldexp_f32word run throughG.decodeandlowerdoes that without local data.With that removed, this is ready from my side.
AI-assisted; the commands above were run locally.
@Holastor on GitHub · 2026-11-26 20:31 UTC · original
Thank you for the verification and the census breakdown!
Addressed in commit
78d7a404:check_real_cache_sample()and the reference to the local shader request key.check_decode_and_lower(), which tests decoding andStagelowering using a synthetic source-built VOP3Av_ldexp_f32instruction without any local cache files.@MasterDomino on GitHub · 2026-11-26 21:08 UTC · original · approved these changes
Approving at
78d7a404.check_real_cache_sampleand the request key are gone, from the test and from the description.check_decode_and_lowerbuilds a VOP3A word with opcode0x362(v_ldexp_f32on gfx10), decodes it and lowers it throughStagewithout any local file.startup_gfx2hlsl_ldexp_check.py,startup_gfx2hlsl_compute_check.py,docs_links_check.pyandbidi_controls_check.pyall exit 0.4276e725only the test file changed. My earlier run of all 132startup_gfx2hlsl_*_check.pyon4276e725therefore still covers the translator: 130 passed, and the two draw checks need CTest arguments and fail the same way onmainwhen run bare.v_ldexp_f32, and none regresses.@Leyukaka's three points were addressed in
4276e725, and mine in78d7a404.AI-assisted.
@KelboLive on GitHub · 2026-11-27 04:09 UTC · original · reviewed
Solid V_LD_EXP_F32 lowering implementation. The ldexp32 helper mirrors pixel_aot.py exactly (verified by check_helper_parity), and the test suite is the gold standard for this project.
Key observations:
The f() method fix for double-negation (line 2523) is spot-on:
-(-0.5)was previously rendered as--0.5, which HLSL does not support. The new logic checkstext.startswith('-')and wraps with parens to produce(-(-0.5))instead.Encoding validation correctly isolates neg/abs bits on src1 exponent (w1[30] for neg, w0[9 for abs) and unused src2 field (w1[26:18]), rejecting them before they can be misinterpreted.
The float_sources=1 marking in SCA ensures the exponent operand is treated as integer-only, with modifier detection refusing
-s4,-v2,|s4|,abs(s4)on the exponent side.Negative controls are excellent: removing the handler entirely verifies it's present, and the mutant_op that treats the exponent as float verifies the refusal catches float modifiers.
ldexp32 parity simulation tests: normal scaling, signed zero preservation, infinity/NaN passthrough, clamped overflow/underflow, and subnormal rounding (both tie-to-even cases). This covers the entire IEEE 754 half-life of a float.
One small suggestion for PR #2618 tracking: could you add a one-line reference comment in the helper emission block linking to the issue, similar to the V_PERM_B32 and V_LERP_U8 helpers?
Looks ready to merge after the existing CHANGES_REQUESTED comments are addressed.