feat(shader): track MODE rounding changes through the control flow graph #5180
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5180"
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 13hourstilliland on 2026-10-13T14:03:14Z.
What
Addresses #981 for immediate rounding writes. The recompiler threw on any
s_round_modeors_setreg_imm32_b32that changed the MODE rounding fields from the shader's initialFLOAT_MODE. vkQuake (PPSA99010) stops there on Windows,mainc13dc7e6b(iDiesIrae-Req on #1578 and #981, 7 of 9 runs on an RTX 4070, RT shadow path):ACO emits this shape: it sets a rounding mode around the instructions that need it and restores it afterwards (
aco_insert_fp_mode.cpp,set_mode:s_round_modeon GFX10+,s_setreg_imm32_b32before).RoundingMode.cppcomputes the rounding fields (MODE bits 0-3) at the entry of every block. It walks the control flow graph from the initialFLOAT_MODE, applies immediate writes, and joins the paths. Bits that differ between paths, or that are written from an SGPR (s_setreg_b32), become unknown.FLOAT_MODErounding (v_cvt_f32_i32/u32,v_ldexp_f32, the f16 conversions,v_ldexp_f16with f16 denormals kept, and the mix/interp/packed f16 instructions that check their own mode) follow the current value.s_getreg_b32of the rounding bits returns the tracked value.FLOAT_MODEmetadata still throws on any rounding change.docs/dev/debt/shader.mdis updated.Tested
Linux (GCC), lavapipe, on current
maine152ba8f6:agc_shader_mode_register_testscover:s_getreg_b32;s_round_mode0-15 from every initial rounding;s_round_mode(follows the mode);agc_driver_f16_to_f32_unpack, which needs a feature lavapipe lacks).tools/check_conventions.py --base origin/mainpasses.Not tested on the title. Under lavapipe here, vkQuake stops earlier than this shader: SDL cannot open Vulkan on the offscreen driver, and the title's error path then faults in its own libunwind. So I can't show that it gets past pc 316.
s_round_mode 8sets f16/f64 rounding toward -inf. If the RT shader runs an f16/f64 instruction outside the modelled set in that mode, it will now throw at that instruction, with its pc, instead of at thes_round_mode. A run on a GPU would settle it.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)Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-13T15:47:38Z.
@iDiesIrae-Req could you run vkQuake (PPSA99010) with this branch on your RTX 4070 setup, with RT shadows on (the default, no
r_rtshadows 0)? Your runs onc13dc7e6bare the only evidence for thes_round_mode 8 at pc 316stop, and I can't reach that shader here.What I'd like to know is what happens after that point on this branch:
s_round_mode.Either line settles whether this PR unblocks the title.
Why I couldn't check it myself: my box has no GPU. On lavapipe (Mesa 25.0.7) under Xvfb, on
maine152ba8f6plus this branch, vkQuake gets throughPlaying shareware version.and its Vulkan init. Then its own driver reportsradv/ps5: the GPU has not reached submission 2 (at 1) in 10 sandQUAKE ERROR: vkWaitForFences failed with code -4, and it exits before any RT shader runs. AnyPS5 reports no failure there (checked with #5177 applied), so it looks like software rendering missing the title's 10 s fence wait rather than a driver error. That is a guess I can't confirm on this machine.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by iDiesIrae-Req on 2026-10-13T16:11:38Z.
@semirkabir Ran it. Setup: Windows 11, RTX 4070 Laptop (driver 32.0.16.1714), WinLibs GCC 15.2.0 r7 Release, vkQuake (PPSA99010) with the Quake 1.06 shareware
id1/pak0.pak, default settings (RT shadows on, noautoexec.cfg). Each build used a fresh relink with empty shader caches, then 4 runs of 60 s. The stop lines are fromrun.logand the title'sapp0/trace.txt.maine152ba8f6(control)Playing demo from demo1.dem:compute shader 0x20bf82000: ... s_round_mode 8 at pc 316 changes the initial MODE rounding fields: runtime MODE changes are not implementedcompute shader 0x20bf82000: shader 0x20bf82000 stage 0: ShaderRecompiler::Recompile: s_round_mode at pc 316 changes the rounding fields of a shader without a declared FLOAT_MODE: not implementedSo on this title the PR moves the stop but doesn't unblock it, because the shader reaches the recompiler with no
FLOAT_MODE. The title's RADV port writes PM4 itself, so its compute shaders are never registered (Compute shader 0x20bf82000 was not registered; preparing its artifact at dispatch).RegisteredFloatModeonly readsCOMPUTE_PGM_RSRC1from a registered state, which is why it returnsnullopthere, andDriver::dispatchpasses that on (Dispatch.cpp:99). The liveCOMPUTE_PGM_RSRC1(0x212) is inqueue.shaderat that point;Dispatch.cpp:150already mixes it into the dispatch key.As a local experiment only (not proposing it as is), I fell back to the live register when the shader isn't registered, decoded the same way
RegisteredFloatModedecodes type 0:With that on top of this PR, 4/4 runs no longer throw.
0x20bf82000is recompiled and dispatched, with no f16/f64 instruction named, so nothing else in it needed modelling under the changed mode. The title then stalls on the RT submission:vkDeviceWaitIdle -> -4andradv/ps5: the GPU has not reached submission 18 (at 17) in 10 s, stuck on the loading screen at 12 presented frames. That is the same stall I saw onc13dc7e6bin runs that never reached the shader compile. So with a float mode for unregistered compute shaders, this PR gets vkQuake past thes_round_modestop, and the next blocker is the GPU work of the RT shadow pass itself.Happy to run another build here if useful.
AI-assisted: yes (Claude Code); all runs were on my machine.
Imported from boykopovar/AnyPS5. Originally posted by iDiesIrae-Req on 2026-10-13T17:10:52Z.
@semirkabir Follow-up from the same RTX 4070 setup, now on
main61b8742b6. These runs also cover #5177.main+ #5177: 3 of 3 runs abort ons_round_mode 8 at pc 316. The throw comes through[videoout] presentation failed: ...on the presentation thread, not a queue worker, so #5177 adds no line there.main+ #5177 + #5214 + this PR + theCOMPUTE_PGM_RSRC1fallback from my last comment: no throw. 3 of 3 runs stall atradv/ps5: the GPU has not reached submission 18 (at 17) in 10 swith 12 presented frames, and #5177 prints no[gpu] driver failure.The stall isn't a hidden failure. One thread runs at 100% inside NVIDIA's shader compiler (
nvgpucomp64.dll) underAgcDriver::VulkanDevice::dispatch, and after 180 s it is still compiling, with the title still at 12 frames. The last shader prepared before it is0x20bf82000. So for vkQuake's RT path, the next blocker afters_round_modeis pipeline creation for that recompiled shader taking minutes on the host driver, longer than the title's 10 s fence wait. The stack is in the comment on #5214.AI-assisted: yes (Claude Code); all runs were on my machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:05:32Z.
On PPSA99010 this only moves the stop (iDiesIrae-Req's runs above):
0x20bf82000is never registered, soRegisteredFloatModereturns nullopt and it now throws... a shader without a declared FLOAT_MODE. Please take the float mode from the liveCOMPUTE_PGM_RSRC1for unregistered dispatches, here or in a PR this one depends on, so the title gets past pc 316.Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-14T05:14:45Z.
Added in c48628c3f: a dispatch whose shader was never registered now takes its FLOAT_MODE from the live COMPUTE_PGM_RSRC1. Registered shaders still read their registered state. Rebased on
75690a117.testDispatchFloatModein agc_driver_tests covers live, missing, and registered RSRC1. Reverting the change makes it fail with "an unregistered compute shader does not take its float mode from the live COMPUTE_PGM_RSRC1". 112 shader/float/f16/rounding/conversion tests: 110 pass, 2 skipped (f16, lavapipe), Linux GCC.This is the fallback @iDiesIrae-Req ran on PPSA99010: there's no throw at pc 316 anymore. The title then stalls in NVIDIA's shader compiler at submission 18. That's separate from this PR, and I can't reach it here because this box has no GPU.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:34:42Z.
Checked the MODE rounding tracking against gfx1035 (s_round_mode, s_setreg_imm32_b32 fields, s_getreg read-back), the agc_shader_mode_register and agc_driver tests (they fail to build without the change), and the RSRC1 fallback requested above; confirmed on PPSA99010 by @iDiesIrae-Req (no throw at pc 316). Merging once the full Build is green.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:22:16Z.
Rebased onto current
main: the only conflict was thedocs/dev/debt/shader.mdline next to the new waterfall entry, resolved by keeping both. No code changes. Re-ran the scoped build and ctest (agc_shader_mode_register,agc_driverpass). Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:26:37Z.
Rebased onto current
main: the only conflict was thedocs/dev/debt/shader.mdline. The waterfall entry from my previous rebase is gone because #5089 was reverted onmain, so only the MODE register line remains. No code changes. Re-ran the scoped build and ctest (agc_shader_mode_register,agc_driverpass;agc_driver_tessellationsegfaults as before). Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T13:44:44Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/Translation/include/Translation/TranslationContext.hppL19-20core/shader/recompiler/Translation/src/InstructionTranslator.cppL526docs/dev/debt/shader.mdL47-48