Repository navigation
feat(agc): run mesh-path draws through a compute pass on devices without mesh shaders - #9356
billythemenace2 wants to merge 3 commits into
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Re-run on this PR's head, since the Tested section lists my earlier runs as the prototype's. 6861beb against its base 1698d1e, Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
With the PR, all three configurations pass:
No test reports The failures shared with the base are AI-assisted: yes |
|
@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 Rebased onto AI-assisted (Claude Code). |
6861beb to
950a12b
Compare
adriadam10
left a comment
There was a problem hiding this comment.
Read the whole diff. The design is sound and the third-party runs are useful evidence. Three things to address, plus a rebase:
- Silent drop of indirect draws with more than 4 instances.
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. - Unbounded output buffer.
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.- Conflict with
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.
…out mesh shaders A mesh-path draw (the NGG primitive shader path) needed VK_EXT_mesh_shader. On a device without it, or for a draw whose targets have more layers than the device's maxMeshOutputLayers, the mesh program is now compiled as a GLCompute shader (SpirvTarget::meshAsCompute) that writes the draw's primitives and vertex records to a device buffer behind a VkDrawIndirectCommand header. A generated readback vertex shader (BuildMeshReadbackVertexShader) reads the records back for a triangle or line list drawn with vkCmdDrawIndirect, carrying position, parameters, clip and cull distances and the provoking vertex's layer. - The compute pass has its own pipeline layout with a compute push range; the draw's independent-sets layout lost the device on RDNA1. - The pass pins the program's subgroup size where the device allows it and refuses compute subgroups narrower than the wave, except the 32-lane subgroups that run a wave-64 program in paired lanes. - MeshDrawRunsAsCompute decides per draw: always without mesh shaders, and on a device with them when MeshDrawLayers exceeds maxMeshOutputLayers. - APS5_NO_MESH_SHADER=1 leaves VK_EXT_mesh_shader off. - Serialization version 43 stores meshAsCompute; the shader disk cache format is 45 for the record layout field. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…nd it From review of the mesh compute fallback: - An indirect mesh draw run as compute sized its output buffer for four instances, and a record with more drew nothing. Its record is now read on the CPU (IndirectDrawPath::MeshCompute, which waits for the producer like the other CPU-read paths), and the buffer is sized from the groups and instances it resolves to. Mesh.cpp draws an indirect record with six instances. - The output buffer is bounded: a draw that needs more than 256 MiB (MeshComputeOutputLimitBytes) or maxStorageBufferRange throws. - docs/dev/ARCHITECTURE.md describes the compute pass and the readback vertex stage. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
main gained mesh-path point output with register and exported point sizes. The compute fallback's vertex record carries no point size and its readback draws triangle or line lists, so a mesh program with point output run as compute now throws instead of failing to emit; agc_driver_mesh runs its point cases on the native mesh stage only, and the debt file lists it. Rebased onto main: serialization version 45 after main's point and fused arithmetic fields, shader disk cache format 46. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
950a12b to
f49a25a
Compare
|
@adriadam10 thank you for the full read. All four points are addressed, rebased onto
One addition from the rebase, On the RX 5700 XT, these pass: AI-assisted (Claude Code). |
adriadam10
left a comment
There was a problem hiding this comment.
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 / maxStorageBufferRange bound with a throw, the ARCHITECTURE.md section). Two things left:
- Conflicts with
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. - Conventions fails: the new debt line links
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.
|
Hi @billythemenace2 — first, thank you (and @tezzgod74, @root-over, @Alexius0815 and everyone who ran hardware) for getting this design to approved-and-proven. adriadam10 called it sound and the HW evidence across RDNA2, 680M, RX 9060 XT, MoltenVK and Pascal is exactly what a fallback this deep needs. Since the branch has been sitting on the rebase for a while (24 conflicting files, and the queue moves ~300 PRs/day), I would like to resuscitate it rather than watch it rot: I will cherry-pick your three commits onto current main, resolve the conflicts, re-verify, and open a fresh PR with full attribution (your commits kept, Co-authored-by where I touch them up, and a pointer back here so you can close this one when the new one lands). If you would rather finish the rebase yourself, say the word and I will stand down immediately — no toe-stepping intended. And if any of the conflict resolutions needs your judgement (oneandonlydean flagged a few spots), I will come back here with the exact hunks before deciding. |
|
@SuarezPM go ahead, you are ready now and I had only planned to start tomorrow, so I will stand down on this one to avoid two people resolving the same 24 files. One thing that may help: the Intel HD 520 run above (head |
|
Superseding resuscitation is up: #17611 carries this design forward (commits c0faaaf, fe9ac93, ecf0a2b cherry-picked with your authorship, @billythemenace2) reconciled onto current main with fallback hardening, tests and validation evidence. Thanks to @Adria for the sound-design review and to @sherySJ for the version-collision warning (re-verified: serial 57 / format 61 still free). @sherySJ, once #17611 is up for testing, your Intel HD 520 run (agc_driver_mesh, layered_volume, graphics) would be very welcome. |
…aders Supersedes boykopovar#9356 by billythemenace2; commits c0faaaf, fe9ac93 and ecf0a2b cherry-picked with authorship preserved, reconciled onto current main (serialization 57, disk-cache format 61) with fallback hardening and tests.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Head f49a25ae9f036a1d27e6418faeac7c812be5773e, base main. 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:
python3 repo_read.py search "meshArguments" core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
python3 repo_read.py search "specializations" core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
python3 repo_read.py search "MeshArgumentAddressDword" core/shader
python3 repo_read.py search "computeWave32" core/libs/prx/libSceAgcDriver
python3 repo_read.py search "ControlBarrier" core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
python3 repo_read.py cat core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp 1762 1782
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp 446 490
python3 repo_read.py cat core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp 170 212
python3 repo_read.py cat core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvInputOutput.cpp 204 222
Results
| Check | Result | Note |
|---|---|---|
| Build | not run | No build in this review |
| Tests named in the description | not run | Author-reported runs only |
| Description claims against code | passed | Switch, serialization and disk-cache versions, debt entry and docs match |
| Changed hunks in the diff | passed | Every hunk read; callers checked only where noted |
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
- Nothing was built or run. The author's runs (RX 5700 XT, RX 9060 XT, RDNA2 iGPU, RX 6650 XT, Vega iGPU, Apple M4, Radeon 680M, Intel Gen9) are reported in the description and were not reproduced.
- Files read: the diff hunks of all 36 files in the reviewed list. I did not open the full text of any changed file in the review folder. Callers were read only for the functions named in the findings and for the mesh argument, pipeline stage and barrier paths.
tests/Graphics.cppandtests/ShaderMemory.cppare too large for the review folder. I read only their diff hunks.- The message a barycentric mesh pixel shader gets on the fallback was not traced. The description says it keeps its existing message.
- That
variantIdis non-zero for programs loaded from the disk cache (MeshComputeStagesrequires it) was not traced. - Whether
LocalInvocationIndexis always declared when the mesh program is emitted as compute was not traced.DefineInputsdeclares it only for some lane and wave cases. - GPU behaviour was not checked: the barriers, the push-constant ranges with compute stage flags, the 256 MiB output limit, and RADV's
maxMeshOutputLayersof 8, which the description states.
To get this to a good state
Nothing is required. The two non-blocking points above are optional.
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