perf(shader): convert runtime-format buffer components at their run-time width #20251

Merged
Remi-Bon merged 2 commits from upstream-pr/20251 into main 2026-11-26 10:40:21 +00:00
Remi-Bon commented 2026-11-14 22:41:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Remi-Bon on 2026-11-14T22:41:40Z.


What

The component loop of genericFormattedLoad (from #21973) converts each component once per (type, bit width) pair found in the format table, then selects the matching result.
Unorm, snorm, scaled and integer components now take the component width at run time (NormalizeFormatComponentWidth), so one conversion per type remains. Float and d16 conversions keep one per width.
Rebased on main after #21973 landed: the component loop this PR first added is dropped, only the run-time-width conversion is kept.

Tested

Windows 11, AMD Radeon RX 9070. No title was run for this PR.

  • Format, buffer and tbuffer tests, ctest -R "format|formatted|gpu_buffer|tbuffer|buffer_load" -V under ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer: 37/37 on main (6c70b74203) and on this change, no VUID- in either log, loader inserts the validation layer in both.
  • SPIR-V size from agc_formatted_buffer_once on main and on this change: GPU-selected formatted load 10380 to 8891 words (three loads: 11114 to 9621); one load 3975 to 2322, three 4477 to 2824; pixel shader specialized 4774 to 3137, registration 5403 to 3770.
    No pipeline build time or frame time is claimed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070, driver 32.0.32029.2010, Windows 11 Pro 26300
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5316953462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20251). Originally posted by [Remi-Bon](https://github.com/Remi-Bon) on 2026-11-14T22:41:40Z. --- ### What The component loop of `genericFormattedLoad` (from #21973) converts each component once per (type, bit width) pair found in the format table, then selects the matching result. Unorm, snorm, scaled and integer components now take the component width at run time (`NormalizeFormatComponentWidth`), so one conversion per type remains. Float and d16 conversions keep one per width. Rebased on `main` after #21973 landed: the component loop this PR first added is dropped, only the run-time-width conversion is kept. ### Tested Windows 11, AMD Radeon RX 9070. No title was run for this PR. - Format, buffer and `tbuffer` tests, `ctest -R "format|formatted|gpu_buffer|tbuffer|buffer_load" -V` under `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer`: 37/37 on `main` (6c70b74203) and on this change, no `VUID-` in either log, loader inserts the validation layer in both. - SPIR-V size from `agc_formatted_buffer_once` on `main` and on this change: GPU-selected formatted load 10380 to 8891 words (three loads: 11114 to 9621); one load 3975 to 2322, three 4477 to 2824; pixel shader specialized 4774 to 3137, registration 5403 to 3770. No pipeline build time or frame time is claimed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 9070, driver 32.0.32029.2010, Windows 11 Pro 26300 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 23:32:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T23:32:04Z.

Review: COMMENTED


Reviewed — no blocking findings

The available diff and source support the stated loop refactor, but the review is incomplete because the exposed reader did not provide access to every required repository file.

What I ran

  • Reviewed head 221e5088130b76d86a47d80735e03decda65cf60; no build or tests were run.
  • Read description.md, commits.md, manifest.json, diff.patch, SpirvFormatConvert.hpp, SpirvFormatConvert.cpp (all 448 lines), and SpirvRuntimeBuffer.cpp lines 620–780. The prepared bundle lists four changed files, all marked included; I read three. files.json was not available through the exposed reader.

Results

Check Result Note
Diff and stated goal passed Matches the dynamic component loop refactor
Targeted source review not run Reader access limited full verification
Build and tests not run No commands were run

Findings

Blocking

None identified in the code inspected.

Non-blocking

None.

Not verified

  • SpirvEmitterHelpers.hpp was not read; its full text is marked included in the manifest.
  • Callers and tests for NormalizeFormatComponentWidth were not inspected. Repository search was unavailable through the exposed reader.
  • The author reports Windows 11 / AMD RX 9070 test and SPIR-V size results in the description; these were not independently run or verified.
  • No statement is made about uninspected code or files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6000792609 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20251#pullrequestreview-6000792609). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T23:32:04Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The available diff and source support the stated loop refactor, but the review is incomplete because the exposed reader did not provide access to every required repository file. ## What I ran - Reviewed head `221e5088130b76d86a47d80735e03decda65cf60`; no build or tests were run. - Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `SpirvFormatConvert.hpp`, `SpirvFormatConvert.cpp` (all 448 lines), and `SpirvRuntimeBuffer.cpp` lines 620–780. The prepared bundle lists four changed files, all marked included; I read three. `files.json` was not available through the exposed reader. ## Results | Check | Result | Note | |---|---|---| | Diff and stated goal | passed | Matches the dynamic component loop refactor | | Targeted source review | not run | Reader access limited full verification | | Build and tests | not run | No commands were run | ## Findings ### Blocking None identified in the code inspected. ### Non-blocking None. ## Not verified - `SpirvEmitterHelpers.hpp` was not read; its full text is marked included in the manifest. - Callers and tests for `NormalizeFormatComponentWidth` were not inspected. Repository search was unavailable through the exposed reader. - The author reports Windows 11 / AMD RX 9070 test and SPIR-V size results in the description; these were not independently run or verified. - No statement is made about uninspected code or files. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-22 10:35:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T10:35:13Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: correct the signed normalized conversion so it preserves the SNORM sign and scale.

What I ran

Reviewed head 3aec2e2fa304b70ab81a4871857378b736903cef. I read the prepared description, commit summary, manifest, diff, and all four changed files listed as reviewed. I did not run commands or tests; repo_read.py was used for targeted source reads.

Results

Check Result Note
Source review failed SNORM conversion has a concrete correctness defect
Tests not run No tests run during this review
Build not run No build run during this review

Findings

Blocking

  • core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvFormatConvert.cpp:83 — The SNORM path ORs the sign bit into the result of the new width-based UNORM conversion. UnormWidthToF32Bits returns an IEEE-754 bit pattern, whose sign bit is bit 31; this sets the result negative for negative SNORM values, but it never divides the magnitude by the SNORM positive maximum. For example, an 8-bit SNORM value of -64 is emitted as -64.0 rather than approximately -0.504. The existing NormalizeFormatComponent path at this file's lines 159–166 uses the SNORM maximum and should be preserved in the runtime-width path.

Non-blocking

None.

Not verified

No tests, build, or runtime checks were performed. The author-reported Windows 11 / AMD Radeon RX 9070 runs and measurements were not independently verified. files.json was not available through the review reader; the manifest lists four changed files, and all four full texts were read. No files were excluded in the manifest.

To get this to a good state

Correct runtime-width SNORM conversion to produce the same normalized values as the existing fixed-width path, then run the focused format and formatted buffer tests on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011773636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20251#pullrequestreview-6011773636). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T10:35:13Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: correct the signed normalized conversion so it preserves the SNORM sign and scale. ## What I ran Reviewed head `3aec2e2fa304b70ab81a4871857378b736903cef`. I read the prepared description, commit summary, manifest, diff, and all four changed files listed as reviewed. I did not run commands or tests; `repo_read.py` was used for targeted source reads. ## Results | Check | Result | Note | |---|---|---| | Source review | failed | SNORM conversion has a concrete correctness defect | | Tests | not run | No tests run during this review | | Build | not run | No build run during this review | ## Findings ### Blocking - `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvFormatConvert.cpp:83` — The SNORM path ORs the sign bit into the result of the new width-based UNORM conversion. `UnormWidthToF32Bits` returns an IEEE-754 bit pattern, whose sign bit is bit 31; this sets the result negative for negative SNORM values, but it never divides the magnitude by the SNORM positive maximum. For example, an 8-bit SNORM value of -64 is emitted as -64.0 rather than approximately -0.504. The existing `NormalizeFormatComponent` path at this file's lines 159–166 uses the SNORM maximum and should be preserved in the runtime-width path. ### Non-blocking None. ## Not verified No tests, build, or runtime checks were performed. The author-reported Windows 11 / AMD Radeon RX 9070 runs and measurements were not independently verified. `files.json` was not available through the review reader; the manifest lists four changed files, and all four full texts were read. No files were excluded in the manifest. ## To get this to a good state Correct runtime-width SNORM conversion to produce the same normalized values as the existing fixed-width path, then run the focused format and formatted buffer tests on the updated head.
MarcZX10 commented 2026-11-25 17:19:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T17:19:36Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed change adds run-time-width conversions for formatted buffer components and a focused SNORM case; no concrete defect was identified in the code read.

What I ran

Reviewed head 7d2c4bcc0dc9169cdf63a4be8fcc147244ff0aea. No commands or tests were run; this review session provided read-only review tools rather than a shell.

Results

Check Result Note
Diff and changed lines passed All five changed files read
Targeted conversion and caller context passed Runtime format conversion path read
Tests not run No execution environment available

Findings

Blocking

None identified.

Non-blocking

None.

Not verified

Tests, builds, runtime behavior, and the author-reported performance measurements were not independently verified. No changed files were excluded; files.json was unavailable through the review reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6061945956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20251#pullrequestreview-6061945956). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T17:19:36Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed change adds run-time-width conversions for formatted buffer components and a focused SNORM case; no concrete defect was identified in the code read. ## What I ran Reviewed head `7d2c4bcc0dc9169cdf63a4be8fcc147244ff0aea`. No commands or tests were run; this review session provided read-only review tools rather than a shell. ## Results | Check | Result | Note | |---|---|---| | Diff and changed lines | passed | All five changed files read | | Targeted conversion and caller context | passed | Runtime format conversion path read | | Tests | not run | No execution environment available | ## Findings ### Blocking None identified. ### Non-blocking None. ## Not verified Tests, builds, runtime behavior, and the author-reported performance measurements were not independently verified. No changed files were excluded; `files.json` was unavailable through the review reader. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!20251
No description provided.