graphics: draw per-vertex pixel shaders through the VS-store path on MoltenVK #1441
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1441
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1441/head"
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?
@wuboo on GitHub · 2026-10-12 06:54 UTC · original
wuboo:pr/pv-vsstore-wiring→main· +3088 −18 · 22 files · 12 commits · closed without mergingDepends on #1440 (the emitter and
perVertexVsStore.h); the first three commits of this branch are #1440, review only the last two.The path only matters where the game gets as far as drawing on MoltenVK, i.e. together with the PRs that
let the renderer start on Apple GPUs without the optional device features (for example #1314, and #633 /
#1083 for the rest of the start-up); on its own it changes nothing on devices that run
PerVertexKHR.What this is
#1440 can emit a vertex/pixel shader pair that passes the per-vertex attributes through a storage
buffer. This PR makes the renderer use it, on devices that cannot run
PerVertexKHR.PvVsStoreEnabledFor(fragmentShaderBarycentric, moltenvk, KYTY_PV_VSSTORE):by default when the device does not run
fragmentShaderBarycentricand the driver is MoltenVK(
VkPhysicalDeviceDriverProperties::driverID).KYTY_PV_VSSTORE=0turns it off,=1forces it on(A/B runs, the GPU harness on another driver). On macOS the extension is never requested today, so
the first term is
falsethere; if #959 lands, the call invulkanWindow.cpppasses itsfragment_shader_barycentric_enabledinstead (a one-line change).Parameterinputs the VS-store variant is emitted next to the normal one (same
push_data_start_dword, so thedescriptor layout is unchanged), validated with
spirv-val, and remembered by shader id. A variantthat fails validation is logged and its draws keep the existing path. This doubles the emission cost
of vertex shaders when the path is on.
RenderExecutor::TryPvVsStoreDraw, decided before any resource of the draw isprepared):
DecidePvVsStore(#1440, CPU-tested) takes the interface verdict of the pair, the drawplan from
ScanPvVsStoreVertexRange(min/max ofindex + vertex_offset), whether the index buffercan be bound as a storage descriptor, whether its last word fits in the buffer the cache hands out,
and whether a cap region is free. If everything holds the draw is recorded with the VS-store pair's
pipeline (distinct pipeline-cache identity), set 1 = {cap slab, index buffer} and the 8-dword push
block after the native push data.
it was last used in has finished on the GPU.
Touchis called when the draw is recorded, becauseresource preparation can flush the scheduler between
Placeand the draw.ring, location 31, interface, index tail), plus used draws, instanced draws, records and scanned
indices. They are logged on the first candidate draw and every 8192nd.
The index buffer copy of 8-bit indices (already widened to 16 bit on the host) is padded to a whole
word, because the pixel shader reads the buffer as
uint32.Fallback
A draw that cannot take the path is drawn exactly as before this PR. There is no replacement path
(no capture/replay prototype in main), so on a device without
PerVertexKHRsuch a draw still hasthe problems it has today; the counters say how many there are. In particular triangle strips and
fans, non-indexed draws and primitive restart are not covered.
Tests
per_vertex_vsstore): capability switch and its parser, the vertex-range scan (both indexsizes, unaligned source, negative and positive
vertex_offset, dropped corners, 32-bit overflow),nine more mutants (see #1440 for how mutants are made); each fails its test.
TryPvVsStoreDraw,BindPvVsStore, slab buffers, pipeline layout withthe second set) is not covered by CPU tests: it needs a Vulkan device. The GPU harness from #1440
(7/7 cases and
--stress) covers the shader pair and the descriptor/push layout, not the renderer.(a bench branch, not this branch): on the level scene the path gave +21 % to +34 % frames per second
over the same stack with
KYTY_PV_VSSTORE=0(where those draws went through a local capture/replay prototype path thatmaindoes not have), with identical frames at the same guest flips. This rebased branch has not been run in a game byitself, so treat the numbers as indicative of the mechanism, not as a measurement of this exact tree.
ctestas onmain(GPU-dependent tests skip without a Vulkan loader).Limits and honest caveats
buffer (tile-based GPUs behind MoltenVK); that is why the default is MoltenVK only. See #1440.
stride * 16bytes per vertex per instance per draw, kept until the GPUfinishes the command buffer; draws that do not fit a 64 MiB slab stay on the existing path. The
index scan reads every index of every candidate draw once, on the CPU (no memo in this PR); it was
not measured.
MoltenVK pipelines, touches the same pipeline-layout code). Textual conflicts with several others
in
renderDraw.cpp/vulkanWindow.cpp.@coderabbitai[bot] on GitHub · 2026-10-12 07:03 UTC · original · edited 2026-10-17 11:32 UTC
📝 Walkthrough
The change adds a per-vertex VS-store path for eligible indexed triangle draws. It adds planning and allocation helpers, emits vertex and pixel SPIR-V variants that store and load per-vertex data, and integrates the variants into renderer pipeline and draw execution. Draws that do not qualify continue through the existing path. CPU, shader-emission, GPU, and mutation tests cover the helpers and rendering path.
Suggested reviewers:
theantipopauPriority: ➖ Normal
Change: Feature
Merge Risk: 🟠 High · up to
29655Eligible VS-store draws can fail on the intended MoltenVK path or render incorrect per-vertex inputs; some supported devices can also halt when creating the pipeline. These issues affect the feature’s core rendering path and should be fixed before merge.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 126 functions across 18 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -0,0 +179,4 @@// Distinct pipeline-cache identity from the PerVertexKHR variants of the same programs.value.graphics.vertex[0].id |= 1ull << 61;value.graphics.pixel.id |= 1ull << 61;value.graphics.pv_store_layout = PvVsStoreSetLayout(graphics);@coderabbitai[bot] on GitHub · 2026-10-12 07:03 UTC · original · edited 2026-10-12 10:16 UTC
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Destroy the VS-store shader modules and the set layout.
GetPvVsStoreProgramscreates two shader modules withCompileSPVfor each accepted pair. It stores them in the statics_pairs.PvVsStoreSetLayoutcreates the statics_set_layout. No code destroys any of these objects:ProgramCache::~ProgramCachedestroys only the native permutation modules.PipelineCache::~PipelineCachedestroys only the per-pipeline layouts.At
vkDestroyDevice, the validation layer reports the remaining objects as validation errors.VulkanDebugMessengerCallbackcallsEXITon these errors, so a run with validation enabled aborts at shutdown. The static maps also keep handles from the old device after the device is gone.Add a teardown function, for example
ShutdownPvVsStore(vk::Device). It must destroy everys_pairsmodule ands_set_layout, then clears_pairsands_shaders. Call it from the pipeline cache destructor or beforedevice.destroy.✅ Confirmed as addressed by @wuboo
@coderabbitai[bot] on GitHub · 2026-10-12 07:03 UTC · original · edited 2026-10-12 10:18 UTC
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cppline 157 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 33444
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42151
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16555
🌐 Web query:
official Vulkan specification PrimitiveId fragment shader Geometry capability tessellation capability VK_KHR_fragment_shader_barycentric feature💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12178
Use only capabilities enabled by the device.
The VS-store fragment shader declares
CapabilityGeometryforPrimitiveId, but the device enablestessellationShader, notgeometryShader. Vulkan permitsPrimitiveIdwith theTessellationcapability. Use that capability instead.Suggested fix for the PrimitiveId capability
The VS-store path also still requires fragment barycentrics.
DefineInputskeeps per-vertexParameterentries instate.inputs, andDefineModuleuses those entries to requireCapabilityFragmentBarycentricKHRandSPV_KHR_fragment_shader_barycentric. Non-flat per-vertex interpolation then readsBaryCoordSmoothorBaryCoordNoPerspective.On Apple,
VulkanCreateDevicedoes not chain or enablefragmentShaderBarycentric. Therefore, either enableVK_KHR_fragment_shader_barycentricand its feature when MoltenVK reports support, or remove this dependency before using VS-store on devices that do not report it. Otherwise, the emitted shader requires an unavailable feature.📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-12 07:03 UTC · original · reviewed
Actionable comments posted: 2
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
e3aa901a-43e9-49f1-927d-d65e10686088📥 Commits
Reviewing files that changed from the base of the PR and between
dad900c61dand d305947c013b60e410a52a05b54feb3b405b3aa0.📒 Files selected for processing (22)
CMakeLists.txtsrc/graphics/host_gpu/renderer/perVertexVsStore.hsrc/graphics/host_gpu/renderer/perVertexVsStoreRuntime.cppsrc/graphics/host_gpu/renderer/perVertexVsStoreRuntime.hsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.hsrc/graphics/host_gpu/renderer/pipeline/shaders.cppsrc/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpptests/PerVertexVsStoreGpu.cmaketests/PerVertexVsStoreGpuTests.cpptests/PerVertexVsStoreMutants.cmaketests/PerVertexVsStoreTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@ -0,0 +179,4 @@// Distinct pipeline-cache identity from the PerVertexKHR variants of the same programs.value.graphics.vertex[0].id |= 1ull << 61;value.graphics.pixel.id |= 1ull << 61;value.graphics.pv_store_layout = PvVsStoreSetLayout(graphics);@wuboo on GitHub · 2026-10-12 10:09 UTC · original
Valid, fixed in 82f328b7. New
ShutdownPvVsStore(vk::Device)destroys the two modules of every accepted pair and the set layout, clearss_pairs/s_shaders;WindowContext::~WindowContextcalls it afterwaitIdleand after the render context (pipelines, pipeline layouts) is gone, right before the device is destroyed. Builds and the full ctest is unchanged; no CPU test is possible because the objects are Vulkan handles, and I did not run it under the validation layer.@wuboo on GitHub · 2026-10-12 10:09 UTC · original
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cppline 157 (outdated):Two parts.n1. Capability: valid. The device enables
tessellationShaderbut notgeometryShader, so the VS-store PS now declaresTessellationforPrimitiveId. Fixed in 98aac3b9 (the emitter belongs to #1440, so it is in that branch and reaches this PR by the rebase). Test:shader_cfgchecksCapability Tessellationand the absence ofCapability Geometry; mutantshader_cfg_pv_vsstore_mutant_capability_geometryfails it.n2. Barycentric feature: the observation is right (the PS still readsBaryCoordKHR, and on macOSfragmentShaderBarycentricis never requested; the VS-store path is meant for exactly that device), but I left it unchanged here. It is not specific to this path: every guest PS with custom interpolation (VINTRP) already getsFragmentBarycentricKHR/BaryCoordKHRfrom the emitter, which does not condition it on the platform (see the existingshader_cfgchecks for custom VINTRP). Requesting the feature on Apple would change device creation for the whole renderer and needs its own GPU/validation run, so it is better as a separate change. I have not run the validation layer on this path.@coderabbitai[bot] on GitHub · 2026-10-12 10:15 UTC · original · edited 2026-10-12 15:21 UTC
On
tests/PerVertexVsStoreGpuTests.cppline 382 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Enable
tessellationShaderinstead ofgeometryShaderon the harness device.The emitter now asks for
spv::CapabilityTessellationwhen a pixel shader readsPrimitiveId(seeDefinePvStoreinspirvEmitterPvStore.cpp). Thecapability_geometrymutant exists to keep the pixel shader from asking for Geometry. Even so, this harness still enablesgeometryShaderand never enablestessellationShader. The Vulkan spec does not allow a shader module to declare the Tessellation capability whiletessellationShaderis off. MoltenVK can accept this without an error, but validation layers will report it. It also means the harness no longer uses the same device features as the renderer, even though the file header says it uses the renderer's setup. The comment on line 382 is out of date for the same reason.🐛 Proposed fix
📝 Committable suggestion
✅ Confirmed as addressed by @wuboo
@coderabbitai[bot] on GitHub · 2026-10-12 10:15 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
71bf51c1-62fe-4ff4-b286-04ca9d5ab0ab📥 Commits
Reviewing files that changed from the base of the PR and between d305947c013b60e410a52a05b54feb3b405b3aa0 and 82f328b78974c5957965191217944b6170d24813.
📒 Files selected for processing (10)
CMakeLists.txtsrc/graphics/host_gpu/renderer/perVertexVsStore.hsrc/graphics/host_gpu/renderer/perVertexVsStoreRuntime.cppsrc/graphics/host_gpu/renderer/perVertexVsStoreRuntime.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpptests/PerVertexVsStoreGpuTests.cpptests/PerVertexVsStoreMutants.cmaketests/PerVertexVsStoreTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@ -0,0 +179,4 @@// Distinct pipeline-cache identity from the PerVertexKHR variants of the same programs.value.graphics.vertex[0].id |= 1ull << 61;value.graphics.pixel.id |= 1ull << 61;value.graphics.pv_store_layout = PvVsStoreSetLayout(graphics);@coderabbitai[bot] on GitHub · 2026-10-12 10:16 UTC · original
@wubooThanks for fixing this. The teardown you describe addresses the module and descriptor-set-layout leaks and clears the cached handles. The shutdown order keeps the device alive during cleanup.Validation-layer shutdown testing remains unverified.
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-12 10:18 UTC · original
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cppline 157 (outdated):@wubooThanks for the clarification.The reported
Tessellationchange addresses the capability concern. The regression check and capability mutant cover that change.I agree that the barycentric dependency is shared with existing custom VINTRP shaders, rather than introduced by VS-store. A separate renderer-wide change with GPU and validation-layer testing is appropriate. The dependency remains unresolved, so this combined finding stays open.
Would you like me to open a follow-up issue for the macOS barycentric-feature dependency?
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
You are interacting with an AI system.
@theantipopau on GitHub · 2026-10-12 11:09 UTC · original · approved these changes
Reviewed only the two wiring commits (
8a389ff8,82f328b7) per the PR note; #1440's emitter/harness commits are out of scope here.Wiring correctness checks against main:
TryPvVsStoreDrawruns before bindings are prepared, correctly rejects mesh stages and non-per-vertex pairs, and everyDecidePvVsStorefallback keeps the existing path and just counts the reason (CountPvVsStoreDraw) — no draws regress on other drivers.Touch(region)happens at record time beforeBindPvVsStore, matching the stated reason (resource prep can flush the scheduler betweenPlaceand the draw); the slab's tick-based reuse rules live in the runtime.PrepareIndexBuffer(needed since the PS readsuint32), the guest path re-ObtainBuffers to computetail_fitsfrom the buffer the cache hands out, and unaligned guest addresses remain on PerVertexKHR — conservative and correct.use_pv_store ? pv_store.programs->graphics : state.programsintoGetGraphicsPipelinedrives the 2-set layout (PvVsStorePushRangeBytescomputes the larger push range only when the variant layout exists), so per-variant pipelines get distinct identity.82f328b7's shutdown destroys modules/set layout under the same lock before device teardown and skips non-Usepairs that borrowedgraphics— matches object-lifetime requirements.One observation, non-blocking:
ResolvePvVsStoreEnabledis called inVulkanCreateDeviceevery device creation but only reads its env/driverIDinputs — fine, just noting the one-line follow-up when #959 lands is deliberate.CI green on all platforms; the path is default-off outside MoltenVK-without-barycentric, so risk on other drivers is nil. Murphy's-honest approval: renderer wiring itself is Vulkan-device-dependent and doesn't have CPU coverage, but the tested seams (scan/decide/push-block) are CPU-consumed in the harness.
@wuboo on GitHub · 2026-10-12 13:54 UTC · original
On
tests/PerVertexVsStoreGpuTests.cppline 382 (outdated):Agreed and fixed. The harness now checks that the device supports
tessellationShaderand enables it (features.tessellationShader = VK_TRUE) instead ofgeometryShader, matching the renderer and theTessellationcapability the emitter declares forPrimitiveId; the stale comment is replaced. The change lives in #1440 (pr/d1-emitter, 8977bb43), and #1441 is rebased on top of it. It is a GPU-only harness, so there is no CPU test or mutant for this line; the harness compiles, it still has to be run on a GPU machine.@coderabbitai[bot] on GitHub · 2026-10-12 13:54 UTC · original
On
tests/PerVertexVsStoreGpuTests.cppline 382 (outdated):@wubooThanks for confirming the fix. The support check andfeatures.tessellationShader = VK_TRUEaddress this finding. GPU validation remains pending, as you noted.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@wuboo on GitHub · 2026-10-12 15:21 UTC · original
On
tests/PerVertexVsStoreGpuTests.cppline 382 (outdated):Follow-up: with 8977bb43 the harness enables
tessellationShaderand has been run on MoltenVK (Apple M3 Max): all 7 cases pass,--stresspasses, and both harness mutants fail as expected.@coderabbitai[bot] on GitHub · 2026-10-12 15:21 UTC · original
On
tests/PerVertexVsStoreGpuTests.cppline 382 (outdated):@wubooThanks for confirming the GPU results. Your reported MoltenVK run covers the previously pending GPU check: all 7 cases and--stresspass, and both harness mutants fail as expected.✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-16 18:06 UTC · original · edited 2026-10-16 18:42 UTC
On
src/graphics/host_gpu/renderer/renderDraw.cppline 1171 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14291
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 22297
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 43352
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42238
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32373
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9995
Validate the prepared index binding.
TryPvVsStoreDrawvalidates oneObtainBufferresult beforePrepareGraphicsBindings, butPrepareIndexBufferobtains the same range again afterward. For small CPU-modified ranges,ObtainBufferusesStreamBuffer::Map; eachCommitadvances the stream offset, so the two bindings can differ.BindPvVsStorethen uses the second binding. If its descriptor is invalid,EXIT_IFaborts the draw. If only the tail does not fit, the descriptor is clamped and the draw still does not fall back.Move the VS-store decision after
PrepareIndexBufferand validate that prepared binding.Suggested fix
✅ Addressed in commit
29655ac@coderabbitai[bot] on GitHub · 2026-10-16 18:06 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
63c0a4ae-fe87-4d74-afac-8ce9e18f2355📥 Commits
Reviewing files that changed from the base of the PR and between 516a49f94c0d5d1a14a0f1d4531128e4fb3f0d4d and
990c175491.📒 Files selected for processing: 15
CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.hsrc/graphics/host_gpu/renderer/pipeline/shaders.cppsrc/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpptests/PerVertexVsStoreGpuTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-16 18:51 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
7f007654-4c63-40cc-9a68-53a095ac4375📥 Commits
Reviewing files that changed from the base of the PR and between
990c175491and29655ac0ed.📒 Files selected for processing: 5
src/graphics/host_gpu/renderer/perVertexVsStore.hsrc/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderDraw.cpptests/PerVertexVsStoreMutants.cmaketests/PerVertexVsStoreTests.cpp🚧 Files skipped from review as they are similar to previous changes: 3
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
Pull request closed