feat(agc): run unregistered NGG vertex programs that need a workgroup on the mesh path #1825
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1825"
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 TheAggie on 2026-10-08T20:37:36Z.
What
RADV on the PS5 (mihawk-99/PS5_Mesa) enables NGG culling by default on GFX10 and GFX10.3 (
radv_physical_device.c,use_ngg_culling). Its vertex shaders are then ACO's NGG culling programs:s_barrier.v_mbcntand a prefix sum, and read the wave's total withv_readlane_b32of lane 63.s_sendmsgGS_ALLOC_REQ, prim export).AnyPS5 runs a PRIMGEN draw without GS on the vertex path, a Vulkan vertex shader with one guest lane per invocation. It has no workgroup memory or barrier, and on a 32-lane host it cannot read lanes 32-63. Every such draw failed with
v_readlane_b32 of lane 63 is outside the 32-lane host subgroup. ccleste (PPSA59322) only rendered withRADV_DEBUG=nonggc.The geometry path already provides what these programs need:
SpirvEmitter.cpp,laneCount).GS_ALLOC_REQand primitive exports.This PR sends such a draw there.
decodeDrawroutes a draw to the geometry path when all of these hold:VGT_SHADER_STAGES_ENhasPRIMGEN_ENwithoutGS_EN,PRIMGEN_PASSTHRU_ENorHS_EN.s_barrier.Passthrough programs and every program that works today stay on the vertex path. RADV's own blits are passthrough, as are ps5-opengl's vertex shaders.
ProgramUsesWorkgroupdecodes the program once per snapshot (DS instructions ors_barrier) and caches the answer on it.DecodeShaderStages(queue, vertexWorkgroup)builds the mesh configuration from the NGG registers for such a program:GE_MAX_OUTPUT_PER_SUBGROUP) instead of the GS output budget.ES_VGPR_COMP_CNT0); ccleste's load all.GS_EN, passthrough or tessellation throws.Registered programs keep today's routing. Routing them would also change registration-time preparation (
PrepareRegistered,ResolveGraphicsStagesAbi), so I left that for a follow-up.Tests:
agc_driver_graphics(NggVertexWorkgroupTests), using ccleste's culling-draw registers (VGT_SHADER_STAGES_EN0x00012010,GE_NGG_SUBGRP_CNTL0x10080,GE_MAX_OUTPUT_PER_SUBGROUP0x80,VGT_ESGS_RING_ITEMSIZE1):SPI_SHADER_PGM_RSRC1_GS/RSRC2_GS(0x222c0005,0x00400030) takes the mesh path.GS_EN, passthrough and tessellation are rejected.agc_driver(testProgramWorkgroupUse): an LDS write and ans_barrierneed a workgroup, a plain program does not, the result is cached, and the check starts at the program's entry.There is no GPU execution test of a culling program on the mesh path; ccleste exercises it, below.
Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.
CTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.RADV_DEBUG), on currentmainwith this PR, #1819 and my other pending changes on a local branch. Earlier, on an oldermain, it was also play-tested this way.Not tested on AMD, Intel or Linux.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-09T11:49:01Z.
Title evidence: a registered (AGC header) vertex program in Marvel's Wolverine (PPSA03671, v01.001.005) has the same shape, so the
front->header.empty()condition currently leaves it on the vertex path.Windows 11, MinGW, RTX 3070 (32-lane subgroups),
maind70b89989plus #1339. The title creates its swapchain, then stops at its first draw:The program (wave64, 828 dwords) is NGG culling code like the one you describe:
s_mov_b32 exec_lo, -1, lane id fromv_mbcnt_lo/hi(-1), thenv_cmpx_lt_u32of the lane id againsts3.v_cndmaskof each lane's bit with the samelane id < s3compare, then an OR scan with DPProw_shr1/2/4/8,v_permlanex16_b32, andv_readlane_b32of lanes 31 and 63, OR'd together.v_mbcntover that mask, writes through LDS (10 DS instructions, nos_barrier), and allocates its primitives withs_sendmsgGS_ALLOC_REQ (25 exports).Two details that may matter if registered programs take the mesh path too:
bound_ctrlset.MatchHalfWaveScan(951370324) only accepts it clear. For reductions whose identity is 0 (OR, IAdd, UMax) the result is the same either way, since the step then writesop(0, own)=ownat the lanes without a source. Locally, accepting it for those three lets all four steps and thev_permlanex16_b32match.EntryLaneWalkrejects the keys: their mask comes fromv_cmp_lt_u32(lane id, s3)rather than a ballot, and the vertex path setss3to64 | 64 << 8.I can test a revision of this PR on this title if that helps.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T05:58:04Z.
Review: CHANGES_REQUESTED
This PR carries the four commits of #1732, which is still open and has an unanswered design request from @oneandonlydean (decide up front which programs are deferred, as #1836 does, instead of compiling whatever isn't registered at the first draw). Whatever shape #1732 ends up with changes the routing here (
decodeDraw,ShaderRegistry,PrepareRegistered), so this can't land first.mainincore/libs/prx/libSceAgcDriver/tests/Submit.cpp.I haven't built or run it yet for that reason; I'll review the NGG-specific part on the rebased branch.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:15:40Z.
Additional platform validation on standalone PR head
70afd4995b968b175f1e0dddc5906c04200a4c48:Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja.
Release /
BUILD_TESTING=ON: built the selected test targets; 9 CTest cases, 0 failures, 0 CTest skips.Tests:
agc_driver,agc_driver_graphics,agc_driver_prepared_shaders,agc_driver_prepared_unregistered_graphics,agc_driver_prepared_shaders_indirect,agc_driver_prepared_shaders_uncached,agc_driver_prepared_shaders_debug,agc_driver_prepared_shaders_debug_failure,agc_driver_prepared_shaders_deferred.Reproduce after building the test targets:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver($|_graphics$|_prepared_unregistered_graphics|_prepared_shaders)".Vulkan: Mesa lavapipe 26.2.4 software Vulkan; no native Linux GPU/retail-title validation.
Internal limitation: write-watched guest-heap mirror subcases returned early because WSL userfaultfd async write protection is unavailable. The other graphics assertions ran; zero CTest skips does not include this internal early return.
Integration limitation: a local merge against main
948a526c2has source conflicts; these results validate the standalone PR head, not a resolved merge.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T16:36:34Z.
Native Windows platform run on NVIDIA and Intel, for the mesh side of this.
Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release. RTX 5060 Laptop GPU (32.0.16.1742) and an Arrow Lake iGPU (Core Ultra 9 275HX, 32.0.101.8991). All seven commits (ade03f85 to 62a87e4e) cherry-picked onto
main57f96fd2without conflicts. Mesh draws render nothing on Intel onmain(#2815), so I added that fix (377829ec) to be able to exercise the mesh path there; on NVIDIA it changes nothing. Both GPUs ran withAPS5_NO_PIPELINE_LTO=1to keep the #2777 race out of it.agc_driver_prepared_unregistered_graphics,agc_driver_graphicsandagc_driver_mesh: 3/3 on both GPUs.--parallel 6): 710/710 on the RTX 5060. On the iGPU the only failures are the five that also fail onmainand have their own fixes (f64_fma_subnormals,fp16_overflow,vop1_float_unary,vopc_compare(#2114, #2822) andlds_beyond_device_limit(#2805)).Possibly related: #2783 is the same
v_readlane_b32of lane 63 in a wave64 NGG culling vertex program, on NVIDIA in Taxi Chaos 2, but there the program is registered, which @tv7 notes above keeps it on the vertex path with this PR as it stands.AI-assisted (Claude Code); the numbers above are from runs on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-10T20:31:27Z.
Independent conditional startup validation of 62a87e4e
Validated the three NGG commits above #1732 at your pinned head
62a87e4e9a4df647708c97582fe77ea87de41663, with the local empty-registry raw-graphics policy required in the #1732 review. This is an unpublished diagnostic stack, not unmodified-main compatibility.Title: PPSA99902, Sonic Unleashed Recompiled 01.003.000. After the local SW_64KB_D_X color change described in #2970, the vertex path refused
ReadLanelane 63 for a wave64 program on the RTX 5080's subgroup32. Captured program: 308 words, 24 DS instructions, 4 s_barrier instructions, no AGC header; code SHA2569c26bcbae52a22f13c79c6ae7375052017088abc857a09f44fba7e9e7881dfa7.The program is now confirmed, not inferred just from the error text: temporary instrumentation on the main
43d2a7c4prerequisite stack captured the exact same code as stage Mesh, with mesh/workgroup context, wave64 and host subgroup32. The instrumentation was then removed byte-for-byte and full libraries rebuilt. With the disk shader cache disabled, five CPU preparation attempts of the original Vertex/subgroup32 request reproduce the lane63 guard; five of the captured Mesh/subgroup32 request prepare. Subgroup64 controls prepare for both requests. These are preparation controls, not measurements of console culling or rendered geometry. Private shader/request files were not uploaded.Behavioral tests: Windows 11 Enterprise 26200, RTX 5080, WinLibs r7 GCC 15.2.0, Release, BUILD_TESTING=ON. Full libraries built. On main
4a747c48, the proposal plus corrected raw policy passed 17 relevant groups five times; after the additional classification guard below,18 groups passed five times, no skips, maximum 4.18 s. The integrated color/NGG stack passed 22 groups five times. Conventions/test-registration checks passed; full suite and Linux were not tested.Policy integration finding: the proposal's new front-program classification calls ProgramSnapshot before the registered-only draw lookup. In a registered-workgroup fixture, that can classify forbidden raw code as Mesh and fail at a missing user-config 0x25b rather than the registered-shader refusal. This does not prove a mixed raw draw was accepted. Locally I gate classification on an empty registry, reject reserved address bits, and use ReadRawShader there. The new registered-workgroup case then gets the registered-shader refusal; removing the empty-registry gate makes it fail again. Sources restored byte-for-byte, full libraries rebuilt, all18 groups passed five repetitions. Local adapter commit
2a9d5f8e; no new PR.Controlled title runs: on the preserved main4a prerequisite profile, changing only libSceAgcDriver.prx removes the ReadLane stop in all five runs, then refuses
DISPATCH_DIRECT at DWORD 656: dispatch modifiers 0x2047 are not implemented(42.905, 43.397, 40.552, 41.649, 40.869s). Restored-driver controls reproduce ReadLane. The first earlier exploratory NGG attempt timed out and initially hit a library lock during restoration; it is retained separately and excluded from those five repetitions. Subsequent baseline restoration/hash checks passed.The next packet is covered by #2756, which is being independently validated. Similar #2783 concerns registered NGG work; this title uses unregistered workgroups, so I have not claimed its shader/reduction is identical. Default filtering still misses pathconf. No gameplay, presented-frame or console-semantics claim; original dump, 123 baseline library files and guest libc preserved/hash checked. No branch push or new PR. AI-assisted validation/local adapter: Codex.
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-11T00:32:49Z.
@adriadam10 #1732 now has the rule @oneandonlydean asked for: an unregistered graphics program is read raw only while the registry is empty, and
RegisterShaderthrows after raw draws. I've rebased this PR onto that head (39fdc48b), so its three commits now sit on top of it (head e5507ddf).The vertex-program check this PR adds, which decides whether an unregistered NGG vertex program needs a workgroup, goes through the same
ProgramSnapshot. So it follows the same rule: with any shader registered, an unregistered vertex program still throws.agc_driver_mesh,agc_driver_graphics, theagc_driver_prepared_*tests andagc_driver_prepared_unregistered_graphicspass on Windows 11 / RTX 5070 Ti.agc_driver_ngg_vertex_wave_infotimes out invkWaitForFenceshere, as it does onmain.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:27:33Z.
Review: APPROVED
Rebased onto current
mainand added one commit: a TechnicalDebt line (Unknown function info) for the assumptions of the mesh routing (one output primitive per input, vertex budget fromGE_MAX_OUTPUT_PER_SUBGROUP, GS/ES VGPR checks skipped), since they come from ACO output and not from hardware.Checked: libSceAgcDriver build and ctest (
agc_driver,agc_driver_graphics,agc_driver_prepared_graphics,agc_driver_prepared_unregistered_graphics) green; the new tests don't build/fail without the change. Platform runs by @Mouhand-Kaddo, @Silverash-i8 and @Amoenus cover Linux lavapipe, NVIDIA, Intel and a captured Sonic Unleashed program. Merging once CI is green.