Skip to content

feat(agc): emulate barycentrics of mesh draws run as compute in the readback vertex shader - #1959

Draft
Thimo188 wants to merge 16 commits into
mainfrom
upstream-pr/28142
Draft

Thimo188 wants to merge 16 commits into
mainfrom
upstream-pr/28142

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28142, originally opened by yuriy1337.

Source commit: b496c74cc5726bf928a75f33d5c00864f0743cbe. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Depends on boykopovar#17611. Until it merges, this diff also shows boykopovar#17611's commits; only the top commit is this PR.

Problem. On a GPU with neither VK_EXT_mesh_shader nor fragmentShaderBarycentric, boykopovar#17611 runs mesh draws as compute, but a pixel shader that reads barycentrics still stops the draw:

Fix.

  • A draw run as compute compiles its pixel shader as on the vertex path.
  • The readback vertex shader writes the emulated barycentric inputs (BuildMeshBarycentricReadbackVertexShader). Each corner writes its one-hot weights, the 1/w-scaled weights for offset reads, all three corners' per-vertex values and the provoking corner's flat values.
  • The readback cache is also keyed by the pixel shader's SPIR-V hash when it emulates barycentrics.
  • Provoking-vertex validation applies the barycentric-patch rule: line output, and a flat per-vertex input with the last provoking vertex, throw.

This is an alternative to boykopovar#9387 (the tessellation route) for draws run as compute. The native mesh path and main's native barycentric pairing are untouched. Debt: edits to boykopovar#17611's fragment agc-mesh-fallback-compute.md.

Overlap with other PRs

tools/pr_overlap.py measures from main, so it reports boykopovar#17611's footprint too, and it fails closed. Counting only this PR's commit:

Tested

Linux, A/B against boykopovar#17611's head 59203ed861 on the same machine, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.

Full ctest (6844 tests), RTX 3070: native and APS5_NO_MESH_SHADER=1 have 0 failures on both heads. APS5_FORCE_MESH_COMPUTE=1 fails the same 2 tests on both heads (agc_driver_tessellation_geometry, agc_driver_viewport_index).

Focused set, 26 tests, under the validation layer:

Device boykopovar#17611 this PR
RTX 3070, native mesh 26 passed 26 passed
RTX 3070, APS5_NO_MESH_SHADER=1 26 passed, mesh_barycentric_emulation skipped 26 passed, it runs
RTX 3070, APS5_FORCE_MESH_COMPUTE=1 26 passed, mesh_barycentric_emulation skipped 26 passed, it runs
Intel UHD TGL GT1 (no mesh, no barycentrics) 26 passed, mesh_barycentric_emulation skipped 26 passed, it runs
llvmpipe 26 passed, mesh tests skip 26 passed, mesh tests skip

The PR adds no VUID- lines: there are 0 on each device except Intel, which logs the same 48 maxCombinedClipAndCullDistances-00710 on both heads.

The new tests catch the bug. Applied to boykopovar#17611 without the fix, all three fail in every compute-path config: Intel and no-mesh with the SPIR-V 1.4 error from the GTX 1050 Ti logs, forced compute with graphics interfaces disagree at location 0.

Not tested: titles, AMD. Windows: build only.

Test details
  • Build: Ubuntu 26.04.1, kernel 7.0.0-31, GCC, Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON.
  • Focused set: ctest -V -R 'agc_driver_mesh|barycentric|layered_volume|mesh_output|request_serializer|agc_driver_graphics' with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, using the layer from LunarG SDK 1.4.363.0. Every log shows Insert instance layer "VK_LAYER_KHRONOS_validation", and none shows was not found but was requested.
  • New coverage on the compute path:
    • agc_driver_mesh_barycentric_emulation used to skip there. It now checks perspective, linear and iterated (offset) I/J pixels and raw per-vertex values against the reference: 932 pixels each on RTX 3070 (no mesh, forced) and Intel.
    • agc_driver_mesh adds non-indexed and indexed draws, front and back culling compared with the ordinary readback draw, and a flat input with the first and last provoking vertex.
    • agc_driver_layered_volume_draw adds a layered mesh draw run as compute.
  • Titles: the failures above come from reports in feat(agc): emulate mesh pipeline draws with a compute pass when VK_EXT_mesh_shader is unavailable boykopovar/AnyPS5#17611's thread; I did not rerun those titles.
  • Windows 10, WinLibs GCC 15.2.0 r7 (the release CI uses): every file this PR changes compiles and links. 36 executables fail at the post-link objcopy --rename-section step ("Invalid argument"), the same 36 on feat(agc): emulate mesh pipeline draws with a compute pass when VK_EXT_mesh_shader is unavailable boykopovar/AnyPS5#17611's head. Tests can't run on this machine: its CPU (i7-3770K) lacks AVX2/BMI, and the host-CPU check stops them on both heads.

Checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kn5E2jBvwSg6P3XXp7MUJt

billythemenace2 and others added 16 commits November 8, 2026 18:21
…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>
…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.
The draw-time MeshDrawRunsAsCompute decision now matches the compile-time one (mesh && (forced || !meshShader)): on mesh-capable devices oversized-layer draws stay on the native layer-window replay instead of throwing in recordMeshCompute, whose pipeline has no compute stage there. Removes the now-unused MeshDrawLayers helper, scopes the BDA capability allowance to the compute/readback stages, documents the readback cache, and rewords the ARCHITECTURE section. Tests updated plus a literal 34-slice/8-layer regression.
Resolve the ShaderDiskCache.hpp FormatVersion conflict as 78: main is at 68 and 69-77 are set by other open pull requests.
Re-derive the mesh-as-compute fallback on the current main: async
MaterializeInBackground draw-stage path, Settled indirect path,
deviceAtomicWorkgroupMemoryBarriers/meshInlineFunctions/
spannedShuffleThroughMemory targets, version 63 serializer with
58-61 blacklisted.

Unify MeshDrawRunsAsCompute on mesh && (forced || !meshShader) at
every call site with an explicit force flag; the layer condition
stays out per review. Cap the CPU multi-record indirect mesh path
with a loud Require plus a debt entry. The follow-up commit renumbers
the serializer to 64 and the disk-cache format to 97.
…to 97

The rebase onto current main collides with its serializer 63 and
disk-cache format 96: write version 64 with meshAsCompute after the
spanned-subgroup flag, keep the emulated-barycentrics flag trailing,
reject the blacklisted 58-61 range, and bump the disk format for the
new mesh record layout in artifacts (304/568-byte static asserts).

Adapt the fallback to current main APIs (BindComputePipeline) and
bring the request-serializer, shader-memory and graphics tests to the
new versions, including the shared meshAsCompute activation decision
with an explicit force flag and a loud refusal for multi-record
indirect mesh draws run as compute.
Three conflicts, all from boykopovar#24898 reworking the mesh argument path:

- Recorder.hpp / Recorder.cpp: keep the 8-rule span (firstIgnored) and carry
  the compute-fallback flag on the same signature.
- Draw.cpp: keep the non-indexed MeshArgumentRulesFor(draw) overload and the
  multi-record Require; propagate asCompute explicitly from
  recordMeshArguments, and leave the 3-argument helpers mesh-only so the
  boykopovar#24898 tests keep their mesh limits under APS5_FORCE_MESH_COMPUTE.
A pull request records debt through a fragment, not by editing the debt files
(docs/dev/TechnicalDebt.md#fragments). Move the four entries into
docs/dev/debt/changes/agc-mesh-fallback-compute.md, restore both debt files to
main, and drop the stray leading space the direct edit left on the
DB_RENDER_CONTROL entry.

tools/debt_fold.py --check and tools/check_conventions.py pass.
boykopovar#25434 prebuilds graphics pipeline libraries on the first visit of a shader
set and hands the compiled mesh program straight to the Pipeline constructor.
On a device without VK_EXT_mesh_shader that created a
VK_SHADER_STAGE_MESH_BIT_EXT stage from the compute-layout program once the
constructor's mesh-shader Require was gone.

Return false from Pipeline::Prebuild when MeshDrawRunsAsCompute is set, and
require that no stage is still Mesh in the constructor when meshCompute is
set, so any other caller is caught too.

Verified on RTX 2060 SUPER, Linux x86_64, driver 620.73.04, with the
validation layer: 23 focused tests pass in default, APS5_FORCE_MESH_COMPUTE=1
and APS5_NO_MESH_SHADER=1, 0 VUID- lines, layer inserted in every run.
…every path

The guard exempted IndirectDrawPath::Gpu, so a mesh-path indirect draw that
still carried that path with more than one resolved record fell through to the
single-record resolve: recordMeshArguments copied front() into one argument
buffer and the fallback issued one dispatch and one indirect draw, dropping
every later record silently.

Reject a compute-path draw with more than one resolved record whatever the path
says, before anything is recorded. Per-record dispatch stays the follow-up
already listed in the debt entry.

Verified on RTX 2060 SUPER, Linux x86_64, driver 620.73.04, with the validation
layer: 23 focused tests pass in default, APS5_FORCE_MESH_COMPUTE=1 and
APS5_NO_MESH_SHADER=1, 0 VUID- lines, layer inserted in every run.
…eadback vertex shader

On a device without VK_EXT_mesh_shader and fragmentShaderBarycentric, a mesh-path draw whose pixel shader reads barycentrics runs through the compute fallback, but its pixel shader was still compiled for the mesh stage, which declares SPV_EXT_mesh_shader in a SPIR-V 1.3 module, and the fallback refused barycentric inputs. The pixel shader of a draw run as compute is now compiled as on the vertex path, and the readback vertex shader writes the emulated interface itself: each corner is its own vertex of the triangle list, so it writes the one-hot weights of its slot, the 1/w-scaled weights for offset barycentrics, the three corners' per-vertex values and the provoking corner's flat values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kn5E2jBvwSg6P3XXp7MUJt
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 100 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
PR 103 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
PR 311 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
docs/dev/debt/changes/agc-mesh-fallback-compute.md
PR 425 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
docs/dev/debt/changes/agc-mesh-fallback-compute.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants