feat(shader): bit-exact RDNA v_rcp_f32 behind APS5_EXACT_RCP #9305
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9305"
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 tibzejoker on 2026-10-21T17:56:45Z.
What
Follow-up to #7671, which was closed because the console's
v_rcp_f32is not correctly rounded, and a target that differs from the console is not wanted. This PR emits the RDNA reciprocal itself, bit for bit, behind an opt-in switch. The default output is unchanged.APS5_EXACT_RCPset,v_rcp_f32andv_rcp_iflag_f32on a normal input with a normal result compute the hardware's datapath in 32-bit integer arithmetic:m >> 18), with its linear term rounded to nearest even (shift 14, or 15 when the product reaches 2^38);DontInlinefunction, which only runs when the 6 dropped bits are within 2 of the rounding cut, so 6.25 % of inputs.1/x, as now.v_rcp_f32gains at least 13.6k words, and the total grows by 28 %. That is too much to pay by default for a difference no title has shown visibly. It suits comparisons against hardware and titles that depend on the exact bits.Generated::RecompilerSwitches). It is documented inENVIRONMENT.md, and there is an entry indocs/dev/debt/shader.md.Tested
Windows 11 26200, WinLibs GCC 15.2.0 r7, Release.
agc_driver_rcp_hardware. It checks 256 measured RDNA 2 (input, output) pairs, 128 of them where the correction table applies, each at 6 exponents and both signs.agc_driver_rcp_hardware_exactsetsAPS5_EXACT_RCP=1and passes on the RTX 4090 and the UHD 770.main's recompiler and the same switch, it fails on both GPUs:v_rcp_f32 of 0x00813df5 is 0x7e7d8a33, expected the RDNA 2 value 0x7e7d8a32on NVIDIA, and0x00802922 is 0x7e7fadd7, expected 0x7e7fadd6on Intel.^agcsuite. 879 of 883 pass. The four left fail the same way onmain:agc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locationsfail withmain's recompiler too, andagc_driver_image_array_window_past_layer_limitdoes not compile with MinGW (requested alignment 65536 exceeds 8192).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
https://claude.ai/code/session_017EjjFU1FjMR11oWDYs8UMo
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T23:21:49Z.
Review: COMMENTED
Confirmed
red→greenon Linux, and on lavapipe as a third device (the PR's runs are an RTX 4090 and an Intel UHD 770, both on Windows). lavapipe is a software rasterizer, so it is a useful reference here: its nativev_rcp_f32also diverges from the RDNA 2 value, and the correction table makes it bit-exact too.Tested
Ubuntu 26.04, Intel i7-8700, GCC 15.2.0, Release,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, device selected withVK_ICD_FILENAMES, run asAPS5_EXACT_RCP=1 ./agc_driver_rcp_hardware_tests(theagc_driver_rcp_hardware_exactentry). Head662dc031c; it applies cleanly onmaina6dcea927.agc_driver_rcp_hardware_exactmain's recompiler + the PR's test onlyWith the recompiler reverted to
main(SpirvAlu*,SpirvModuleEmitter.cpp, the twoSpirvEmitter*headers and the newSpirvAluEmitterReciprocal.cppremoved) and the PR's test kept, it exits non-zero on both devices, each at a different input and in the opposite ULP direction:The NVIDIA line is the same input and values reported in the PR body. lavapipe's native reciprocal diverges on a different mantissa and rounds the other way. With the full PR both devices return the exact RDNA 2 reciprocal for every measured pair and pass. The default
agc_driver_rcp_hardwareentry (switch unset) still skips with exit 77.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.