shader: add a VS-store emitter for per-vertex pixel inputs (no renderer wiring) #1440
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!1440
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1440/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-emitter→main· +2309 −5 · 14 files · 7 commits · closed without mergingWhat this is
Pixel shaders that read raw vertex attributes (
V_INTERP_MOVof a parameter, or the barycentricVGPRs) are emitted with
PerVertexKHRinputs andVK_KHR_fragment_shader_barycentric. MoltenVK doesnot expose that extension (the macOS path never enables it), so those pixel shaders cannot run there.
This PR adds an alternative SPIR-V emission for such a pair of shaders, plus the pure helpers both
sides must agree on. It is not used by anything yet: the renderer wiring is the follow-up #1441.
Parameteroutput as auvec4(bits unchanged) tocap[record * stride + slot]in a storage buffer (set 1, binding 0).recordisbase + (instance - first_instance) * span + (vertex_index - first).PerVertexKHRinputs, the pixel shader reads the three corners of itsprimitive from the same buffer, using
gl_PrimitiveIDand the draw's index buffer (set 1,binding 1):
cap[record(instance, index[first_index + primitive * 3 + k] + vertex_offset)], k = 0..2.P0/P10/P20 are then the same values the
PerVertexKHRpath would give.not need to know its VS). Location 31 carries the instance index VS -> PS and is therefore reserved.
kPvVsStorePushDwords).perVertexVsStore.hholds the arithmetic (record numbering, draw plan, pass ring, slab bookkeeping,index-descriptor math, fallback classification). It has no Vulkan or global state, and the CPU tests
and the SPIR-V emitter share it.
EmitProgramgets an optionalPvStoreInfo*; withnullptr(all existing callers) the output isunchanged.
Tests
per_vertex_vsstore(CPU, plus the mutants built at configure time): planner, record model against a direct read of the vertex array, 16/32-bitindices,
vertex_offsetof both signs,first_instance, odd 16-bit ends, index-descriptor clamp,ring and slab reuse.
shader_cfggainsTestPvVsStoreEmission: both variants validate withspirv-val, the VS-store PSreads the same corners as the
PerVertexKHRPS, and the dynamic stride comes from push dword 7.tests/PerVertexVsStoreMutants.cmakegenerates, at configure time, a copy of
perVertexVsStore.h(or ofspirvEmitterPvStore.cpp) withone expression changed; each mutant's test must fail (
WILL_FAIL, or a grep for the failure messagewhere the check aborts). A mutant whose text no longer occurs exactly once breaks configuration, so
the list cannot go stale unnoticed. 18 header mutants + 2 test-seam mutants for the CPU test, 3 for
shader_cfg(corners 0/2 swapped; stride read from the wrong push dword; location 31 aborts theemission again).
per_vertex_vsstore_gpu_tests(opt-in, needs MoltenVK viaSDL_VULKAN_LIBRARY, notpart of ctest): the real emitter output is drawn with the renderer's set/push layout and compared bit
for bit with the CPU per-vertex model (7 cases: 16/32-bit indices,
vertex_offset> 0 / < 0,first_instance, 2 instances, an index buffer bound at an offset that is not a multiple ofminStorageBufferOffsetAlignment, 16-bit indices ending inside a word), and reads the cap bufferback to check what
gl_VertexIndex/gl_InstanceIndexcontain.--stressadds 2 cases ofValidation
mainatdad900c6; fullctestunchanged againstmain(the 19 tests that need a Vulkanloader skip without one), new tests and all mutants as above.
--stresscases on MoltenVK (Apple silicon).mainbehaves exactly as before; the in-game numbers arein the follow-up #1441.
Limits worth knowing (TBDR)
of the same render pass reads it. Vulkan does not promise that between the two stages without a
barrier, and a barrier inside a render pass cannot order them. On the tile-based Apple GPUs behind
MoltenVK the vertex work of a pass runs before its fragment work, which is what this relies on; the
VS-store cap buffer is
Coherentand the VS issues a memory barrier after its stores. It has beenchecked with the harness above on MoltenVK only and is not meant for immediate-mode GPUs.
index sizes other than 16/32 bit, shaders that use location 31, and a PS that reads a per-vertex
location the VS does not write. A stage that uses location 31 still emits (the location is recorded);
the interface check rejects the pair. #1441 counts each reason.
gl_BaryCoord*forsmooth interpolation of a per-vertex attribute); only the per-vertex corner values move to the buffer.
Removing that dependency is what #959 is about and is not attempted here.
stride * 16bytes per vertex per instance for the life of the render pass.the stages as assumed. That is what the harness is for.
@coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · edited 2026-10-16 18:01 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
9846703b-c8c3-47ff-9b0f-695280bca18e📥 Commits
Reviewing files that changed from the base of the PR and between 8977bb43e34469460cddae479c9ca254bfe7254a and
a110391ea9.📒 Files selected for processing: 9
CMakeLists.txtsrc/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; 5 remain after this review.
📝 Walkthrough
The change adds draw planning and record management for per-vertex VS-store data. The SPIR-V emitter can write vertex parameters to the store and load corner values in the fragment stage. CPU, shader-configuration, GPU, and mutation tests exercise these paths.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Feature
Merge Risk: ⚪ Minimal · up to
a1103This adds an opt-in per-vertex shader emission path with no renderer wiring, so current rendering behavior is unchanged. No merge-blocking issue remains in the reviewed context.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 30.23% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 86 functions across 10 files. (2 skipped: 1 unsupported, 1 too large.)
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 +141,4 @@// shaders.if (request.range_end > 0xffffffffull || records > 0xffffffffull ||records * request.record_stride_vec4 * 4ull > 0xffffffffull)return reject(V::TooLarge);@coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · edited 2026-10-12 10:20 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Bound the record count by the
uint32_tbase too.PlanPvVsStorechecks onlyrecords * stride * 4against 2^32. Ifrecord_stride_vec4is 0 (the dynamic-stride default), the product is 0. In that caserecordscan exceed 2^32 and still returnUse.PvVsStoreRing::Allocatethen truncatesm_usedinto theuint32_t base. The shader math also wraps. Reject a request whenrecords > 0xffffffff, and rejectrecord_stride_vec4 == 0for VS-store use.Proposed fix
📝 Committable suggestion
✅ Addressed in commits 39ec292 to 98aac3b
@ -0,0 +554,4 @@cp_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // the loop re-records one buffercp_info.queueFamilyIndex = gpu.family;VkCommandPool pool = VK_NULL_HANDLE;CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");@coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · edited 2026-10-12 10:16 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Create the command pool with
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT.The loop at Line 596 records each case into the same
cmd. Line 645 callsvkBeginCommandBuffer_again after the previous submission ran.vkBeginCommandBufferdoes an implicit reset only if the pool hasVK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT. Herecp_info.flagsis 0. From the second case on, every recording is invalid usage (VUID-vkBeginCommandBuffer-commandBuffer-00050). MoltenVK accepts this. Other drivers or the validation layers can give undefined results or reject the harness.🐛 Proposed fix
📝 Committable suggestion
✅ Addressed in commits 39ec292 to 98aac3b
@ -0,0 +689,4 @@submit.commandBufferCount = 1;submit.pCommandBuffers = &cmd;CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit");CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle");@coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · edited 2026-10-12 10:18 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add the memory dependencies before the image copy and before the host readback.
The render pass has no
VkSubpassDependencytoVK_SUBPASS_EXTERNAL. The implicit external dependency hasdstStageMask = BOTTOM_OF_PIPEanddstAccessMask = 0. As a result,vkCmdCopyImageToBuffer_at Line 667 has no synchronization with the color-attachment writes. It also has no synchronization with the final layout transition.The host reads
readback.mappedandcap.mappedaftervkQueueWaitIdle_. No barrier makes the transfer writes or the vertex-shader SSBO writes available toVK_ACCESS_HOST_READ_BIT. The harness compares results bit for bit. On a non-MoltenVK driver, these hazards can produce false FAIL results.vkCmdPipelineBarrier_is already loaded but never called. Add:vkCmdEndRenderPass_) fromCOLOR_ATTACHMENT_OUTPUT/COLOR_ATTACHMENT_WRITEtoTRANSFER/TRANSFER_READ;TRANSFER | VERTEX_SHADER(TRANSFER_WRITE | SHADER_WRITE) toHOST/HOST_READ.🐛 Proposed fix
The barrier after
vkCmdEndRenderPass_covers the attachment writes. The layout transition tofinalLayoutstill runs under the implicit external dependency. To be fully correct, also add an explicitVkSubpassDependency(subpass 0 →VK_SUBPASS_EXTERNAL) with these same stage and access masks.📝 Committable suggestion
✅ Addressed in commits 39ec292 to 98aac3b
@coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · reviewed
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
f0c5dd58-51e3-4fae-9d2a-2f1bfb5bace6📥 Commits
Reviewing files that changed from the base of the PR and between
dad900c61dand 7e06c0f9c02ddb2584b1d7f8ad6f5028f0f5090e.📒 Files selected for processing (14)
CMakeLists.txtsrc/graphics/host_gpu/renderer/perVertexVsStore.hsrc/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; 6 remain after this review.
@ -0,0 +141,4 @@// shaders.if (request.range_end > 0xffffffffull || records > 0xffffffffull ||records * request.record_stride_vec4 * 4ull > 0xffffffffull)return reject(V::TooLarge);@wuboo on GitHub · 2026-10-12 10:09 UTC · original
Valid, fixed in 39ec2925.
PlanPvVsStorerejectsrecord_stride_vec4 == 0(verdictEmpty: nothing to store) and boundsrecordsitself by 2^32-1 (TooLarge). Besides the zero stride, the 64-bit product could also wrap: with span 2^30, 2^30 instances and stride 4 it is exactly 2^64 = 0, so that case is in the test too. Tests:per_vertex_vsstore, mutantsstride_zero_okandrecords_wrap_ok(both fail the test).@ -0,0 +554,4 @@cp_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // the loop re-records one buffercp_info.queueFamilyIndex = gpu.family;VkCommandPool pool = VK_NULL_HANDLE;CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");@wuboo on GitHub · 2026-10-12 10:09 UTC · original
Valid, fixed in 138066c3: the pool is created with
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BITsince the loop re-records one command buffer.@ -0,0 +689,4 @@submit.commandBufferCount = 1;submit.pCommandBuffers = &cmd;CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit");CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle");@wuboo on GitHub · 2026-10-12 10:09 UTC · original
Valid, fixed in 138066c3. Instead of a barrier after
vkCmdEndRenderPassI added an explicitVkSubpassDependency(colour attachment write -> transfer read), which also orders the final layout transition, plus a barrier after the copy (transfer write + vertex shader write -> host read). The harness compiles; it could not be run here (no Vulkan loader in the test environment, same SKIP as in the baseline), so the change is not verified on a GPU.@coderabbitai[bot] on GitHub · 2026-10-12 10:16 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
9b25bd48-ab19-43ef-9393-ba93b2df8b06📥 Commits
Reviewing files that changed from the base of the PR and between 7e06c0f9c02ddb2584b1d7f8ad6f5028f0f5090e and 98aac3b9cb34b458d68784e3965f051e8113952a.
📒 Files selected for processing (7)
CMakeLists.txtsrc/graphics/host_gpu/renderer/perVertexVsStore.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpptests/PerVertexVsStoreGpuTests.cpptests/PerVertexVsStoreMutants.cmaketests/PerVertexVsStoreTests.cpptests/shaderCfgTests.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; 6 remain after this review.
@ -0,0 +554,4 @@cp_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // the loop re-records one buffercp_info.queueFamilyIndex = gpu.family;VkCommandPool pool = VK_NULL_HANDLE;CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");@coderabbitai[bot] on GitHub · 2026-10-12 10:16 UTC · original
@wubooThanks for confirming the fix in138066c3.VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BITpermits the implicit reset when the loop records the command buffer again.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.
@ -0,0 +689,4 @@submit.commandBufferCount = 1;submit.pCommandBuffers = &cmd;CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit");CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle");@coderabbitai[bot] on GitHub · 2026-10-12 10:18 UTC · original
@wubooThanks for the fix in138066c3. The explicitVkSubpassDependencyaddresses the image-copy dependency and orders the final layout transition. The post-copy barrier addresses host visibility for both readback buffers.GPU behavior remains unverified because the test environment has no Vulkan loader.
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.
@ -0,0 +141,4 @@// shaders.if (request.range_end > 0xffffffffull || records > 0xffffffffull ||records * request.record_stride_vec4 * 4ull > 0xffffffffull)return reject(V::TooLarge);@coderabbitai[bot] on GitHub · 2026-10-12 10:21 UTC · original
@wuboo, thanks for the fix. ReturningEmptyfor zero stride is appropriate. The explicit record-count bound also rejects the case where the 64-bit product wraps to zero. The reported regression tests and mutants cover both failure paths.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.
@ -0,0 +689,4 @@submit.commandBufferCount = 1;submit.pCommandBuffers = &cmd;CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit");CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle");@wuboo on GitHub · 2026-10-12 12:09 UTC · original
Follow-up: the harness with 138066c3 has now been run on MoltenVK (Apple M3 Max): all 7 cases pass,
--stresspasses, and both harness mutants fail as expected.@ -0,0 +689,4 @@submit.commandBufferCount = 1;submit.pCommandBuffers = &cmd;CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit");CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle");@coderabbitai[bot] on GitHub · 2026-10-12 12:09 UTC · original
@wubooThanks for the update. Your results confirm that138066c3passes all seven cases and--stresson MoltenVK with Apple M3 Max. Both harness mutants fail as expected.This closes the earlier GPU-validation gap for that environment. It does not establish behavior on other drivers.
✅ Review thread resolved.
You are interacting with an AI system.
Pull request closed