vulkan: use descriptor sets for MoltenVK shader pipelines #685

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

@⁠carbonimax on GitHub · 2026-09-17 19:32 UTC · original
carbonimax:codex/push-descriptor-moltenvk → main · +177 −119 · 5 files · 2 commits · closed without merging

Problem

On macOS, MoltenVK (1.4.3, binding through Metal3 argument buffers) does not deliver the storage
buffer length behind OpArrayLength when the buffer is bound with vkCmdPushDescriptorSetKHR.
With the same SPIR-V module and the same descriptor, OpArrayLength reads 0 through push
descriptors and 4 through regular descriptor sets.

The game's video conversion pixel shader (hash e197e307a5f2cb39) compares an index against
OpArrayLength and falls back to 0 when the bound check fails, so the converted video frame comes
out black with green bands.

Measurements

The real SPIR-V was instrumented offline (32-bit OpArrayLength result bit-packed into R,G,B, A
forced to 1.0 so an alpha blend cannot hide the value, module validated) and executed on the GPU:

binding path observed R over all 8 294 400 pixels OpArrayLength value
push descriptors 0 0
descriptor sets 4 4 (offset 13488, range 16)

Same module, same descriptor and same driver in both runs. Rendering the video render target with
plain descriptor sets produces the correct frame.

Change

  • SelectMaxPushDescriptors(vk::DriverId, uint32_t) returns 0 for vk::DriverId::eMoltenvk and
    passes the reported limit through for every other driver.
  • UsePushDescriptors(count, max) keeps the previous count <= max decision and additionally
    requires max > 0.
  • The driver id comes from vk::PhysicalDeviceDriverProperties, chained behind the existing
    vk::PhysicalDevicePushDescriptorProperties query; the emulator requests API version 1.3, so the
    structure is core and no extra query is needed.
  • The existing device selection log now reports the effective limit
    (Select device: ..., max push descriptors=0).
  • tests/PushDescriptorPolicyTests.cpp pins the policy: MoltenVK loses the limit, other drivers
    keep it, plus (0,0), (4,0), (33,32), (32,32), (4,32), (0,32).

Other drivers are unchanged by this patch: the previous descriptor_count <= max_push_descriptors
decision still holds whenever max_push_descriptors > 0, and the emulator's own push layouts
(tiler, blit helper, fault manager) are untouched.

Validation

  • On 104530e with this patch in a clean worktree, ninja kyty_emulator push_descriptor_policy_tests succeeds (635 compile steps, both targets linked) and
    push_descriptor_policy_tests prints PushDescriptorPolicyTests: ok; shader_cfg_tests also
    builds and passes in that same tree.
  • The two patched translation units compile with the project's production flags.
  • Game runs were done on a local experimental checkout that also carries the per-vertex prototype
    experiment, not on a build of this branch alone: there, the image read back from the GPU right
    before presentation decodes to a correct frame instead of black with green bands
    (A2R10G10B10_UNORM_PACK32 dump, 3840x2160), and the video plays correctly.

Known limits

  • Measured on MoltenVK 1.4.3 only; other versions were not tested.
  • No gameplay validation: a later vertex/fragment interface mismatch remains
    (Fragment input(s) `user(locn1)` mismatching vertex shader output type(s)), and it is not
    addressed here.
**@⁠carbonimax** on GitHub · 2026-09-17 19:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/685) `carbonimax:codex/push-descriptor-moltenvk` → `main` · +177 −119 · 5 files · 2 commits · closed without merging ## Problem On macOS, MoltenVK (1.4.3, binding through Metal3 argument buffers) does not deliver the storage buffer length behind `OpArrayLength` when the buffer is bound with `vkCmdPushDescriptorSetKHR`. With the same SPIR-V module and the same descriptor, `OpArrayLength` reads 0 through push descriptors and 4 through regular descriptor sets. The game's video conversion pixel shader (hash `e197e307a5f2cb39`) compares an index against `OpArrayLength` and falls back to 0 when the bound check fails, so the converted video frame comes out black with green bands. ## Measurements The real SPIR-V was instrumented offline (32-bit `OpArrayLength` result bit-packed into R,G,B, A forced to 1.0 so an alpha blend cannot hide the value, module validated) and executed on the GPU: | binding path | observed R over all 8 294 400 pixels | `OpArrayLength` value | | --- | --- | --- | | push descriptors | 0 | 0 | | descriptor sets | 4 | 4 (offset 13488, range 16) | Same module, same descriptor and same driver in both runs. Rendering the video render target with plain descriptor sets produces the correct frame. ## Change - `SelectMaxPushDescriptors(vk::DriverId, uint32_t)` returns 0 for `vk::DriverId::eMoltenvk` and passes the reported limit through for every other driver. - `UsePushDescriptors(count, max)` keeps the previous `count <= max` decision and additionally requires `max > 0`. - The driver id comes from `vk::PhysicalDeviceDriverProperties`, chained behind the existing `vk::PhysicalDevicePushDescriptorProperties` query; the emulator requests API version 1.3, so the structure is core and no extra query is needed. - The existing device selection log now reports the effective limit (`Select device: ..., max push descriptors=0`). - `tests/PushDescriptorPolicyTests.cpp` pins the policy: MoltenVK loses the limit, other drivers keep it, plus `(0,0)`, `(4,0)`, `(33,32)`, `(32,32)`, `(4,32)`, `(0,32)`. Other drivers are unchanged by this patch: the previous `descriptor_count <= max_push_descriptors` decision still holds whenever `max_push_descriptors > 0`, and the emulator's own push layouts (tiler, blit helper, fault manager) are untouched. ## Validation - On `104530e` with this patch in a clean worktree, `ninja kyty_emulator push_descriptor_policy_tests` succeeds (635 compile steps, both targets linked) and `push_descriptor_policy_tests` prints `PushDescriptorPolicyTests: ok`; `shader_cfg_tests` also builds and passes in that same tree. - The two patched translation units compile with the project's production flags. - Game runs were done on a local experimental checkout that also carries the per-vertex prototype experiment, not on a build of this branch alone: there, the image read back from the GPU right before presentation decodes to a correct frame instead of black with green bands (`A2R10G10B10_UNORM_PACK32` dump, 3840x2160), and the video plays correctly. ## Known limits - Measured on MoltenVK 1.4.3 only; other versions were not tested. - No gameplay validation: a later vertex/fragment interface mismatch remains (``Fragment input(s) `user(locn1)` mismatching vertex shader output type(s)``), and it is not addressed here.
MoltenVK 1.4.3 reads 0 from OpArrayLength for a storage buffer bound with
vkCmdPushDescriptorSetKHR, while the same descriptor bound as a regular descriptor set reads 4.
The game's video conversion pixel shader compares an index against OpArrayLength and falls back to
0 when the bound check fails, which paints the converted frame black with green bands on macOS.

Derive the push descriptor limit from the driver id and keep the push path only when the device
reports a non-zero limit, so other drivers keep their previous behaviour.
Apply the repository's pinned clang-format 22.1.3 hook to the source files modified by this pull request.

Assisted-by: OpenAI GPT-6.1 Sol
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:29:47 +00:00
github-bot closed this pull request 2026-11-26 09:29:47 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-17 21:02 UTC · original · edited 2026-10-13 22:44 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 0bb7bf7e-4813-43b2-a1f2-06977bab0946
📥 Commits

Reviewing files that changed from the base of the PR and between e0629fb56bc100977c5a0d2e62d4e9c28c2526c4 and b529ceee4e787e0290d30258a421c11574a8f6e6.

📒 Files selected for processing (4)
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/pipeline/shaders.cpp
  • src/graphics/host_gpu/vulkanCommon.h
  • src/graphics/presentation/window/vulkanWindow.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/graphics/host_gpu/vulkanCommon.h
  • src/graphics/host_gpu/renderer/pipeline/shaders.cpp

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

📝 Walkthrough

Walkthrough

The change adds helpers to select a push-descriptor limit and determine whether a descriptor layout can use push descriptors. Vulkan initialization queries driver properties and selects the limit using the driver ID and reported device limit. Descriptor-layout creation uses the shared eligibility helper. A standalone test executable covers policy behavior and is registered with CTest and the aggregate test target.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to b529c

MoltenVK avoids the reported push-descriptor issue by using regular descriptor sets, while other drivers retain their reported limit. No concrete merge-blocking risk is established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to bd289

This is a narrowly scoped driver compatibility change with no demonstrated increase in privileges or external access. Residual uncertainty concerns concurrent execution and behavior on actual devices.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed binding route applies to graphics and compute pipelines on a selected MoltenVK device, not only the video shader motivating the fix. It increases use of the existing descriptor heap without adding a new descriptor-submission interface.

Trust Boundaries and Controls

  • observed — Driver identity and the reported capability come from the selected Vulkan physical device. The policy narrows push-descriptor eligibility and leaves the existing validation-feature setup in place; the changed flow does not introduce a guest-supplied driver identity or privilege transition.

Resilience and Maintainability Implications

  • observed — The existing allocator reduces batch size on pool exhaustion or fragmentation and retires exhausted pools with completion ticks. Pool reset requires a completed tick. Normal renderer destruction invokes scheduler shutdown, which submits outstanding commands and waits before descriptor-heap member destruction. These are existing lifecycle controls reused by the newly routed pipelines.
Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the main change: using descriptor sets instead of push descriptors for MoltenVK shader pipelines.
Description check Passed The description directly explains the MoltenVK push-descriptor issue, the policy changes, tests, validation, and known limits.
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 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: 1 unsupported.)

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-09-17 21:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/685#issuecomment-5721176880) · edited 2026-10-13 22:44 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/685?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 --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- 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**: `0bb7bf7e-4813-43b2-a1f2-06977bab0946` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between e0629fb56bc100977c5a0d2e62d4e9c28c2526c4 and b529ceee4e787e0290d30258a421c11574a8f6e6. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (4)</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/pipeline/shaders.cpp` * `src/graphics/host_gpu/vulkanCommon.h` * `src/graphics/presentation/window/vulkanWindow.cpp` </dd> </dl> </details> <details> <summary><strong>🚧 Files skipped from review as they are similar to previous changes (2)</strong></summary> <dl> <dd> * src/graphics/host_gpu/vulkanCommon.h * src/graphics/host_gpu/renderer/pipeline/shaders.cpp </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough The change adds helpers to select a push-descriptor limit and determine whether a descriptor layout can use push descriptors. Vulkan initialization queries driver properties and selects the limit using the driver ID and reported device limit. Descriptor-layout creation uses the shared eligibility helper. A standalone test executable covers policy behavior and is registered with CTest and the aggregate test target. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"b529ceee4e787e0290d30258a421c11574a8f6e6" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>b529c</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `b529c` --> <!-- final_review_risk_coverage:{"sourceCommitId":"b529ceee4e787e0290d30258a421c11574a8f6e6","coveredCommitId":"b529ceee4e787e0290d30258a421c11574a8f6e6","kind":"reviewed"} --> MoltenVK avoids the reported push-descriptor issue by using regular descriptor sets, while other drivers retain their reported limit. No concrete merge-blocking risk is established. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- architecture_review_start --> <details> <summary><strong>Security Architecture Review</strong></summary> <dl> <dd> **Security architecture risk:** _🔵 Low_ · up to `bd289` This is a narrowly scoped driver compatibility change with no demonstrated increase in privileges or external access. Residual uncertainty concerns concurrent execution and behavior on actual devices. **Retained concerns** No architecture-level concerns identified. <details> <summary><h4><strong>Security review details</strong></h4></summary> <dl> <dd> **Security Blast Radius** - _inferred_ — The changed binding route applies to graphics and compute pipelines on a selected MoltenVK device, not only the video shader motivating the fix. It increases use of the existing descriptor heap without adding a new descriptor-submission interface. **Trust Boundaries and Controls** - _observed_ — Driver identity and the reported capability come from the selected Vulkan physical device. The policy narrows push-descriptor eligibility and leaves the existing validation-feature setup in place; the changed flow does not introduce a guest-supplied driver identity or privilege transition. **Resilience and Maintainability Implications** - _observed_ — The existing allocator reduces batch size on pool exhaustion or fragmentation and retires exhausted pools with completion ticks. Pool reset requires a completed tick. Normal renderer destruction invokes scheduler shutdown, which submits outstanding commands and waits before descriptor-heap member destruction. These are existing lifecycle controls reused by the newly routed pipelines. </dd> </dl> </details> </dd> </dl> </details> <!-- architecture_review_end --> <!-- 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-v1.svg" width="14" height="17" align="middle" alt="Passed" title="Passed"></picture></sup> 4 | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v1.svg" width="14" height="17" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ 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 identifies the main change: using descriptor sets instead of push descriptors for MoltenVK shader pipelines. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the MoltenVK push-descriptor issue, the policy changes, tests, validation, and known limits. | | 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 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: 1 unsupported.) </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=685)! 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 -->

Pull request closed

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