shader: add a VS-store emitter for per-vertex pixel inputs (no renderer wiring) #1440

Closed
github-bot wants to merge 7 commits from gh-pr/1440/head into gh-pr/1440/base
Owner

@⁠wuboo on GitHub · 2026-10-12 06:54 UTC · original
wuboo:pr/pv-vsstore-emitter → main · +2309 −5 · 14 files · 7 commits · closed without merging

What this is

Pixel shaders that read raw vertex attributes (V_INTERP_MOV of a parameter, or the barycentric
VGPRs) are emitted with PerVertexKHR inputs and VK_KHR_fragment_shader_barycentric. MoltenVK does
not 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.

  • VS variant: the vertex shader writes every Parameter output as a uvec4 (bits unchanged) to
    cap[record * stride + slot] in a storage buffer (set 1, binding 0). record is
    base + (instance - first_instance) * span + (vertex_index - first).
  • PS variant: instead of PerVertexKHR inputs, the pixel shader reads the three corners of its
    primitive from the same buffer, using gl_PrimitiveID and 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 PerVertexKHR path would give.
  • The host parameter location is the slot, so the two variants are emitted independently (the PS does
    not need to know its VS). Location 31 carries the instance index VS -> PS and is therefore reserved.
  • Both variants take an 8-dword push block after the native push data (kPvVsStorePushDwords).
  • perVertexVsStore.h holds 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.

EmitProgram gets an optional PvStoreInfo*; with nullptr (all existing callers) the output is
unchanged.

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-bit
    indices, vertex_offset of both signs, first_instance, odd 16-bit ends, index-descriptor clamp,
    ring and slab reuse.
  • shader_cfg gains TestPvVsStoreEmission: both variants validate with spirv-val, the VS-store PS
    reads the same corners as the PerVertexKHR PS, and the dynamic stride comes from push dword 7.
  • Mutants. The production sources carry no mutant switches. tests/PerVertexVsStoreMutants.cmake
    generates, at configure time, a copy of perVertexVsStore.h (or of spirvEmitterPvStore.cpp) with
    one expression changed; each mutant's test must fail (WILL_FAIL, or a grep for the failure message
    where 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 the
    emission again).
  • GPU harness per_vertex_vsstore_gpu_tests (opt-in, needs MoltenVK via SDL_VULKAN_LIBRARY, not
    part 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 of
    minStorageBufferOffsetAlignment, 16-bit indices ending inside a word), and reads the cap buffer
    back to check what gl_VertexIndex / gl_InstanceIndex contain. --stress adds 2 cases of

    = 2M triangles x 2..4 instances (tile parameter buffer overflow). --dump prints the SPIR-V
    without a GPU. Two harness mutants (corner swap, unrounded index range) must fail it.

Validation

  • Rebased on main at dad900c6; full ctest unchanged against main (the 19 tests that need a Vulkan
    loader skip without one), new tests and all mutants as above.
  • The GPU harness passes 7/7 cases and the --stress cases on MoltenVK (Apple silicon).
  • Nothing in this PR is used by the renderer, so main behaves exactly as before; the in-game numbers are
    in the follow-up #1441.

Limits worth knowing (TBDR)

  • The scheme relies on the vertex stage of a draw having written the buffer before the fragment stage
    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 Coherent and the VS issues a memory barrier after its stores. It has been
    checked with the harness above on MoltenVK only and is not meant for immediate-mode GPUs.
  • Triangle lists only. The planner rejects other topologies, non-indexed draws, primitive restart,
    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.
  • The pixel stage keeps whatever barycentric reads the guest shader itself makes (gl_BaryCoord* for
    smooth 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.
  • Memory: one record is stride * 16 bytes per vertex per instance for the life of the render pass.
  • The CPU tests cover the arithmetic and the emitted SPIR-V; they cannot tell whether a driver orders
    the stages as assumed. That is what the harness is for.
**@⁠wuboo** on GitHub · 2026-10-12 06:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440) `wuboo:pr/pv-vsstore-emitter` → `main` · +2309 −5 · 14 files · 7 commits · closed without merging ## What this is Pixel shaders that read raw vertex attributes (`V_INTERP_MOV` of a parameter, or the barycentric VGPRs) are emitted with `PerVertexKHR` inputs and `VK_KHR_fragment_shader_barycentric`. MoltenVK does not 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. - **VS variant:** the vertex shader writes every `Parameter` output as a `uvec4` (bits unchanged) to `cap[record * stride + slot]` in a storage buffer (set 1, binding 0). `record` is `base + (instance - first_instance) * span + (vertex_index - first)`. - **PS variant:** instead of `PerVertexKHR` inputs, the pixel shader reads the three corners of its primitive from the same buffer, using `gl_PrimitiveID` and 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 `PerVertexKHR` path would give. - The host parameter location is the slot, so the two variants are emitted independently (the PS does not need to know its VS). Location 31 carries the instance index VS -> PS and is therefore reserved. - Both variants take an 8-dword push block after the native push data (`kPvVsStorePushDwords`). - `perVertexVsStore.h` holds 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. `EmitProgram` gets an optional `PvStoreInfo*`; with `nullptr` (all existing callers) the output is unchanged. ## 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-bit indices, `vertex_offset` of both signs, `first_instance`, odd 16-bit ends, index-descriptor clamp, ring and slab reuse. - `shader_cfg` gains `TestPvVsStoreEmission`: both variants validate with `spirv-val`, the VS-store PS reads the same corners as the `PerVertexKHR` PS, and the dynamic stride comes from push dword 7. - **Mutants.** The production sources carry no mutant switches. `tests/PerVertexVsStoreMutants.cmake` generates, at configure time, a copy of `perVertexVsStore.h` (or of `spirvEmitterPvStore.cpp`) with one expression changed; each mutant's test must fail (`WILL_FAIL`, or a grep for the failure message where 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 the emission again). - **GPU harness** `per_vertex_vsstore_gpu_tests` (opt-in, needs MoltenVK via `SDL_VULKAN_LIBRARY`, not part 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 of `minStorageBufferOffsetAlignment`, 16-bit indices ending inside a word), and reads the cap buffer back to check what `gl_VertexIndex` / `gl_InstanceIndex` contain. `--stress` adds 2 cases of >= 2M triangles x 2..4 instances (tile parameter buffer overflow). `--dump` prints the SPIR-V without a GPU. Two harness mutants (corner swap, unrounded index range) must fail it. ## Validation - Rebased on `main` at `dad900c6`; full `ctest` unchanged against `main` (the 19 tests that need a Vulkan loader skip without one), new tests and all mutants as above. - The GPU harness passes 7/7 cases and the `--stress` cases on MoltenVK (Apple silicon). - Nothing in this PR is used by the renderer, so `main` behaves exactly as before; the in-game numbers are in the follow-up #1441. ## Limits worth knowing (TBDR) - The scheme relies on the vertex stage of a draw having written the buffer before the fragment stage 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 `Coherent` and the VS issues a memory barrier after its stores. It has been checked with the harness above on MoltenVK only and is not meant for immediate-mode GPUs. - Triangle lists only. The planner rejects other topologies, non-indexed draws, primitive restart, 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. - The pixel stage keeps whatever barycentric reads the guest shader itself makes (`gl_BaryCoord*` for smooth 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. - Memory: one record is `stride * 16` bytes per vertex per instance for the life of the render pass. - The CPU tests cover the arithmetic and the emitted SPIR-V; they cannot tell whether a driver orders the stages as assumed. That is what the harness is for.
The vertex shader of a pair writes its Parameter outputs to a storage buffer
(cap[record * stride + slot], bits unchanged); the pixel shader reads the three
corners of its primitive back through gl_PrimitiveID and the draw's index buffer
instead of using PerVertexKHR inputs. EmitProgram takes an optional PvStoreInfo;
without it the output is unchanged.

perVertexVsStore.h holds the arithmetic both sides must agree on (record
numbering, draw plan, pass ring, slab bookkeeping, index-descriptor math,
fallback classification) with CPU tests. Mutants are generated at configure time
from copies of the sources (tests/PerVertexVsStoreMutants.cmake), so the
production sources carry no mutant switches.
Draws the real emitter output with the renderer's set/push layout and compares
every probed pixel bit for bit with the CPU per-vertex model; reads the cap
buffer back to check what gl_VertexIndex / gl_InstanceIndex contain. Cases: 16-
and 32-bit indices, vertex_offset of both signs, first_instance, two instances,
an index buffer bound at an offset that is not a multiple of
minStorageBufferOffsetAlignment, 16-bit indices ending inside a word; --stress
adds draws of 2M+ triangles with 2..4 instances. --dump prints the SPIR-V and
needs no GPU. Opt-in (MoltenVK through SDL_VULKAN_LIBRARY), not part of ctest.
Two harness mutants (corners 0/2 swapped, unrounded index range) must fail it.
Location 31 carries the instance index from the VS to the PS, so a pair that
uses it cannot take the VS-store path, but the emitter used to abort the
process on it before ClassifyPvVsStoreInterface could reject the pair. The
location is now recorded and the interface check decides. Test: a VS exporting
parameter 31 emits and reports location 31; mutant: the old abort.
PlanPvVsStore multiplied records by the record stride in 64 bits only. A zero
stride made the product 0 whatever the draw size, and a record count near 2^60
wrapped the product around 2^64, so both passed as Use although the record base is
a uint32_t. The plan now bounds the record count itself and treats a zero stride
as nothing to store.

Tests: per_vertex_vsstore with mutants stride_zero_ok and records_wrap_ok.
Create the command pool with the reset flag, because the loop re-records one
command buffer for every case. Add the memory dependencies the harness lacked: a
subpass dependency from the colour attachment writes (and the final layout
transition) to the copy, and a barrier from the copy and the vertex shader stores
to the host reads. MoltenVK accepted the old harness; other drivers or the
validation layers need these.
The VS-store pixel shader reads PrimitiveId and declared the Geometry capability
for it. The device enables tessellationShader but never geometryShader (MoltenVK
has none), so a module declaring Geometry uses a feature that is not enabled.
PrimitiveId in a fragment shader is also valid with Tessellation.

Tests: shader_cfg checks the capability; the capability_geometry mutant
(shader_cfg_pv_vsstore_mutant_capability_geometry) brings Geometry back.
The VS-store pixel shader declares the Tessellation capability for PrimitiveId, so the
harness has to enable that feature (as the renderer does) instead of geometryShader.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:47 +00:00
github-bot closed this pull request 2026-11-26 09:56:47 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · edited 2026-10-16 18:01 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 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.txt
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
  • tests/PerVertexVsStoreGpuTests.cpp
  • tests/shaderCfgTests.cpp

Included 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: nmzik

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to a1103

This 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: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: adding a VS-store SPIR-V emitter for per-vertex pixel inputs, while noting that renderer wiring is deferred.
Description check Passed The description directly explains the VS-store emission path, shared helpers, tests, GPU harness, limitations, and deferred renderer integration.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 07:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#issuecomment-6119366396) · edited 2026-10-16 18:01 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1440?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9846703b-c8c3-47ff-9b0f-695280bca18e` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 8977bb43e34469460cddae479c9ca254bfe7254a and a110391ea929223ac2dca6c01059936d44d3ea24. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 9</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp` * `src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp` * `tests/PerVertexVsStoreGpuTests.cpp` * `tests/shaderCfgTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> 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:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"a110391ea929223ac2dca6c01059936d44d3ea24" --> **Change:** Feature <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>a1103</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `a1103` --> <!-- final_review_risk_coverage:{"sourceCommitId":"a110391ea929223ac2dca6c01059936d44d3ea24","coveredCommitId":"a110391ea929223ac2dca6c01059936d44d3ea24","kind":"reviewed"} --> This 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. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | 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:… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main change: adding a VS-store SPIR-V emitter for per-vertex pixel inputs, while noting that renderer wiring is deferred. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the VS-store emission path, shared helpers, tests, GPU harness, limitations, and deferred renderer integration. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **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. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1440)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -0,0 +141,4 @@
// shaders.
if (request.range_end > 0xffffffffull || records > 0xffffffffull ||
records * request.record_stride_vec4 * 4ull > 0xffffffffull)
return reject(V::TooLarge);
Author
Owner

@⁠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_t base too.

PlanPvVsStore checks only records * stride * 4 against 2^32. If record_stride_vec4 is 0 (the dynamic-stride default), the product is 0. In that case records can exceed 2^32 and still return Use. PvVsStoreRing::Allocate then truncates m_used into the uint32_t base. The shader math also wraps. Reject a request when records > 0xffffffff, and reject record_stride_vec4 == 0 for VS-store use.

Proposed fix
-	if (request.range_end > 0xffffffffull ||
+	if (request.range_end > 0xffffffffull || records > 0xffffffffull ||
+	    request.record_stride_vec4 == 0 ||
 	    records * request.record_stride_vec4 * 4ull > 0xffffffffull)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

	if (request.index_count < kPvVsStoreCorners || request.instance_count == 0 ||
	    request.range_end <= request.range_first)
		return reject(V::Empty);
	const uint64_t span    = request.range_end - request.range_first;
	const uint64_t records = span * request.instance_count;
	// Record * stride * 4 dwords must stay below 2^32 in the shaders.
	if (request.range_end > 0xffffffffull || records > 0xffffffffull ||
	    request.record_stride_vec4 == 0 ||
	    records * request.record_stride_vec4 * 4ull > 0xffffffffull)
		return reject(V::TooLarge);

✅ Addressed in commits 39ec292 to 98aac3b

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 07:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4245393410) · edited 2026-10-12 10:20 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Bound the record count by the `uint32_t` base too.** `PlanPvVsStore` checks only `records * stride * 4` against 2^32. If `record_stride_vec4` is 0 (the dynamic-stride default), the product is 0. In that case `records` can exceed 2^32 and still return `Use`. `PvVsStoreRing::Allocate` then truncates `m_used` into the `uint32_t base`. The shader math also wraps. Reject a request when `records > 0xffffffff`, and reject `record_stride_vec4 == 0` for VS-store use. <details> <summary>Proposed fix</summary> ```diff - if (request.range_end > 0xffffffffull || + if (request.range_end > 0xffffffffull || records > 0xffffffffull || + request.record_stride_vec4 == 0 || records * request.record_stride_vec4 * 4ull > 0xffffffffull) ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion if (request.index_count < kPvVsStoreCorners || request.instance_count == 0 || request.range_end <= request.range_first) return reject(V::Empty); const uint64_t span = request.range_end - request.range_first; const uint64_t records = span * request.instance_count; // Record * stride * 4 dwords must stay below 2^32 in the shaders. if (request.range_end > 0xffffffffull || records > 0xffffffffull || request.record_stride_vec4 == 0 || records * request.record_stride_vec4 * 4ull > 0xffffffffull) return reject(V::TooLarge); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:51ba70accc56c21521e683af --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ 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 buffer
cp_info.queueFamilyIndex = gpu.family;
VkCommandPool pool = VK_NULL_HANDLE;
CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");
Author
Owner

@⁠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 calls vkBeginCommandBuffer_ again after the previous submission ran. vkBeginCommandBuffer does an implicit reset only if the pool has VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT. Here cp_info.flags is 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
--- "a/tests/PerVertexVsStoreGpuTests.cpp"
+++ "b/tests/PerVertexVsStoreGpuTests.cpp"
@@ -538,8 +538,9 @@
 	VkPipeline pipeline = VK_NULL_HANDLE;
 	CheckVk(vkCreateGraphicsPipelines_(gpu.device, VK_NULL_HANDLE, 1, &gi, nullptr, &pipeline), "graphics pipeline");
 
 	VkCommandPoolCreateInfo cp_info {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
+	cp_info.flags            = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
 	cp_info.queueFamilyIndex = gpu.family;
 	VkCommandPool pool = VK_NULL_HANDLE;
 	CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");
 	VkCommandBufferAllocateInfo cb_alloc {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

	VkCommandPoolCreateInfo cp_info {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
	cp_info.flags            = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
	cp_info.queueFamilyIndex = gpu.family;
	VkCommandPool pool = VK_NULL_HANDLE;
	CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");

✅ Addressed in commits 39ec292 to 98aac3b

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 07:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4245393427) · 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 calls `vkBeginCommandBuffer_` again after the previous submission ran. `vkBeginCommandBuffer` does an implicit reset only if the pool has `VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT`. Here `cp_info.flags` is 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. <details> <summary>🐛 Proposed fix</summary> ```diff --- "a/tests/PerVertexVsStoreGpuTests.cpp" +++ "b/tests/PerVertexVsStoreGpuTests.cpp" @@ -538,8 +538,9 @@ VkPipeline pipeline = VK_NULL_HANDLE; CheckVk(vkCreateGraphicsPipelines_(gpu.device, VK_NULL_HANDLE, 1, &gi, nullptr, &pipeline), "graphics pipeline"); VkCommandPoolCreateInfo cp_info {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; + cp_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; cp_info.queueFamilyIndex = gpu.family; VkCommandPool pool = VK_NULL_HANDLE; CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool"); VkCommandBufferAllocateInfo cb_alloc {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO}; ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion VkCommandPoolCreateInfo cp_info {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; cp_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; cp_info.queueFamilyIndex = gpu.family; VkCommandPool pool = VK_NULL_HANDLE; CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool"); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:68fc9c81bc839df057a3d75a --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ 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");
Author
Owner

@⁠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 VkSubpassDependency to VK_SUBPASS_EXTERNAL. The implicit external dependency has dstStageMask = BOTTOM_OF_PIPE and dstAccessMask = 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.mapped and cap.mapped after vkQueueWaitIdle_. No barrier makes the transfer writes or the vertex-shader SSBO writes available to VK_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:

  • a subpass dependency (or a barrier after vkCmdEndRenderPass_) from COLOR_ATTACHMENT_OUTPUT/COLOR_ATTACHMENT_WRITE to TRANSFER/TRANSFER_READ;
  • a barrier after the copy from TRANSFER | VERTEX_SHADER (TRANSFER_WRITE | SHADER_WRITE) to HOST/HOST_READ.
🐛 Proposed fix
--- "a/tests/PerVertexVsStoreGpuTests.cpp"
+++ "b/tests/PerVertexVsStoreGpuTests.cpp"
@@ -660,12 +660,22 @@
 		vkCmdPushConstants_(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, push_offset, sizeof(block), block.data());
 		// same as the renderer: firstIndex 0, the index buffer is bound at its offset
 		vkCmdDrawIndexed_(cmd, count, c.instance_count, 0, c.vertex_offset, c.first_instance);
 		vkCmdEndRenderPass_(cmd);
+		VkMemoryBarrier to_copy {VK_STRUCTURE_TYPE_MEMORY_BARRIER};
+		to_copy.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
+		to_copy.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
+		vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &to_copy, 0,
+		                      nullptr, 0, nullptr);
 		VkBufferImageCopy copy {};
 		copy.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
 		copy.imageExtent      = {kDim, kDim, 1};
 		vkCmdCopyImageToBuffer_(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, readback.buffer, 1, &copy);
+		VkMemoryBarrier to_host {VK_STRUCTURE_TYPE_MEMORY_BARRIER};
+		to_host.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
+		to_host.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
+		vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1,
+		                      &to_host, 0, nullptr, 0, nullptr);
 		CheckVk(vkEndCommandBuffer_(cmd), "end");
 		VkSubmitInfo submit {VK_STRUCTURE_TYPE_SUBMIT_INFO};
 		submit.commandBufferCount = 1;
 		submit.pCommandBuffers    = &cmd;

The barrier after vkCmdEndRenderPass_ covers the attachment writes. The layout transition to finalLayout still runs under the implicit external dependency. To be fully correct, also add an explicit VkSubpassDependency (subpass 0 → VK_SUBPASS_EXTERNAL) with these same stage and access masks.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		vkCmdEndRenderPass_(cmd);
		VkMemoryBarrier to_copy {VK_STRUCTURE_TYPE_MEMORY_BARRIER};
		to_copy.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
		to_copy.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
		vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &to_copy, 0,
		                      nullptr, 0, nullptr);
		VkBufferImageCopy copy {};
		copy.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
		copy.imageExtent      = {kDim, kDim, 1};
		vkCmdCopyImageToBuffer_(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, readback.buffer, 1, &copy);
		VkMemoryBarrier to_host {VK_STRUCTURE_TYPE_MEMORY_BARRIER};
		to_host.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
		to_host.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
		vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1,
		                      &to_host, 0, nullptr, 0, nullptr);
		CheckVk(vkEndCommandBuffer_(cmd), "end");
		VkSubmitInfo submit {VK_STRUCTURE_TYPE_SUBMIT_INFO};
		submit.commandBufferCount = 1;
		submit.pCommandBuffers    = &cmd;
		CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit");
		CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle");

✅ Addressed in commits 39ec292 to 98aac3b

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 07:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4245393435) · 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 `VkSubpassDependency` to `VK_SUBPASS_EXTERNAL`. The implicit external dependency has `dstStageMask = BOTTOM_OF_PIPE` and `dstAccessMask = 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.mapped` and `cap.mapped` after `vkQueueWaitIdle_`. No barrier makes the transfer writes or the vertex-shader SSBO writes available to `VK_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: - a subpass dependency (or a barrier after `vkCmdEndRenderPass_`) from `COLOR_ATTACHMENT_OUTPUT`/`COLOR_ATTACHMENT_WRITE` to `TRANSFER`/`TRANSFER_READ`; - a barrier after the copy from `TRANSFER | VERTEX_SHADER` (`TRANSFER_WRITE | SHADER_WRITE`) to `HOST`/`HOST_READ`. <details> <summary>🐛 Proposed fix</summary> ```diff --- "a/tests/PerVertexVsStoreGpuTests.cpp" +++ "b/tests/PerVertexVsStoreGpuTests.cpp" @@ -660,12 +660,22 @@ vkCmdPushConstants_(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, push_offset, sizeof(block), block.data()); // same as the renderer: firstIndex 0, the index buffer is bound at its offset vkCmdDrawIndexed_(cmd, count, c.instance_count, 0, c.vertex_offset, c.first_instance); vkCmdEndRenderPass_(cmd); + VkMemoryBarrier to_copy {VK_STRUCTURE_TYPE_MEMORY_BARRIER}; + to_copy.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + to_copy.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &to_copy, 0, + nullptr, 0, nullptr); VkBufferImageCopy copy {}; copy.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; copy.imageExtent = {kDim, kDim, 1}; vkCmdCopyImageToBuffer_(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, readback.buffer, 1, &copy); + VkMemoryBarrier to_host {VK_STRUCTURE_TYPE_MEMORY_BARRIER}; + to_host.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT; + to_host.dstAccessMask = VK_ACCESS_HOST_READ_BIT; + vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, + &to_host, 0, nullptr, 0, nullptr); CheckVk(vkEndCommandBuffer_(cmd), "end"); VkSubmitInfo submit {VK_STRUCTURE_TYPE_SUBMIT_INFO}; submit.commandBufferCount = 1; submit.pCommandBuffers = &cmd; ``` The barrier after `vkCmdEndRenderPass_` covers the attachment writes. The layout transition to `finalLayout` still runs under the implicit external dependency. To be fully correct, also add an explicit `VkSubpassDependency` (subpass 0 → `VK_SUBPASS_EXTERNAL`) with these same stage and access masks. </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion vkCmdEndRenderPass_(cmd); VkMemoryBarrier to_copy {VK_STRUCTURE_TYPE_MEMORY_BARRIER}; to_copy.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; to_copy.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &to_copy, 0, nullptr, 0, nullptr); VkBufferImageCopy copy {}; copy.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; copy.imageExtent = {kDim, kDim, 1}; vkCmdCopyImageToBuffer_(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, readback.buffer, 1, &copy); VkMemoryBarrier to_host {VK_STRUCTURE_TYPE_MEMORY_BARRIER}; to_host.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT; to_host.dstAccessMask = VK_ACCESS_HOST_READ_BIT; vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, &to_host, 0, nullptr, 0, nullptr); CheckVk(vkEndCommandBuffer_(cmd), "end"); VkSubmitInfo submit {VK_STRUCTURE_TYPE_SUBMIT_INFO}; submit.commandBufferCount = 1; submit.pCommandBuffers = &cmd; CheckVk(vkQueueSubmit_(gpu.queue, 1, &submit, VK_NULL_HANDLE), "submit"); CheckVk(vkQueueWaitIdle_(gpu.queue), "wait idle"); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:7eb7b1d22393a331a62d6c6f --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commits 39ec292 to 98aac3b
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 07:00 UTC · original · reviewed

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0c5dd58-51e3-4fae-9d2a-2f1bfb5bace6
📥 Commits

Reviewing files that changed from the base of the PR and between dad900c61d and 7e06c0f9c02ddb2584b1d7f8ad6f5028f0f5090e.

📒 Files selected for processing (14)
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/perVertexVsStore.h
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpp
  • tests/PerVertexVsStoreGpu.cmake
  • tests/PerVertexVsStoreGpuTests.cpp
  • tests/PerVertexVsStoreMutants.cmake
  • tests/PerVertexVsStoreTests.cpp
  • tests/shaderCfgTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 07:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#pullrequestreview-5487386721) · **reviewed** **Actionable comments posted: 3** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f0c5dd58-51e3-4fae-9d2a-2f1bfb5bace6` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between dad900c61d6c7ff8aefc9e666ca7c3de4bbf4176 and 7e06c0f9c02ddb2584b1d7f8ad6f5028f0f5090e. </details> <details> <summary>📒 Files selected for processing (14)</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/perVertexVsStore.h` * `src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp` * `src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpp` * `tests/PerVertexVsStoreGpu.cmake` * `tests/PerVertexVsStoreGpuTests.cpp` * `tests/PerVertexVsStoreMutants.cmake` * `tests/PerVertexVsStoreTests.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=a5e4bf59-23b6-4b79-a85b-b26e85eb6cc0 attempt=ec3f70eb-9394-4712-9010-10a3f854d60d batch=1/1 -->
@ -0,0 +141,4 @@
// shaders.
if (request.range_end > 0xffffffffull || records > 0xffffffffull ||
records * request.record_stride_vec4 * 4ull > 0xffffffffull)
return reject(V::TooLarge);
Author
Owner

@⁠wuboo on GitHub · 2026-10-12 10:09 UTC · original

Valid, fixed in 39ec2925. PlanPvVsStore rejects record_stride_vec4 == 0 (verdict Empty: nothing to store) and bounds records itself 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, mutants stride_zero_ok and records_wrap_ok (both fail the test).

**@⁠wuboo** on GitHub · 2026-10-12 10:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4246832822) Valid, fixed in 39ec2925. `PlanPvVsStore` rejects `record_stride_vec4 == 0` (verdict `Empty`: nothing to store) and bounds `records` itself 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`, mutants `stride_zero_ok` and `records_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 buffer
cp_info.queueFamilyIndex = gpu.family;
VkCommandPool pool = VK_NULL_HANDLE;
CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");
Author
Owner

@⁠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_BIT since the loop re-records one command buffer.

**@⁠wuboo** on GitHub · 2026-10-12 10:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4246833060) Valid, fixed in 138066c3: the pool is created with `VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT` since 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");
Author
Owner

@⁠wuboo on GitHub · 2026-10-12 10:09 UTC · original

Valid, fixed in 138066c3. Instead of a barrier after vkCmdEndRenderPass I added an explicit VkSubpassDependency (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.

**@⁠wuboo** on GitHub · 2026-10-12 10:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4246833305) Valid, fixed in 138066c3. Instead of a barrier after `vkCmdEndRenderPass` I added an explicit `VkSubpassDependency` (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.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 10:16 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Do not use OpMemoryBarrier to synchronize this same-draw… · spirvEmitterPvStore.cpp:179-192

src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpp:179-192
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Do not use OpMemoryBarrier to synchronize this same-draw buffer handoff.

OpMemoryBarrier orders memory accesses, but it does not synchronize vertex and fragment invocations. Coherent does not add that execution dependency. A fragment load can therefore observe stale or uninitialized records written by other vertex invocations. The planner has no device-ordering capability gate, and the GPU harness opts into coherent mode and performs the store and load in one draw.

Keep this path on PerVertexKHR unless the producer and consumer use separate commands with an API-level memory dependency.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 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.txt
  • src/graphics/host_gpu/renderer/perVertexVsStore.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpp
  • tests/PerVertexVsStoreGpuTests.cpp
  • tests/PerVertexVsStoreMutants.cmake
  • tests/PerVertexVsStoreTests.cpp
  • tests/shaderCfgTests.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/PerVertexVsStoreTests.cpp
  • tests/PerVertexVsStoreGpuTests.cpp
  • src/graphics/host_gpu/renderer/perVertexVsStore.h

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 10:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#pullrequestreview-5489347059) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟠 Major</strong> · Do not use <code>OpMemoryBarrier</code> to synchronize this same-draw… · <code>spirvEmitterPvStore.cpp:179-192</code></summary><blockquote> > > `src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpp:179-192` > **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** > > **Do not use `OpMemoryBarrier` to synchronize this same-draw buffer handoff.** > > `OpMemoryBarrier` orders memory accesses, but it does not synchronize vertex and fragment invocations. `Coherent` does not add that execution dependency. A fragment load can therefore observe stale or uninitialized records written by other vertex invocations. The planner has no device-ordering capability gate, and the GPU harness opts into `coherent` mode and performs the store and load in one draw. > > Keep this path on `PerVertexKHR` unless the producer and consumer use separate commands with an API-level memory dependency. > > <!-- cr-comment:v1:ff234615e08a7b73fb4b3c29 --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9b25bd48-ab19-43ef-9393-ba93b2df8b06` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7e06c0f9c02ddb2584b1d7f8ad6f5028f0f5090e and 98aac3b9cb34b458d68784e3965f051e8113952a. </details> <details> <summary>📒 Files selected for processing (7)</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/perVertexVsStore.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterPvStore.cpp` * `tests/PerVertexVsStoreGpuTests.cpp` * `tests/PerVertexVsStoreMutants.cmake` * `tests/PerVertexVsStoreTests.cpp` * `tests/shaderCfgTests.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary> * tests/PerVertexVsStoreTests.cpp * tests/PerVertexVsStoreGpuTests.cpp * src/graphics/host_gpu/renderer/perVertexVsStore.h </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=c5e0227c-a4ce-42ca-9302-226099f2d40c attempt=94c9301e-6898-4382-98eb-9e151cf9eb94 batch=1/1 -->
@ -0,0 +554,4 @@
cp_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // the loop re-records one buffer
cp_info.queueFamilyIndex = gpu.family;
VkCommandPool pool = VK_NULL_HANDLE;
CheckVk(vkCreateCommandPool_(gpu.device, &cp_info, nullptr, &pool), "command pool");
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 10:16 UTC · original

@wuboo Thanks for confirming the fix in 138066c3. VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT permits 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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 10:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4246891958) `@wuboo` Thanks for confirming the fix in `138066c3`. `VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT` permits the implicit reset when the loop records the command buffer again. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Repeated%20command-buffer%20recording%20requires%20%60VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT%60%E2%80%94without%20it%2C%20later%20cases%20trigger%20invalid%20Vulkan%20usage.%20A%20small%20fix%20for%20cross-driver%20reliability.%20Try%20%40coderabbitai%20%F0%9F%90%87%E2%9C%85&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1440%23discussion_r4245393427)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
@ -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");
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 10:18 UTC · original

@wuboo Thanks for the fix in 138066c3. The explicit VkSubpassDependency addresses 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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 10:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4246902711) `@wuboo` Thanks for the fix in `138066c3`. The explicit `VkSubpassDependency` addresses 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. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Vulkan%20readback%20lacked%20synchronization%2C%20risking%20false%20test%20failures%20across%20drivers.%20%40coderabbitai%20flagged%20it%3B%20explicit%20render-pass%20and%20host-read%20barriers%20fix%20the%20hazards.%20Try%20%40coderabbitai%20for%20actionable%20code%20reviews!%20%F0%9F%9A%A6&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1440%23discussion_r4245393435)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
@ -0,0 +141,4 @@
// shaders.
if (request.range_end > 0xffffffffull || records > 0xffffffffull ||
records * request.record_stride_vec4 * 4ull > 0xffffffffull)
return reject(V::TooLarge);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 10:21 UTC · original

@wuboo, thanks for the fix. Returning Empty for 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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 10:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4246924574) `@wuboo`, thanks for the fix. Returning `Empty` for 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. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Bound%20records%20to%20uint32%20and%20reject%20zero%20stride%20in%20PlanPvVsStore%E2%80%94plus%20catch%2064-bit%20overflow.%20%40coderabbitai%20spotted%20a%20subtle%20shader%2Fring%20bug.%20Try%20it%20for%20sharper%20code%20reviews!%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1440%23discussion_r4245393410)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
@ -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");
Author
Owner

@⁠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, --stress passes, and both harness mutants fail as expected.

**@⁠wuboo** on GitHub · 2026-10-12 12:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4247834032) Follow-up: the harness with 138066c3 has now been run on MoltenVK (Apple M3 Max): all 7 cases pass, `--stress` passes, 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");
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 12:09 UTC · original

@wuboo Thanks for the update. Your results confirm that 138066c3 passes all seven cases and --stress on 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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 12:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1440#discussion_r4247837808) `@wuboo` Thanks for the update. Your results confirm that `138066c3` passes all seven cases and `--stress` on 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._ <!-- This is an auto-generated reply by CodeRabbit -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.