feat(recompiler): read the scalar aperture sources as values #5005
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5005"
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-13T07:51:28Z.
What
Fixes #3803. Since #1940, a shader that reads
src_shared_base,src_shared_limit,src_private_baseorsrc_private_limit(scalar source codes 235-238) as a value was refused withthe scalar aperture source ... is not modelled. These four sources now return the 64-bit apertures that the flat routing from #1190 already uses. A flat pointer built from them goes to LDS or scratch, and comparing against the limits gives the hardware's ordering.src_shared_base0x80000000_000000000x00000000src_shared_limit0x80000000_ffffffff0xffffffffsrc_private_base0x70000000_000000000x00000000src_private_limit0x70000000_ffffffff0xffffffffs_mov_b64, a 64-bit VALU source such asv_cmp_*_u64, or a lane mask in wave64) returns the whole value. A 32-bit read returns the low dword, as on gfx1030 and gfx1035. Titles take the high dword from ans_mov_b64, the same way LLVM does.SharedApertureHighandPrivateApertureHighmoved fromSpirvMemoryInstructions.cpptoRdnaInstructionDecoder.hpp.RdnaApertureSourceValuebuilds the four values from them, so the routing (SplitAperture) and the reads cannot diverge. The routing itself is unchanged.readRawU32returns the low dword.readU32Pairreturns low and high, which coversreadU64,readF64Bitsand every 64-bit scalar or VALU source.readMaskreads the 64-bit value as a lane mask. Before, a wave64 lane mask would have used the low dword for every lane.readScalarCode235-238 goes through the same values.docs/dev/debt/shader.md):Sources:
SHARED_BASE,SHARED_LIMIT,PRIVATE_BASEandPRIVATE_LIMIT, "Memory Aperture definition. Values are affected by system addressing mode: 32 or 64 bit".SH_MEM_BASES: bits [15:0] are the private base and [31:16] the shared base, so each base is a 16-bit field.064297491a6e):SIRegisterInfo.tdL245-L269: aperture registers are 64 bit, and their low 32 bits are always zero for a base and -1 for a limit.getBaseSegmentApertureinAMDGPULegalizerInfo.cppL2492-L2505 andSIISelLowering.cppL9453-L9462: LLVM copiesSRC_SHARED_BASE/SRC_PRIVATE_BASEas 64 bits and keeps the high half, because a 32-bit read "only returns zeroes".AMDGPUUsage.rstL1187-L1196: in 64-bit mode the apertures are 2^32 bytes and 2^32-aligned.24a19b953e2a):kfd_flat_memory.cL285-L306:MAKE_*_APP_LIMIT(base)is(base & 0xFFFFFFFF00000000) | 0xFFFFFFFF, and on gfx9+ the bases are set by the top 16 address bits.kfd_device_queue_manager_v10.cL51-L57: eachSH_MEM_BASESfield isbase >> 48. So with a 16-bit field of 0x8000, the high dword is 0x80000000.0ad3997b) does not constrain this. ACO never emits these operands, and it does not use FLAT loads or stores on GFX10 (src/amd/compiler/README-ISA.md). A search ofsrc/amdfinds no use of the aperture sources.Not measured on a console: the PS5's two high dwords. They are the values #1190 inferred from GTA V's traversal addresses (shared 0x8000 and private 0x7000 in the high 16 bits), and this PR reads exactly those values so that reads and routing agree. The wave is assumed to use 64-bit addressing (PTR32 clear). The debt entry records both.
Tested
Windows Server 2025, NVIDIA GeForce RTX 3060 (driver 591.86), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. The full run was on
mainc2565f014. After rebasing ontoa24da9029, the aperture,agc_driver_flat_apertures_*andagc_driver_flat_storetests were run again, and all 17 pass.agc_driver_flat_aperture_sources(tests/execution/FlatApertureSources.cpp). One compute dispatch per wave size (wave32, and wave64 where the device can run it). Every lane checks:s_mov_b32ands_mov_b64(low and high) result of each of the four sources;flat_store_dwordthrough a pointer whose high dword comes fromsrc_shared_base, read back withds_read_b32andflat_load_dword;src_private_base, read back withscratch_load_dwordandflat_load_dword;v_cmp_le_u64/v_cmp_ge_u64compares of those pointers against the bases and limits, including the limit itself and the first address past it;v_cndmask_b32with each source as the lane mask.aperture_sources. It asserted the refusal and now asserts the translated constants fors_mov_b32ands_mov_b64of each source.agc_driver_flat_aperture_sourcesfails withShaderRecompiler::Recompile: TranslationContext::readRawU32: the scalar aperture source src_shared_base is not modelled.aperture_sourcesaborts with the same message.SplitApertureto compare withSharedApertureHigh + 1makes the new test fail withBDA access failed: address=0x8000000000000000. The test therefore pins that the value read and the routing match.agc_driver_stencil_ref_exportand thevideo_out_flip_*tests). This includesagc_driver_flat_apertures_0-13and every other flat, global, BDA, LDS, scratch, scalar and recompiler test. The one failure islog_macros. It links onlylibc, and it fails the same way in another worktree build on this machine without this change.tools/check_conventions.py --base upstream/main: all checks passed.tools/check_test_registration.py: none new.src_shared_base;src_shared_basein local runs;src_shared_baseandsrc_private_basein local runs.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 fdfawef324 on 2026-10-13T09:56:15Z.
I ran a title with this change. The build was my integration branch,
mainplus open PRs, with this PR cherry-picked.Marvel's Wolverine (PPSA03671) logged
the scalar aperture source src_shared_base is not modelledand the same forsrc_private_basewithout this PR. With it, neither refusal appears. The title gets further and now stops on an unrelatedvkAllocateMemoryfailure (VK_ERROR_OUT_OF_DEVICE_MEMORY) on a 12 GB GPU.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T00:24:37Z.
Windows test of #5005: Windows 10 (19045), MinGW-w64 GCC 15.2, Release,
ninja -j 4, ctest called directly, GPU selected by the execution tests: NVIDIA GeForce RTX 4080 SUPER (Selected GPUlog line). Tree:mainfeddf7f4c+ merge of PR head823cdc0c4c06b60ba1118ac3c4a457992a482282(local merged2d34b987).16 ctest targets, 3 runs each, exit code 0 in all 48 runs:
agc_driver_flat_aperture_sources,agc_driver_flat_apertures_0to_13(14 targets) andaperture_sources. Logs:rtx5005_*_N.log.Not tested: that the new tests fail without the change (no baseline run), the AMD GPU (present, not selected), other ctest targets, Linux, a title run (PPSA26344).
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T00:29:20Z.
Thanks for the independent run. This adds Windows 10 / RTX 4080 SUPER evidence on
feddf7f4c: 16 targets, three runs each, 48/48 passed. I am keeping your stated limits alongside the result: no baseline failure check, AMD, Linux or title-run coverage in this report.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T01:50:05Z.
Correction to my Windows test above: I wrote that the GPU was shown by a
Selected GPUlog line, but that line was not in the ctest logs of those runs (ctest without-Vdoes not print the output of passing tests). Re-run withctest -Vonmain1633843382ecb1434ac76ac0c4d4655d88bb241f+ this PR's current headc2931c18fad759a2af20733c56a3b12930baaba7(the head has moved since my first run on823cdc0c4): the log showsSelected GPU name=NVIDIA GeForce RTX 4080 SUPER, andagc_driver_flat_aperture_sourcesexits with code 0 (1 run). The 16 targets of my first comment were not re-run.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-14T02:44:21Z.
Hey everyone, I ran another Windows check of this PR, including the before-and-after controls. The final run passed all 40 selected tests on an RTX 4070 SUPER.
Tested PR head
c2931c18fad759a2af20733c56a3b12930baaba7merged into main52d134c0282920d58a9ec07da51db08350e3d6dd. That is the pinned tree for these results; newer main commits were not tested.Windows 11 build 26300, NVIDIA driver 617.42, WinLibs GCC 15.2 r7, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON. The verbose logs confirmSelected GPU name=NVIDIA GeForce RTX 4070 SUPER ... subgroup=32. Vulkan was required. CTest setANYPS5_NO_SHADER_CACHE=1, and the new aperture GPU test also setsrequest.useCache=false.aperture_sources,agc_driver_flat_aperture_sources, all 14agc_driver_flat_apertures_*partitions (126 checked rows), and the related FLAT/LDS and shader tests.src_shared_base is not modelled.SplitAperturetoSharedApertureHigh + 1u. The CPU test passed, while the GPU test failed at BDA address0x8000000000000000with an unwritten0xdeadbeefresult.One environment wrinkle: the initial sandbox run was 39/40 because
agc_shader_disk_cachecould not write its initial cache entry. After restoration, that test failed again in the sandbox and passed on desktop with the same executable hash and no intervening rebuild. I have not identified the exact failing Windows file operation. The disk-cache test enables its own isolated cache.The new GPU test ran guest wave32 and wave64 on host subgroup32. These results check the emulator's aperture values and routing together; they do not measure the PS5 high words or PTR32 state. I did not run a game, Linux, other GPUs, or the whole CTest suite.
Thanks for the work on this. AI-assisted with Codex; the logs, controls, restored source and binary hashes were independently checked in a second review.