fix(agc): read 16-sample FMASK across every storage width #15948

Merged
HabibUrRehmanBhattii merged 9 commits from upstream-pr/15948 into main 2026-11-25 09:22:20 +00:00
HabibUrRehmanBhattii commented 2026-11-05 02:17:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HabibUrRehmanBhattii on 2026-11-05T02:17:46Z.


What

Reads the four 16-sample FMASK layouts through the measured PS5 gfx1013 expansion, and corrects the expansion rule for the existing shorter layouts:

  • Fmask16_S16_F1 (162, 16-bit storage), Fmask32_S16_F2 (164, 32-bit), Fmask64_S16_F4 (167, 64-bit) and Fmask64_S16_F8 (168, 64-bit), with R16_UINT/R32_UINT/R32G32_UINT snapshots and two-dword expansion (samples 0-7 and 8-15).
  • Identity selectors X/Y/Z/W = 4/5/6/7 read both dwords and repeat the low/high pair in Z/W, matching hardware.
  • Measured expansion rule: the stored field is a fragment index in its low log2(fragments) bits plus an unknown flag in the next bit; an unknown flag reads 8 + index, higher field bits are ignored, and samples past the count read 0.
  • Short expansions (2- and 4-sample layouts) repeat their nibble pattern across the 32-bit result; eight-sample results are already 32 bits.

Hardware oracle: 162/164/167/168 on 13.60 and 11.60 (167 also matches on 11.60); every remaining <=8-sample format 156-166 on 13.60 with the guest-style selector, plus 157/159/160/163 repeated on 11.60. All measured outputs match the rule, including the short-expansion replication. Fmask32_S8_F8 keeps its stored-word path. The raw-ISA probe uses mapped stage memory and explicit flushes; the static-array version was the reason earlier probes hung.

The FMASK gap was tracked by issue #3219; merged PR #8429 stopped at 8 samples. No open PR implements these four formats. Only docs/dev/debt/shader.md records the remaining CMASK/packed/selector boundaries.

Tested

Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 4070 (driver 616.92), MinGW GCC 15.2.0, CMake 4.4.4:

  • Branch rebased on current main 1882108b45.
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V:
    • agc_driver_fmask_image_reads: Passed, 136 dispatches / 17408 component checks / 8 compression refusals (main: 104 dispatches).
    • agc_driver_native_fmask: Passed.
    • agc_shader_memory: Passed.
    • Both logs: no was not found but was requested by env var VK_INSTANCE_LAYERS, no new VUID- (0 lines).
  • PS5 hardware: all <=8-sample formats 156-166 measured on 13.60, with 157/159/160/163 repeated on 11.60; 162/164/167/168 measured on both consoles. All measured outputs match the implemented rule.
  • Linux cross-platform: GCC 16.2.1 / CMake 4.4.5 full configure and focused targets build; agc_shader_memory Passed; FMASK GPU test skipped (no Vulkan ICD/lavapipe on that host).
  • python3 tools/check_conventions.py --base origin/main: 0 errors (one pre-existing debt-length warning).
  • python3 tools/pr_overlap.py --branch feat/fmask-16-sample-current: lists open PRs touching the shared debt/emitter/test files; none implement the same FMASK formats. Compare the overlap list before merge.

Checklist

  • Based on current main; no other open PR implements the same functions — #8429 stops at 8 samples; issue #3219 tracks the remaining gap; no open PR implements 162/164/167/168
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file — unchanged
  • No notes, investigation .md files or images added to the repository — only code, tests and the existing debt entry changed; the measurement notes/logs stay attached outside the repository
  • New third-party code is a submodule built from source — none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070, driver 616.92, Windows 11 Home 10.0.26200 (AGC and shader recompiler); PS5 gfx1013 firmware 13.60 and 11.60 used as the hardware oracle
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5164957537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15948). Originally posted by [HabibUrRehmanBhattii](https://github.com/HabibUrRehmanBhattii) on 2026-11-05T02:17:46Z. --- ### What Reads the four 16-sample FMASK layouts through the measured PS5 gfx1013 expansion, and corrects the expansion rule for the existing shorter layouts: - `Fmask16_S16_F1` (162, 16-bit storage), `Fmask32_S16_F2` (164, 32-bit), `Fmask64_S16_F4` (167, 64-bit) and `Fmask64_S16_F8` (168, 64-bit), with `R16_UINT`/`R32_UINT`/`R32G32_UINT` snapshots and two-dword expansion (samples 0-7 and 8-15). - Identity selectors X/Y/Z/W = 4/5/6/7 read both dwords and repeat the low/high pair in Z/W, matching hardware. - Measured expansion rule: the stored field is a fragment index in its low `log2(fragments)` bits plus an unknown flag in the next bit; an unknown flag reads `8 + index`, higher field bits are ignored, and samples past the count read 0. - Short expansions (2- and 4-sample layouts) repeat their nibble pattern across the 32-bit result; eight-sample results are already 32 bits. Hardware oracle: 162/164/167/168 on 13.60 and 11.60 (167 also matches on 11.60); every remaining <=8-sample format 156-166 on 13.60 with the guest-style selector, plus 157/159/160/163 repeated on 11.60. All measured outputs match the rule, including the short-expansion replication. `Fmask32_S8_F8` keeps its stored-word path. The raw-ISA probe uses mapped stage memory and explicit flushes; the static-array version was the reason earlier probes hung. The FMASK gap was tracked by issue #3219; merged PR #8429 stopped at 8 samples. No open PR implements these four formats. Only `docs/dev/debt/shader.md` records the remaining CMASK/packed/selector boundaries. ### Tested Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 4070 (driver 616.92), MinGW GCC 15.2.0, CMake 4.4.4: - Branch rebased on current `main` `1882108b45`. - `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V`: - `agc_driver_fmask_image_reads`: **Passed**, 136 dispatches / 17408 component checks / 8 compression refusals (main: 104 dispatches). - `agc_driver_native_fmask`: **Passed**. - `agc_shader_memory`: **Passed**. - Both logs: no `was not found but was requested by env var VK_INSTANCE_LAYERS`, no new `VUID-` (0 lines). - PS5 hardware: all <=8-sample formats 156-166 measured on 13.60, with 157/159/160/163 repeated on 11.60; 162/164/167/168 measured on both consoles. All measured outputs match the implemented rule. - Linux cross-platform: GCC 16.2.1 / CMake 4.4.5 full configure and focused targets build; `agc_shader_memory` **Passed**; FMASK GPU test skipped (no Vulkan ICD/lavapipe on that host). - `python3 tools/check_conventions.py --base origin/main`: 0 errors (one pre-existing debt-length warning). - `python3 tools/pr_overlap.py --branch feat/fmask-16-sample-current`: lists open PRs touching the shared debt/emitter/test files; none implement the same FMASK formats. Compare the overlap list before merge. ### 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 — #8429 stops at 8 samples; issue #3219 tracks the remaining gap; no open PR implements 162/164/167/168 - [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) - [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 — unchanged - [x] No notes, investigation `.md` files or images added to the repository — only code, tests and the existing debt entry changed; the measurement notes/logs stay attached outside the repository - [x] New third-party code is a submodule built from source — none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070, driver 616.92, Windows 11 Home 10.0.26200 (AGC and shader recompiler); PS5 gfx1013 firmware 13.60 and 11.60 used as the hardware oracle - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 11:11:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:11:23Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the available evidence supports merging.

What I ran

Inspected the prepared diff and targeted repository context at head 04c25d77f4ad52b45afc91247364d889524d96d4. No commands or tests were run; the test results below are author-reported.

Results

Check Result Note
Diff and implementation review passed Changed behavior and key callers inspected
Author-reported checks not run Windows and Linux tests were not run in this review

Findings

Blocking

None.

Non-blocking

None.

Not verified

core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp was excluded from the prepared review files because it is too large. Its changed function was inspected through repo_read.py at the pinned head, but the rest of that file was not read. The supplied description.md reports Windows Vulkan tests, Linux focused build/test, convention checks, and PS5 hardware measurements; those results were not independently verified. No merged-preview check or negative control was run. All other changed files listed in manifest.json were read; the only changed file excluded from the prepared files was tests/ShaderMemory.cpp.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5991751192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15948#pullrequestreview-5991751192). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T11:11:23Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the available evidence supports merging. ## What I ran Inspected the prepared diff and targeted repository context at head `04c25d77f4ad52b45afc91247364d889524d96d4`. No commands or tests were run; the test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and implementation review | passed | Changed behavior and key callers inspected | | Author-reported checks | not run | Windows and Linux tests were not run in this review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` was excluded from the prepared review files because it is too large. Its changed function was inspected through `repo_read.py` at the pinned head, but the rest of that file was not read. The supplied `description.md` reports Windows Vulkan tests, Linux focused build/test, convention checks, and PS5 hardware measurements; those results were not independently verified. No merged-preview check or negative control was run. All other changed files listed in `manifest.json` were read; the only changed file excluded from the prepared files was `tests/ShaderMemory.cpp`. ## 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!15948
No description provided.