feat(agc): run mesh-path draws through a compute pass on devices without mesh shaders #9356
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9356"
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 billythemenace2 on 2026-10-21T19:17:53Z.
Requested by billy
What
A mesh-path draw (the NGG primitive-shader path) needed
VK_EXT_mesh_shader. Devices without it stop atdevice does not support mesh shaders: RDNA1, RDNA2 iGPUs on AMD's Windows driver, Intel Gen9, and Apple through MoltenVK. This runs such a draw through a compute pass instead, as designed in #6528.GLCompute(SpirvTarget::meshAsCompute). It writes the draw's primitive indices and vertex records to a device buffer behind a 16-byteVkDrawIndirectCommandheader. The buffer address travels in the mesh argument dwords.BuildMeshReadbackVertexShader) reads the records back for a triangle or line list drawn withvkCmdDrawIndirect. It carries position, parameters, clip and cull distances, and the layer from the provoking vertex.MeshRecordLayoutdescribes the record (clip and cull counts, layer, provoking vertex, primitive size) and is stored with the compiled program.MeshDrawRunsAsComputedecides per draw. Without mesh shaders the fallback is always used. On a device with them, it's used whenMeshDrawLayers(the bound targets' largest layer, slice or depth-slice count) exceedsmaxMeshOutputLayers, which is 8 on RADV. The draw stage then requests the mesh program withmeshAsComputeset, and a program compiled for the mesh stage that reaches the compute pass is refused.APS5_NO_MESH_SHADER=1leavesVK_EXT_mesh_shaderoff, so every mesh-path draw takes the fallback.IndirectDrawPath::MeshCompute). A draw that needs more thanmin(256 MiB, maxStorageBufferRange)throws.docs/dev/ARCHITECTURE.mddescribes the pass.meshAsCompute. The shader disk cache format is 46, for the record layout field.Not covered here, as follow-ups on top: emulated barycentrics behind the fallback. @root-over's geometry-stage route (
eff3479e9) and @Alexius0815's tessellation route for MoltenVK cover it. Until then, a mesh-path pixel shader that reads barycentrics on a device withoutVK_KHR_fragment_shader_barycentricstill stops with its existing message.Tested
mainf57e4ef72:agc_driver_graphics(with a unit test for the per-draw choice and the subgroup refusal),agc_driver_meshthrough the fallback,agc_driver_layered_volume_draw/_submit/_vertex/_vertex_no_gpl,agc_driver_prepared_graphics(and the three prebuild variants),agc_shader_memory, theagc_shader_disk_cachetests andrequest_serializerpass. The tests that need the native mesh stage skip.6861beb61), Windows: RDNA2 iGPU (fallback only) and RX 9060 XT (RDNA4), natively and withAPS5_NO_MESH_SHADER=1. 891 tests (agc_*andrequest_serializer), with the same failures as the base in each configuration.5e9032eae,168eaf3e9and08346eb8f):mesh=0, fallback only. RX 9060 XT (RDNA4), native and withAPS5_NO_MESH_SHADER=1. 718agc_*tests, with the same failures as the base.mesh=0: 15 of 20 homebrew catalog titles run for 60 s that stopped within 9 s onmain.LayeredVolumeDrawpasses only through the fallback.agc_driver_meshwith the paired-lane case allowed.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 tezzgod74 on 2026-10-22T05:41:27Z.
Re-run on this PR's head, since the Tested section lists my earlier runs as the prototype's. 6861beb61 against its base
1698d1ea6, Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,-DANYPS5_ENABLE_SPIRV_TOOLS=ON, allagc_*tests plusrequest_serializer(891):1698d1ea61002:164e, 32.0.21045.5002,mesh=0),agc_driver_mesh1002:7590, 32.0.32015.2008), all sixagc_driver_mesh*APS5_NO_MESH_SHADER=1,agc_driver_meshWith the PR, all three configurations pass:
agc_driver_graphicsagc_driver_layered_volume_draw,_submit,_vertexand_vertex_no_gplagc_driver_prepared_graphicsagc_shader_memoryagc_shader_disk_cache*testsrequest_serializerNo test reports
module version exceeds requested SPIR-V targeton the iGPU's SPIR-V 1.3 target. The other fiveagc_driver_mesh_*tests skip whenever the fallback runs, on the iGPU and withAPS5_NO_MESH_SHADER=1.The failures shared with the base are
agc_compute_pipeline_capture_runand the threeagc_driver_sample_order*tests on both devices, plus the four f64 and division tests from #7451 on the RX 9060 XT.ImageArrayWindowPastLayerLimit.cppdoesn't compile with MinGW on the base (alignas(65536), the case #9150 checks for), so that test isn't built on either side.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-22T14:08:18Z.
@tezzgod74 thank you for re-running on the PR head itself: the same results on the RDNA2 iGPU and the RX 9060 XT, natively and with
APS5_NO_MESH_SHADER=1, and no SPIR-V target warnings. I'll cite this run in the description.Rebased onto
main8b3e39832, now at950a12b6b.mainsplitDrawintoprepareDrawandrecordPreparedDraw, so the stage swap fromMeshComputeStagesnow sits at the top ofDraw, before both. On the RX 5700 XT,agc_driver_graphics,agc_driver_mesh, the four layered volume tests,agc_driver_prepared_graphicsand its prebuild variants,agc_shader_memory, theagc_shader_disk_cachetests andrequest_serializerpass.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-22T18:26:38Z.
Review: CHANGES_REQUESTED
Read the whole diff. The design is sound and the third-party runs are useful evidence. Three things to address, plus a rebase:
MeshArgumentRulesFor(..., asCompute=true)setsmaxTotal = indexGroups * MeshComputeIndirectInstances(Draw.cpp:856,MeshComputeIndirectInstances = 4).ResolveMeshArgumentsthen returns zero groups whengroups > maxTotal / instances(Draw.cpp:888), so an indirect mesh draw with 5+ instances draws nothing and nothing is thrown. Onmainthe same clamp is a real device limit; here it is a number chosen to size the output buffer. Either size the buffer from the instance count that is actually read, or throw when the draw exceeds what the buffer holds. Add a test with 5+ instances.recordMeshComputeallocatesMeshOutputHeaderBytes + groups * groupBytesper draw (Draw.cpp:1864), withgroups = meshGroups * instanceCountand no upper bound (direct case) andgroupBytesincludingrecordBytes * maxVertices. A draw with a large instance or index count allocates that in device-local memory and holds it until the batch retires. State the bound (orRequirea maximum and throw above it) and give peak RSS/VRAM before/after on a big mesh workload, as in the memory rules (docs/rules/memory.md).docs/dev/ARCHITECTURE.md: a new compute pass and generated readback vertex stage in the draw path changes the pipeline; add the section under the draw diagram.maininShaderValidation.cpp(stage count / barycentric patches line,:668):mainnow accepts triangle strip there ("require a triangle list or strip"). Keep that condition and message together with yourmeshComputestage count.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T20:57:54Z.
Review: CHANGES_REQUESTED
The three points from the last review are addressed (indirect record read on the CPU with the output sized from groups × instances and a 6-instance test, the 256 MiB /
maxStorageBufferRangebound with a throw, the ARCHITECTURE.md section). Two things left:mainin 8 files:Draw.cpp,tests/ShaderMemory.cpp,CacheKey.hpp,ControlFlow/src/RequestSerializer.cpp,Recompiler.hpp,SpirvEmitter.hpp,SpirvEmitter.cpp,tests/RequestSerializerTests.cpp. The one inDraw.cppneeds a decision:mainnow also binds the pixel-function LDS buffer right after the descriptor sets (BindPixelFunctionLds) and passesPixelFunctionLdsSubgroup(shaders) != 0utoStartDrawPass; both must survive inside yourbindResourceslambda and themeshComputecondition. Please rebase and re-run the touched tests, including serialization/disk-cache versions after whatevermainbumped.core/shader/recompiler/Recompiler.cpp, so the check wants it indocs/dev/debt/shader.md. Either move it there or link alibSceAgcDriverfile like the neighbouring lines.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T18:37:37Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(1e658521a0): headf49a25ae9fconflicts incore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/LayeredVolumeDraw.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/tests/RequestSerializerTests.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T05:21:42Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Head
f49a25ae9f036a1d27e6418faeac7c812be5773e, basemain. No merged-preview check. No build, no tests, no GPU run. The checks were a read of the diff and of the head code through the repository reader:Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:885—indexGroupsis computed in theasComputebranch ofMeshArgumentRulesForand never used. It is dead code, and an unused-variable warning fails the build if warnings are errors. Removing the line fixes it.core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp:469—stages.eraseshifts the entries ofstages, but the stencil-replay check after it (lines 474 to 478) still indexesstageswith theshadersindex. For a mesh-as-compute pipeline, that check now looks at the fragment stage instead of the readback vertex stage. Nothing fails today, because the readback vertex stage never gets a subgroup size, but the check no longer covers the stage it names. Running the check before the erase, or finding the stage by itsstagevalue, fixes it.Not verified
tests/Graphics.cppandtests/ShaderMemory.cppare too large for the review folder. I read only their diff hunks.variantIdis non-zero for programs loaded from the disk cache (MeshComputeStagesrequires it) was not traced.LocalInvocationIndexis always declared when the mesh program is emitted as compute was not traced.DefineInputsdeclares it only for some lane and wave cases.maxMeshOutputLayersof 8, which the description states.To get this to a good state
Nothing is required. The two non-blocking points above are optional.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.