Validate SGPR ranges for vertex table and add regression tests #2301

Open
github-bot wants to merge 2 commits from github-bot/gh-2301 into main AGit
Owner

@⁠msawe354 on GitHub · 2026-11-16 15:22 UTC · original
msawe354:main → main · +22 −7 · 2 files · 2 commits · open

This pull request improves the robustness of vertex input handling in the shader system by adding stricter validation for vertex table pointers and enhancing the related tests. The changes ensure that invalid register assignments are detected and rejected, improving stability and correctness.

Validation improvements in shader code:

  • Added checks in ShaderGetStaticVertexInputInfo (in shader.cpp) to ensure vertex_buffer_reg and vertex_attrib_reg are within valid SGPR (Scalar General Purpose Register) bounds, logging an error and returning false if they exceed limits.

Test improvements:

  • Updated CheckRejected in ShaderVertexMetadataTests.cpp to accept a configurable max_user_sgprs parameter, allowing more flexible testing of SGPR limits.
  • Modified test cases to use boundary SGPR values (e.g., 31 instead of 63) and to pass the correct max_user_sgprs value, ensuring the new validation logic is properly exercised.
  • Added missing include for hardwareContext.h in the test file to support the new test logic.
**@⁠msawe354** on GitHub · 2026-11-16 15:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2301) `msawe354:main` → `main` · +22 −7 · 2 files · 2 commits · open This pull request improves the robustness of vertex input handling in the shader system by adding stricter validation for vertex table pointers and enhancing the related tests. The changes ensure that invalid register assignments are detected and rejected, improving stability and correctness. Validation improvements in shader code: * Added checks in `ShaderGetStaticVertexInputInfo` (in `shader.cpp`) to ensure `vertex_buffer_reg` and `vertex_attrib_reg` are within valid SGPR (Scalar General Purpose Register) bounds, logging an error and returning `false` if they exceed limits. Test improvements: * Updated `CheckRejected` in `ShaderVertexMetadataTests.cpp` to accept a configurable `max_user_sgprs` parameter, allowing more flexible testing of SGPR limits. * Modified test cases to use boundary SGPR values (e.g., 31 instead of 63) and to pass the correct `max_user_sgprs` value, ensuring the new validation logic is properly exercised. * Added missing include for `hardwareContext.h` in the test file to support the new test logic.
Reject inconsistent shader metadata before reading vertex table pointers and add regression coverage.\n\nCo-authored-by: Copilot <[email protected]>
graphics: validate vertex table SGPR ranges
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:20 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 15:28 UTC · original

Explain Change →

Walkthrough

ShaderGetStaticVertexInputInfo now checks dynamic vertex-table SGPR indices before reading pointer data. It logs an error and returns false if the buffer register is missing, the user SGPR count exceeds SGPRS_MAX, or either two-word pointer register exceeds the available count. The tests now pass a configurable SGPR count and check rejection at offset 31.

Estimated code review effort:

Suggested reviewers: nmzik, mrbigbritches

Change: Bug fix

Merge Risk: Low · up to 5a34e

The change adds a check that rejects inconsistent vertex-table SGPR metadata before pointers are read. The updated tests exercise only the metadata reader's existing capacity check, so a regression in the new check would not be caught. It is safe to merge, and adding a test that reaches the new guard would be a worthwhile follow-up.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: adding SGPR range validation for the vertex table in ShaderGetStaticVertexInputInfo, plus regression tests. The raw summary confirms the shader.cpp validation and the …
Description check Passed The description states the SGPR bound checks added to ShaderGetStaticVertexInputInfo, the configurable max_user_sgprs parameter for CheckRejected, the boundary-value test changes, and the hardwareCont…
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: Title check

Explanation

The title names the main change: adding SGPR range validation for the vertex table in ShaderGetStaticVertexInputInfo, plus regression tests. The raw summary confirms the shader.cpp validation and the ShaderVertexMetadataTests.cpp updates. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description states the SGPR bound checks added to ShaderGetStaticVertexInputInfo, the configurable max_user_sgprs parameter for CheckRejected, the boundary-value test changes, and the hardwareContext.h include. These match the raw summary and the changed files, so the description is related to the changeset.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 15:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2301#issuecomment-6920778017) <!-- coderabbit-ai-generated:v1 --> <!-- 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/2301?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-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> ShaderGetStaticVertexInputInfo now checks dynamic vertex-table SGPR indices before reading pointer data. It logs an error and returns false if the buffer register is missing, the user SGPR count exceeds SGPRS_MAX, or either two-word pointer register exceeds the available count. The tests now pass a configurable SGPR count and check rejection at offset 31. <!-- change_assessment_start --> **Estimated code review effort:** **Suggested reviewers:** `nmzik`, `mrbigbritches` <!-- change_assessment_commit:"5a34ed7ddf1118e2ac2e812bbd7257bebfe979b9" --> <!-- change_assessment_priority:{"version":1,"urgency":"p3","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> </dd> </dl> </details> <!-- walkthrough_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · up to <code>5a34e</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `5a34e` --> <!-- final_review_risk_coverage:{"sourceCommitId":"5a34ed7ddf1118e2ac2e812bbd7257bebfe979b9","coveredCommitId":"5a34ed7ddf1118e2ac2e812bbd7257bebfe979b9","kind":"reviewed"} --> The change adds a check that rejects inconsistent vertex-table SGPR metadata before pointers are read. The updated tests exercise only the metadata reader's existing capacity check, so a regression in the new check would not be caught. It is safe to merge, and adding a test that reaches the new guard would be a worthwhile follow-up. <!-- 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</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the main change: adding SGPR range validation for the vertex table in ShaderGetStaticVertexInputInfo, plus regression tests. The raw summary confirms the shader.cpp validation and the … | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states the SGPR bound checks added to ShaderGetStaticVertexInputInfo, the configurable max_user_sgprs parameter for CheckRejected, the boundary-value test changes, and the hardwareCont… | | 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. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the main change: adding SGPR range validation for the vertex table in ShaderGetStaticVertexInputInfo, plus regression tests. The raw summary confirms the shader.cpp validation and the ShaderVertexMetadataTests.cpp updates. The title is specific and matches the changeset. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states the SGPR bound checks added to ShaderGetStaticVertexInputInfo, the configurable max_user_sgprs parameter for CheckRejected, the boundary-value test changes, and the hardwareContext.h include. These match the raw summary and the changed files, so the description is related to the changeset. </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=2301)! 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> <br> - [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> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 15:28 UTC · original · reviewed

Nitpick comments: 1

tests/ShaderVertexMetadataTests.cpp: 1

95-98: Trivial · Maintainability & Code Quality · Quick win

Add coverage for the new stage-specific bound.

These cases call ShaderReadVertexMetadata, which already rejects offset 31 with a limit of 32. They still pass if the new production guard is removed.

Add focused coverage through the production entrypoint or a shared validation helper. With buffer offset 2 and attrib offset 4, check rejection at count 5 and acceptance at count 6. Also cover count 33 and offset 30 with count 32. This distinguishes the new stage bound from the reader's existing capacity check.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 41e2147c07 and 5a34ed7ddf.

Files selected for processing: 2

  • src/graphics/shader/shader.cpp
  • tests/ShaderVertexMetadataTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 15:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2301#pullrequestreview-5922572018) · **reviewed** <!-- coderabbit-ai-generated:v1 --> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning.svg" width="16" height="16" align="absmiddle" alt=""></picture> Nitpick comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>tests/ShaderVertexMetadataTests.cpp: 1</summary><blockquote> <dl> <dd> <br> `95-98`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/neutral-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Trivial** · **Maintainability & Code Quality** · **Quick win** **Add coverage for the new stage-specific bound.** These cases call `ShaderReadVertexMetadata`, which already rejects offset 31 with a limit of 32. They still pass if the new production guard is removed. Add focused coverage through the production entrypoint or a shared validation helper. With buffer offset 2 and attrib offset 4, check rejection at count 5 and acceptance at count 6. Also cover count 33 and offset 30 with count 32. This distinguishes the new stage bound from the reader's existing capacity check. <!-- cr-comment:v1:dd8e0ab959a7daad63a65782 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/41e2147c07bcc6d2206cb2b84e4646497896a18e/.coderabbit.yaml>) - **Commit**: [41e2147](<https://github.com/KytyPS5/KytyPS5/commit/41e2147c07bcc6d2206cb2b84e4646497896a18e>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `14dbecc2-d572-4eda-a466-7ba12e83c5e0` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 41e2147c07bcc6d2206cb2b84e4646497896a18e and 5a34ed7ddf1118e2ac2e812bbd7257bebfe979b9. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</summary> <dl> <dd> <br> * `src/graphics/shader/shader.cpp` * `tests/ShaderVertexMetadataTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=93b0c979-7827-404a-a8af-dcf8b2a843b5 attempt=e2069544-db2e-427e-a82c-127e7dcd35b6 batch=1/1 -->
This pull request has changes conflicting with the target branch.
  • tests/ShaderVertexMetadataTests.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2301/head:github-bot/gh-2301'
git switch 'github-bot/gh-2301'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2301'
git switch 'github-bot/gh-2301'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2301'
git switch 'github-bot/gh-2301'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2301'
git switch 'main'
git merge --squash 'github-bot/gh-2301'
git switch 'main'
git merge --ff-only 'github-bot/gh-2301'
git switch 'main'
git merge 'github-bot/gh-2301'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.