feat(agc): run hardware oracle kernels through the recompiler on Vulkan #12348
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12348"
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 vingelvatten on 2026-10-28T10:30:14Z.
What
tools/hw-oraclemeasures RDNA instructions on a local AMD GPU, but nothing ran the same kernel through the shader recompiler, so a difference between the recompiler and the hardware could only be found by hand (#10771, #10772 and #10922 came from a private harness).agc_oracle_runner(core/libs/prx/libSceAgcDriver/tools/OracleRunner.cpp, built withcmake --build build --target agc_oracle_runner) takes the HSA code object the oracle assembles fromtemplate.s, reads theprobetext and theprobe.kdkernel descriptor (wave size, LDS,FLOAT_MODE,DX10_CLAMP,IEEE,FP16_OVFL, workgroup-id and thread-id enables), refuses every other kernel ABI (scratch, a kernarg size other than 16, user SGPRs other than the kernarg pointer), and dispatches one workgroup through the recompiler on the Vulkan device with the oracle binary's argument convention. The guest block holding the kernarg pair, the rows plus extra bytes and the 16-dword outputs is registered throughGuestAllocationsand passed as a memory region, which the recompiler needs to resolve the kernarg pointer at compile time.HW_ORACLE_RUNTIME=vulkaninhw_oracle.pyassembles exactly as thehipandhsaruntimes do and dispatches through the runner named byHW_ORACLE_VULKAN_RUNNER;--jsonreports carry aruntimefield. One body and one set of rows run on the hardware and on the recompiler, andcompare_results.pylists the differing words.agc_oracle_code_object(host only) parses a code object built in memory and checks every descriptor rejection names its field;agc_driver_oracle_runnerdispatches the pinned template text aroundv_add_f16 v10, v4, v5plus aglobal_load_dwordof each lane's extra dword over two waves and checks every lane against rows measured on a gfx1036;test_hw_oracle.pycovers the new runtime without a GPU.HW_ORACLE.mdgains a Recompiler comparison section; the runner's ABI limits are a debt entry inlibSceAgcDriver.md.First result from the harness, to be reported separately: scalar
v_add_f16,v_sub_f16,v_mul_f16andv_fma_f16return the canonical NaN on NVIDIA and the other operand's NaN on AMD's Vulkan driver where the hardware returns the first operand's NaN (sign-adjusted forv_sub_f16, quieted only with IEEE=1); packed f16,v_max_f16andv_add_f32match bit for bit.Tested
Windows 11 Pro 26300, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release,
BUILD_TESTING=ON. The branch is rebased ontomainab6f5d32ed(headcc920eae69), with the test registrations moved totests/cmake/bytools/agc_test_split.py resolve; the runs below name the base each was made on. On this head the five focused tests with the validation layer pass on both Windows GPUs with noVUID-line,test_hw_oracle.pyruns 68 tests OK (3 skipped) and the conventions check passes; lavapipe was last run on85bf4de89c.ctest -R "agc_oracle_code_object|agc_driver_oracle_runner": both pass on the RTX 4070 Ti SUPER and on the Radeon iGPU (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1).py -3 tools/hw-oracle/test_hw_oracle.py: 58 tests, OK (3 skipped, as onmain) at head85bf4de89c.--jsonon the hardware (hip) and throughvulkanon each GPU;compare_results.pyreportsCompared 64 rows x 2 registers: 0 differing wordsfor both.py -3 tools/check_conventions.py --base origin/main: passes.ctest -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=layer, on each GPU, for the compute tests closest to the runner's dispatch path (agc_driver_exec_host_lanes,agc_driver_bda_span_reads,agc_driver_bda_anchor_reads) onmain3a40945e62(the merge base at the time) and on the PR headda44162ea6, plusagc_driver_oracle_runnerandagc_oracle_code_objecton the head, and the five tests again on the rebased head85bf4de89c, and the runner itself through the CLI run above. Every log hasInsert instance layer "VK_LAYER_KHRONOS_validation"once per device creation, none haswas not found but was requested by env var VK_INSTANCE_LAYERS, and none has aVUID-line, onmainor on the head, on either GPU. The same comparison was first made againstmain0cd07dc4abbefore the rebase, with the same result.da44162ea6,BUILD_TESTING=ONwithANYPS5_AGC_EXECUTION_TESTS=OracleRunner;ExecHostLanes;BdaSpanReads;BdaAnchorReads:agc_oracle_runnerand thelibstarget build;ctest -Vfor the five tests above withANYPS5_GPU=llvmpipe,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layerpasses 5 of 5 (agc_driver_oracle_runnerin 10.3 s; it checks the f16 denormal row there, lavapipe keeps it), with the layer insert line per device creation, no missing-layer line and noVUID-line.test_hw_oracle.py: 57 tests, OK, 1 skipped (58 at head85bf4de89c). The same five tests and the CLI comparison were repeated on the rebased head85bf4de89cwith the same result. The CLI route withHW_ORACLE_RUNTIME=vulkan,HW_ORACLE_TARGET=gfx1036and clang+lld assembly on the test body with extra bytes:Compared 64 rows x 2 registers: 0 differing wordsagainst the gfx1036 hardware report.d24216ada0(third commit) replaces the runner'sstrtoulcount parsing withParseOracleCount, decimal digits only up to 4294967295, so a negative string can no longer wrap into a validthreadsorout_dwords;agc_oracle_code_objectcovers the wraparound values, signs, blanks, suffixes and overflow for both fields and passes; the built runner rejects-18446744073709551615and-18446744073709551600with exit 1.agc_driver_oracle_runneron a device that flushes f16 denormals: the AMD Vulkan driver here reports no f16 denormal preservation and still keeps the0x0001 + 0x0001row, so that row is checked on both GPUs; a device that flushes it to 0 reports the row as unchecked instead of failing (second commit), for the Linux lane's lavapipe.Overlap: #12084 changes the two template read and write lines next to this PR's
assemblechange; whichever lands second rebases.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-10-28T10:34:58Z.
Review: COMMENTED
I fetched this exact head and ran
python3 tools/hw-oracle/test_hw_oracle.pywith Python 3.11.2: 56 tests passed, 2 skipped. I also reviewed the parser/dispatch path and the reported two-GPU end-to-end comparisons. One integration follow-up before this can merge: GitHub currently reportsDIRTY;git merge-treeagainst currentmainshows the only conflict istools/hw-oracle/hw_oracle.py, where #12326 added explicit UTF-8 arguments to the template reads/writes in the same lines this PR updates for the Vulkan runtime. Please rebase/resolve while preserving both the UTF-8 behavior and the Vulkan paths, then refresh tests on that head. I have not approved while the branch is conflicted.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T11:22:02Z.
Review: COMMENTED
I rechecked the new exact head
da44162ea676998268403fc44083e97c105a0278. The updated report now includes the validation-layer comparison against current merge base3a40945e62and identifies the earlier0cd07dc4abcomparison as historical, resolving my freshness comment. I reranpython3 tools/hw-oracle/test_hw_oracle.pylocally on Python 3.11.2: 44 tests passed, 2 skipped;git diff --checkpassed. The refreshed hosted Windows and relinker jobs are still running/queued, so I am not approving until they complete.Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-29T11:07:25Z.
Review: COMMENTED
I rechecked the current head
da44162ea676998268403fc44083e97c105a0278and the refreshed hosted run. The earlier rebase/freshness points look resolved, and the overall Build run is green, but I don't think the hosted result closes the Linux side yet.Run
40679114663has thelinuxjob as skipped. The successful Ubuntu job is configured with-DANYPS5_RELINKER_ONLY=ON, so it does not build or exercise the new AGC oracle runner. That matters here because this PR adds an explicit non-Windows path (std::aligned_alloc, clang/lld assembly,HW_ORACLE_TARGET) and the author noted that the lavapipe path could not be tested locally on the Windows machine.Could you provide Linux evidence that at least builds the new runner and runs the relevant oracle tests there (ideally the lavapipe
agc_driver_oracle_runnerpath withANYPS5_REQUIRE_VULKAN=1), or otherwise narrow/document the platform support? I am withholding approval on that coverage gap rather than treating the aggregate green Build status as proof of the Linux path.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T06:33:02Z.
Review: COMMENTED
Re-checked — new head, pending checks
The new head resolves the prior debt-document conflict and adds a capability-aware f16 denormal check; focused Python tests pass, while hosted build and relinker jobs are still queued.
What I ran
85bf4de89cbcee5c52f8055a19b5350bc7939275; recorded base:47cdccde40bca36c1203ec498d9ff47f23bc6537.main:47cdccde40bca36c1203ec498d9ff47f23bc6537; merge preview tree:a7624c1d8e96638f661fdb28b7f2d555a32077e9(clean).tools/hw-oraclefrom the exact PR ref into a temporary directory and ran the Python suite there. Commands/checks:Results
a7624c1d8e96638f661fdb28b7f2d555a32077e9.tools/sanitizer_report.pyand its test, outside this PR's changed paths.Unedited check output
Sources
85bf4de89cbcee5c52f8055a19b5350bc7939275Not verified
I did not compile the C++ runner, run CTest, or run GPU tests locally. Hosted Windows and relinker jobs remain pending; the author's three-device results are reported, not independently reproduced.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T07:13:44Z.
Review: APPROVED
Reviewed — looks good
I reviewed exact head
85bf4de89cbcee5c52f8055a19b5350bc7939275; the earlier debt conflict is resolved, the current-base comparison found no intervening changes to this PR's touched paths, and I found no remaining blocker. The Python hardware-oracle suite passed locally on this exact head earlier today (58 passed, 2 skipped); hosted Windows, Ubuntu/Windows relinker, ASan, conventions, labels, report, and eligibility checks pass. The two macOS relinker jobs remain pending and Linux product CI is skipped; the author reports the focused Vulkan tests and oracle comparisons on the RTX 4070 Ti SUPER, Radeon iGPU, and lavapipe (report). I did not locally compile the C++ runner or independently reproduce the GPU tests.Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-30T10:09:21Z.
Review: APPROVED
Re-reviewed exact head 85bf4de89cbcee5c52f8055a19b5350bc7939275 after the conflict resolution and refreshed GPU evidence. The earlier Linux/lavapipe and NVIDIA attribution concerns are resolved, and the debt-doc conflict is gone. On this exact head I ran tools/hw-oracle/test_hw_oracle.py on Windows Python 3.12: 58 tests OK (4 platform skips); git diff --check is clean. Git merge-tree is clean against current main
a5939f10a8and also clean pairwise with Malek's live hw-oracle PRs #12812, #12816 and #12821, so this does not create a hidden integration conflict for those changes. Hosted Build is fully green on this head: Windows, Ubuntu/Windows relinker, both macOS relinker lanes, ASan and eligibility all pass; Linux product CI is skipped. I found no remaining blocking issue.Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-30T10:11:48Z.
Review: APPROVED
Re-reviewed exact head 85bf4de89cbcee5c52f8055a19b5350bc7939275 after the Linux/lavapipe and debt-doc follow-ups. I independently fetched that exact SHA (not the stale pre-rebase PR ref), verified a clean merge-tree against current main
a5939f10a8, clean git diff --check, passing conventions, and tools/hw-oracle/test_hw_oracle.py on Windows Python 3.12: 58 tests OK with 4 expected platform skips. Hosted Build and Progress report are green on this head. The author has also supplied focused validation-layer runs on RTX 4070 Ti SUPER, Radeon iGPU, and lavapipe/WSL, plus the base/head attribution checks that resolved the two NVIDIA signals I raised earlier. I found no remaining blocker in the hw-oracle/Vulkan integration.Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-30T18:03:54Z.
Review: CHANGES_REQUESTED
Blocking oracle-facing issue on exact head
85bf4de89cbcee5c52f8055a19b5350bc7939275:agc_oracle_runner'sParseCount()usesstrtoul()without rejecting a leading minus sign.On 64-bit libc, unsigned conversion can wrap specially chosen negative decimal strings into valid small values with no parse error. For example,
-18446744073709551615can become1, and-18446744073709551600can become16. That means malformed negativethreads/out_dwordsarguments can bypass the CLI validation and reachRunOracleKernel()instead of being rejected.Please reject a leading
-before the unsigned conversion (or use an equivalent strict unsigned parser) and add regression cases for both fields using those wraparound values, while keeping the existing valid boundaries unchanged. This is the same defect class just caught in the HSA runner, so keeping the Vulkan runner aligned matters for the shared oracle CLI contract.Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-31T00:43:44Z.
Review: APPROVED
Re-reviewed exact current head d24216ada0b90062fb8ff20891a4964f7e0ad8d0 after the Vulkan-runner count-parser fix. ParseOracleCount is now a strict decimal parser: every character must be 0-9, accumulation uses uint64_t, and values above UINT32_MAX are rejected before narrowing. That closes the negative-wraparound defect I requested changes for, along with signs, whitespace, suffixes and hex-like inputs. The host regression covers both hreads and out_dwords with the two wraparound negatives plus -1/-0/+1/empty/whitespace/suffix/overflow cases, while keeping 0/1/16/1024/007/4294967295 accepted. Exact-head merge-tree against current main
e49d43d625is clean and git diff --check passes. Hosted conventions, eligibility, portability, Windows, Ubuntu/Windows relinker, ASan and report are green; only the generic macOS relinker lanes are queued. The refreshed NVIDIA run on this head reports 2,395 passed, 0 new failures, and no new Vulkan validation IDs versus main. My previous parser blocker is resolved; no remaining blocking issue found.