fix(shader): apply legacy MAD/MAC output modifiers across denormal modes #28479
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28479"
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?
Imported from boykopovar/AnyPS5. Originally posted by DannyOppenheimer on 2026-11-30T22:58:16Z.
What
Measure VOP3 result modifiers (
mul:2,mul:4,div:2,clamp) onv_mad_legacy_f32(0x140) andv_mac_legacy_f32_e64(0x106) natively on RDNA1 (gfx1010) and fix theirFLOAT_MODE/s_denorm_modegating:gfx1010viatools/hw-oracle): because legacy MAD/MAC flush f32 denormal inputs, tiny products, and results in everydenorm32mode (0..3), onlyIEEE_MODEgatesomod. BothFLOAT_MODEdenorm32 = 0..3and dynamics_denorm_mode 0..3applymul:2/mul:4/div:2wheneverIEEE_MODE == 0.div:2on[2^-126, 2^-125)returns signed zero (±0.0) in all fourround32modes (0..3),mul:2/mul:4overflow followsround32, andclampexecutes afteromod(-0.0to+0.0, NaN to0ifDX10_CLAMP == 1).core/shader/recompiler/Translation/src/FloatInstructions.cpp(TranslationContext::vFmaLegacyF32): applyscaleF32Result(destination.omod, IrF32(*value))directly whendestination.omod != 0u && !ieeeModeand zerodestination.omodbeforewriteOperand(destination, value)(matchingfloatCube), instead of delegatingomodtooutputModifierApplies(4u)which disabled scaling ondenorm32 >= 2and could not models_denorm_mode.core/libs/prx/libSceAgcDriver/tests/execution/F32OutputModifier.cpp: fixCheckLegacyModifiersto expect scaling whenever!mode.ieeeMode, addLegacyModeAndSourceCodecoverings_denorm_mode 3/2/1/0and VOP3neg/abssource modifiers withomod/clamp, and extend the legacy rows with-2^-126div:2, flushed-0.0(-2^-126 * 1.5 + 2^-126),±FLT_MAXoverflow acrossround320..3, andsNaN(ieee=0/1,dx10Clamp=0/1).docs/dev/debt/changes/fix-gfx1013-legacy-mad-mac-modifiers.md: update the unfolded shader debt entry to record the nativegfx1010measurements and gating behavior while leavingCloses when: compared with native gfx1013..Overlap note:
tools/pr_overlap.py --branch fix/gfx1010-legacy-mad-mac-modifiersflagged PR #26100 (FloatInstructions.cpparoundvFmaLegacyF32lines 889–891) and uncompared PR #19505. Manual comparison shows #19505 covers unrelated scalarf16directed rounding and #26100 covers directed rounding of the legacy product/addend without modifying VOP3 result modifiers (and builds on#19710), so there is no functional overlap.Tested
tools/hw-oracle,HIP_VISIBLE_DEVICES=1,AMD Radeon RX 5700 XT,gfx1010, AMD Windows driver32.0.21045.29003, Windows 11 Home10.0.26200):819input triples ×64(round32 0..3,ieee 0/1,dx10_clamp 0/1,denorm32 0..3) configs ×16encodings (v_mad_legacy_f32andv_mac_legacy_f32_e64×none/mul:2/mul:4/div:2× unclamped/clamp, mixing wave32/wave64):0mismatches across838,656results.HW_ORACLE_RUNTIME=vulkan(agc_oracle_runner) vs native HIPgfx1010:2,652mismatches on baseline76d0a4a7dcdf(main_16cfg:1,584,src_mods:540,s_denorm_mode:528) reduced to0mismatches onacac33539731across262,144results (1,024rows ×16configs ×16forms atround32=0), exactround321..3overflow/underflow cases, source modifiers, ands_denorm_mode0..3.tools/vulkan_validation_gate.py, Khronos validation layer1.4.369,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer):AMD Radeon RX 5700 XT:8/8tests passed across2iterations on both baseline (76d0a4a7dcdf) and candidate (acac33539731) (agc_driver_dx10_clamp,agc_driver_f32_denormal_flush,agc_driver_f32_output_modifier,agc_driver_f32_result_clamp,agc_driver_fma_legacy,agc_driver_legacy_product_tininess,agc_driver_mac_legacy,agc_driver_transcendental_output_modifier),Insert instance layer "VK_LAYER_KHRONOS_validation"logged8times per iteration (0missing-layer lines,0skipped,0VUID-diagnostics).AMD Radeon(TM) Graphics: same8focusedctest -Vruns under identical validation environment passed on both baseline (8/8in9.37 s) and candidate (8/8in11.25 s),Insert instance layer "VK_LAYER_KHRONOS_validation"logged8times each,0missing-layer lines,0VUID-diagnostics.acac33539731):ctest -V:5/5passed (agc_shader_mode_register,vector_constant_factor_tininess,vector_fused_multiply_add,vector_half_double_output_modifiers,vector_mad_legacy).python tools/debt_fold.py --check,python tools/check_conventions.py, andpython tools/pr_overlap.py --branch fix/gfx1010-legacy-mad-mac-modifierspassed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T23:01:11Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
acac3353973176359dad4e885f64eafcc89883caby inspecting the prepared diff and changed files, plus pinned source context fromrepo_read.py. No tests or builds were run.The reader printed the requested source, but could not append its audit log because the run directory is read-only.
Results
Negative control
Not run; no tests were run during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
The changed translation applies
scaleF32ResultwhenIEEE_MODEis off, clearsomod, and leaves clamp processing towriteOperand, matching the existing result-modifier pattern infloatCube(changed implementation). The associated test additions exercise denormal modes, source modifiers, clamp, NaNs, and directed-rounding overflow (test changes).Not verified
Hardware oracle results, Vulkan validation, CTest, and repository checks were not independently run; those results are reported in the PR description. Files read:
core/libs/prx/libSceAgcDriver/tests/execution/F32OutputModifier.cpp,core/shader/recompiler/Translation/src/FloatInstructions.cpp, anddocs/dev/debt/changes/fix-gfx1013-legacy-mad-mac-modifiers.md. No files listed underreviewedwere excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:26:05Z.
Review: COMMENTED
Both agc_driver_f32_output_modifier and agc_driver_gcn_scalar_buffer_base passed on the main baseline (
96401c8077) and the patch. The changed fixture exercises legacy MAD and MAC results with the modifier, clamp and denormal combinations. Both runs used Linux lavapipe with Vulkan required and the shader cache disabled. The loader inserted Khronos validation 1.4.369, and neither log contained a VUID.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.