Translate ATOMG.CAS (global compare-and-swap): 6 compute programs that did not translate #597
No reviewers
Labels
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
No milestone
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!597
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/global-atomic-cas"
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?
Six of OoT's compute programs did not translate on
main(a598b9f):nvdisasm reads it as
ATOMG.E.CAS.STRONG.GPU PT, R0, [R0], R8, R9. The same goes for 64978274654e224c, f4867235b77e1107, 3b018f504c4715a1, 9d3e6486df0904bf and 99b6a2a493b3ba10.Change. A new IR operation carried through every layer, modeled on
GlobalAtomicExchange32:lower_to_maxwell.h: 0x3a9 lowers to Maxwell'sATOM.E.CAS Rd, [Ra + offset], Rb, Rb+1(U32). The game already keeps the comparator and the value as an even pair (R8/R9, R38/R39, R30/R31). Any other pair is first copied to R250/R251. A 64-bit CAS, an odd address register and other modes still fail.ATOM_caswas a not-implemented stub. It now reads its address asATOMdoes and emitsGlobalAtomicCompareExchange32.GlobalAtomicCompareExchange32 (address, comparator, value)andStorageAtomicCompareExchange32 (binding, offset, comparator, value), both with side effects.META_TABLEandNUM_ARGSgrow from 539 to 541.global_memory_to_storage_buffer_pass.cpp: maps the global operation to the storage one (ReplaceAtomicpasses the extra operand) and counts it as a write where pointers are followed, like the other 32-bit atomics.OpAtomicCompareExchangeon the storage buffer, plus a fallback function written like the other 32-bit atomics' fallbacks (search the buffers, then the page table where stores follow it).Tested on an RTX 4070 Ti (NVIDIA 595.99.02), Ubuntu 26.04, Linux build:
RX_VK_PREPARE_AGAIN=1:prepared 31985 shader programs (... 7 failed)drops to1 failed. The one left isGlobalAtomicAddF32with no SPIR-V fallback (program 499dbfd0721d2858), which is a separate change.nx2/lower_test.pyover the six dumped programs: 6 of 6 lower.RX_VK_DUMP_SPVfor that run: the six programs and the other 3812 dumped all passspirv-val --target-env vulkan1.3 --scalar-block-layout. The fallback'sOpAtomicCompareExchangepasses the value, then the comparator, in SPIR-V's order.tests/test_lower_atomg_cas.py(added to source-regressions): covers lowering of the game's three operand layouts, a copied pair, and two refused forms, and checks that the frontend, IR, pass and back-end pieces exist and the opcode tables matchopcodes.inc. It fails onmainand passes with g++ and clang++.I didn't find which effect those six compute programs drive, so the in-game check above shows nothing regressed, not a visible fix.
Assisted-by: Claude Opus 5.5