fix(shader): apply the VOP3 accumulator modifiers of v_fmac_f32 #18285
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18285"
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 angrysandhill on 2026-11-11T03:14:54Z.
What
VOP3-encoded
v_mac_f32(0x11f) andv_fmac_f32(0x12b) dropped their src2absandnegbits without a word. The decode of VOP2 opcodes in the VOP3 encoding applies only the modifier bits of the two explicit sources. Onv_fmac_f32, though, bit 2 modifies the accumulator, which is the destination register.Measured on RDNA2 hardware (gfx1031):
v_fmac_f32withnegbit 2 computesfma(a, b, -d), and withabsbit 2fma(a, b, |d|).v7, the accumulator is stillvdst.The change:
v_fmac_f32the two bits are kept onsource2, andaccumulatorOperand()copies them onto the accumulator it reads.v_mac_f32(0x11f) andv_mac_legacy_f32(0x106): these exist only on gfx10.1, so they could not be measured here. They now refuse the bits withVOP3 source modifiers are not implementedinstead of dropping them. That condition sits inside the existing throw, so no throw site is added.Tested
Setup: Windows 10 Home 22H2 (10.0.19045), AMD Radeon RX 6750 XT (gfx1031), AMD Software Adrenalin 26.10.1 (driver 32.0.21045.16010), WinLibs GCC 15.2.0 r7 UCRT, Release,
BUILD_TESTING=ON, onmainbaed587feb.Hardware (hardware oracle, HIP runtime). The rows combine 14 values of each of
aandbwith 7 accumulators, 1,372 rows in all:aandb: ±0, ±1, 0.5, 2, max, min normal, the smallest denormal, 1 + 1 ulp, ±infinity, a quiet NaN and a signalling NaN;0x7fc00001, the smallest denormal and −3. They were run in four float-mode settings: IEEE 0 with f32 denormals flushed; IEEE 1 with them kept; rounding up; and DX10 clamp 0 with rounding toward zero. The last three also ran in wave64.negbit 2 givesv_fma_f32 a, b, -con 1,372 of 1,372 rows.absbit 2 givesv_fma_f32 a, b, |c|on 1,372 of 1,372 rows.v7still accumulates intovdst, 1,372 of 1,372 (first setting).Recompiler against the hardware. The same assembled body and rows were run through the recompiler with
HW_ORACLE_RUNTIME=vulkanand compared row by row. M1 is FLOAT_MODE0xf0with IEEE; M2 is0xc0. Rows differing from the hardware, out of 1,372:main-acc, M1 / M2|acc|, M1 / M2The 4 rows left in M2 are the same four rows with and without a modifier: a flushed denormal times ±infinity, with a NaN accumulator. They don't come from this change.
Tests:
agc_driver_vfmac_f32_accumulator_modifiers: 16 rows, each run plain, with-accand with|acc|, in M1 and M2. The expected values are the hardware's.main:v_fmac_f32 -acc M1: lane 0 of 0x3f800000 * 0x40000000 + 0x3f800000 is 0x40400000, expected 0x3f800000.0xf0, which keeps f32 denormals) leaves out the lanes with an f32 denormal input or result there, and the pass line says how many. Such a device leaves those results to the driver's default, as the f32 denormals debt entry records for this mode: an RTX 3050 gave-0for0x80000001(reported below). Simulated here by forcingfloat32DenormPreserveoff onmainafe2226017with this PR merged: the earlier version of the test fails with that same message, this one passes.GLSL.std.450 Fmaas a multiply and an add, whichagc_driver_fma_roundingalready allows for. Only plain rows 13 (3 * 0x3eaaaaab - 1) and 14 (max * 2 - max) give different results the two ways. Sinceb10938aae8, when plain row 13 in M1 gives the separately rounded result, both rows are checked against the separately rounded values (0x00000000,0x7f800000), and the test says so. A Vega 56 on RADV gave0x00000000for row 13 (reported below). Simulated here by having the recompiler emit the f32 fma as a multiply and an add: the earlier version of the test fails with that same message; this one passes and prints the note, also under the validation layer with noVUID-line; with this PR's two source files reverted it still fails, on-acc:lane 0 of 0x3f800000 * 0x40000000 + 0x3f800000 is 0x40400000, expected 0x3f800000.agc_vop2_encoding_decode:v_fmac_f32with the accumulator bits decodes with them onsource2only, andv_mac_f32and0x106with them are refused. Onmainthesource2check and the two refusals fail. The two new accepted entries pass there too, because the accepted loop checks only the opcode and length.^(agc_|shader), 4 at a time: per test identical tomain(1,584 passed, 17 skipped), plus the new test passing. One test fails on both sides:agc_driver_sample_order_grid_reference, which #9503 addresses.main, and the same 30 plus the new test here, serially, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andctest -V.VUID-lines on both.was not found but was requested by env var VK_INSTANCE_LAYERS. Every test that opens a device logs the layer insertion; the two decoder tests open none.Not measured: the PS5's gfx1013.
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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T19:15:05Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
PR #18285 at head
b10938aae8f8ac38999af4d9ffbeac003f920db8(basemain) makes the VOP3v_fmac_f32decoder keep its src2absandnegbits and apply them to the accumulator, and refuses those bits onv_mac_f32and0x106instead of dropping them. The code matches the description.What I ran
b10938aae8f8ac38999af4d9ffbeac003f920db8, basemain. No merged-preview check.files/copies and fromrepo_read.pyat the pinned head:Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/Vop2EncodingDecode.cpp:34: the two new accepted entries (lines 34–35) cannot fail onmain. The accepted loop checks only the opcode and length (file lines 58–71), so the modifier bits are asserted only by the trailing block at lines 86–97. The description says "the three new checks fail on main"; onmainthe two refused entries (lines 54–55) and the trailing block fail, and the accepted entries pass.core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp:2452:readsVop2AccumulatorincludesVMacLegacyF32. For opcode0x106with bit 2 set,checkNativeVop3Modifiersalready throws (line 2098), so the new assignment never runs for it. Harmless; narrowing the helper toVMacF32would make that explicit.core/libs/prx/libSceAgcDriver/tests/execution/VFmacF32AccumulatorModifiers.cpp:153: the file usesstd::spanandstd::as_bytesbut includes no<span>. It compiles only if another header brings it in; not verified.Not verified
float16NativeFma(FloatInstructions.cpp:265, accumulator read at:314) is taken forFPFma32when the native f16 fma mode holds. I did not readreadF16Bits, so I cannot say whether it applies the copiednegateandabsoluteforv_fmac_f32.accumulatorOperandcallers (FloatInstructions.cppandIntegerInstructions.cpp): the decoder sets src2 modifiers only forVMacF32andVMacLegacyF32, and only with bit 2, so the copy changes nothing for them. Checked by reading the call sites.Vop2EncodingDecode.cpp(the diff and lines 56–83);VFmacF32AccumulatorModifiers.cpp(whole file, new in the diff);RdnaVectorOpDecoder.cpp(the touched hunks and helpers at lines 1036–1051, 1904–1933, 2195–2201, 2395–2479, not the full 2,576 lines);OperandAccess.cpp(the diff hunk and call sites, not the full 753 lines). No files were excluded.Sources
github.com/boykopovar/AnyPS5@b10938aae8/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp (L2449-L2455)github.com/boykopovar/AnyPS5@b10938aae8/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp (L70-L75)To get this to a good state
Nothing is required. The optional points are the non-blocking items above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T02:27:27Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
85129d854db998852ff7da5239c06beaf5b97198using the prepared diff and repository reader. I did not run tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No test commands or hardware checks were run. Read:
core/libs/prx/libSceAgcDriver/tests/Vop2EncodingDecode.cpp,core/libs/prx/libSceAgcDriver/tests/execution/VFmacF32AccumulatorModifiers.cpp,core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp, andcore/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp. No changed files were excluded;files.jsonwas not available in the review folder, so exclusions were not independently checked.To get this to a good state
Nothing is required.