refactor(recompiler): emit the v_fma_mixlo/hi and v_interp_*_f16 emulation once per module #4932
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4932"
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 fdfawef324 on 2026-10-13T05:09:27Z.
What
FPInterpolateF16andFPInterpolateF32(fromv_fma_mixlo_f16,v_fma_mixhi_f16,v_interp_p1ll_f16,v_interp_p1lv_f16andv_interp_p2_f16) were lowered by expandingInterpolateinSpirvAluEmitterFloat64.cppinline at every use. One expansion is 1203 SPIR-V words (a 1158-word body and 15NoContractiondecorations), and wave64 shaders emit it twice per instruction, once per half.Interpolateis now emitted once per module as aDontInlinehelper function per result width and float mode, created on first use like the formatted buffer helpers, and every use is anOpFunctionCall.Semantics are unchanged and come from the existing implementation on
main: the function body isInterpolateitself, called with the samehalfResultand mode, so rounding, denormal flushes, NaN propagation and the f16 overflow handling are the same instructions. Operand selection and theop_sel/neg/absmodifiers are applied in Translation before the IR op and are not touched.v_fma_mix_f32is not part of this change: it already lowers to a nativeFma(11 words per use).Measured with
agc_shader_replayon the Demon's Souls requests in the local run directory,mainate51428bf2(word counts, not a speed claim):0x248910200 has no saved request, so it was not measured. Over the 66 requests in that directory that recompile (17 others fail resource analysis on
mainand with this PR alike), the total goes from 12735297 to 12594249 words; only the two programs above contain these instructions, and the other 64 modules are byte-identical.In 0x2489ed100 the four largest basic blocks of
main(three of 28012 words and one of 28041) each hold 16 inline expansions (8 instructions, two wave halves) with their f16 conversions. Denormal flushing costs nothing in these shaders (mode 0; the mix path requires f16 denormals to be kept).For both changed modules, each
OpFunctionCallwas replaced by the helper's body with parameters substituted, and the result was compared withmainafter renaming ids, using constant values, type shapes, decorations and operand dataflow: the instruction streams are identical.Related
#4171 (karanvora2599, open) changes the same
Interpolatecode: it renames it toInterpolateExact, moves the denormal flushes out and adds an f32 fast path, and it editsSpirvEmitterState.hppas well. The two conflict. If #4171 merges first I will rebase this onto it and emit its exact and fast paths once per module the same way; if this one merges first, its helper key (result width and float mode) is where the exact/fast choice would go.Tested
Current head
8847086a0is rebased onto84b01f9cd, retaining the new vertex-input test, grouped BDA loads and rounding frontend. Fresh-O3CPU builds of 48 actual production units plus a direct backend fixture and the actual main inline control pass their expected verdicts. Two repeated calls reuse each of 16 result-width/mode helper keys: 17 functions including the entry point and 32 calls. The same helper-count fixture fails with the actual current-main inline emitter. The matching whole FmaMixOnce translation unit, conventions and diff checks pass. These checks establish helper structure and reuse; no fresh current-head numerical, native GPU or title execution is claimed. The GPU and replay results below are historical at the revisions explicitly recorded.Windows Server 2025, RTX 3060, GCC 15.2.
agc_fma_mix_once: compiles a wave32 compute shader with 0, 1 and 3 chainedv_fma_mixlo_f16/v_fma_mixhi_f16and requires that the two extra uses add fewer words than the first use with its shared function, that the first use adds one function and that the extra uses add none. With the fix reverted it fails (2 more v_fma_mixlo/mixhi_f16 added 3657 SPIR-V words, as many as the first one with its shared emulation (2379)). With the fix it passes (697 words without the instruction, 3116 for one, 4381 for three).mainand with this PR:agc_driver_mix_precision,agc_driver_interpolation_modes(all 8 float modes, callingEmitFPInterpolateF16/F32directly),agc_driver_interpolation_f16,agc_driver_fp16_overflow,agc_driver_f32_arithmetic_nan,agc_driver_f32_denormal_flush,agc_driver_fma_rounding,agc_driver_float16_fma_rounding,agc_driver_float16_result_modifiers,agc_driver_float16_misc,agc_driver_packed_float16_native,agc_driver_pixel_barycentric_emulation,agc_driver_graphics,agc_driver_prepared_graphics,agc_driver_prepared_unregistered_graphics,agc_shader_memoryand its variants,agc_vop3_interp_decode,agc_interpolant_mapping,agc_float16_conversion,agc_formatted_buffer_once.agc_*andshader_*ctest tests built and run with the fix one51428bf2(ctest -R "^(agc_|shader_)" -j 4): all pass.agc_storage_upload_lifetimehit its 30 s timeout once under the parallel run and passed when rerun alone.agc_shader_replaybefore and after on every request above. The tool only recompiles; it cannot execute the shaders, so the replay compares word counts and the SPIR-V itself, not output values.agc_vector_fused_multiply_add(core/libs/tests/VectorFusedMultiplyAdd.cpp, which also covers the mix instructions) passes onmainand with this PR.main3cfb915cf(one conflict in the driver test list, both entries kept);agc_fma_mix_once,agc_driver_mix_precisionandagc_driver_interpolation_f16were rebuilt and pass on it. The other results above are frommaine51428bf2.python -I tools/check_test_registration.py build-dev: 746 test executables, none built and not run.ANYPS5_ENABLE_SPIRV_TOOLSis off in this build), Linux or lavapipe.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)🤖 Generated with Claude Code
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T07:12:18Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
88107b7detogether with thirteen other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:tests/FmaMixOnce.cpp(agc_fma_mix_once): 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:26:47Z.
Checked the diff, built and ran Agc/AgcDriver ctest:
agc_fma_mix_oncepasses and fails with the SpirvAlu change reverted;agc_driver_interpolation_modes,agc_driver_mix_precisionpass (lavapipe). The helper body is the existingInterpolate, so semantics are unchanged. Merging once the full Build is green.