docs(agc): measure the rounding of a halfway array layer #16557

Merged
brumskysb merged 1 commit from upstream-pr/16557 into main 2026-11-10 20:31:23 +00:00
brumskysb commented 2026-11-07 05:04:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brumskysb on 2026-11-07T05:04:20Z.


What

Closes the "RDNA's rounding of a halfway layer is unmeasured" clause in the "1D arrays past maxImageArrayLayers" entry.

Measured on gfx1036 (driver 31.0.22044.1): the layer coordinate is an absolute index, and a halfway layer rounds half to even — layers 0.5, 1.5 and 2.5 of a four-slice array select slices 0, 2 and 2. Half-up would give (1, 2, 3) and truncation or half-down would give (0, 1, 2), so those three inputs separate every candidate rule. Integer layers 0-3 read their own slice, and −1.0 and 5.0 clamp to the first and last slice.

That matches the half-to-even rule the entry already attributes to Vulkan's array-layer selection, which the emulation reproduces — the measurement confirms the rule rather than changing it.

Evidence (script, dump, notes): https://gist.github.com/brumskysb/619a3ea0d55a5a19bc3ccad01e45c8f9

Tested

  • GPU: AMD Radeon(TM) Graphics, integrated RDNA2, gfx1036, driver 31.0.22044.1, Windows 11; harness tools/hw-oracle, wave32, 16 lanes per dispatch.
  • 1D-array T#, type 12, width 4, four slices (DEPTH 3), texel values 0x3F000000 + slice*16 + x, sampled with image_sample_lz through a nearest clamp-to-edge S#.
  • Control first: layers 0, 1, 2, 3 read slices 0, 1, 2, 3. Then 0.5, 1.5, 2.5 and the clamps.

Notes

  • The entry is 1,201 characters, over the 1,000 guideline, so the debt-length warning is expected; it was 988 before. Nothing was trimmed, and the "a NaN layer reads slice 0" clause is untouched because no NaN layer was dispatched here.
  • The convention is worth recording because it cost this campaign a wrong conclusion: for a 1D-array T# the layer coordinate is absolute, not normalized, which is visible in the repository's own ImageOneDimensionalArray.cpp (nearbyint then clamp). Sampling at normalized slice centres therefore dispatches layers 0.125/0.375/0.625/0.875, which round half-to-even to 0/0/1/1 and look exactly like an array with two slices. The descriptor was correct; the coordinate was not.

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
  • 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 (attached 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(TM) Graphics (gfx1036, driver 31.0.22044.1, Windows 11)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5198622150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16557). Originally posted by [brumskysb](https://github.com/brumskysb) on 2026-11-07T05:04:20Z. --- ### What Closes the "RDNA's rounding of a halfway layer is unmeasured" clause in the "1D arrays past maxImageArrayLayers" entry. Measured on gfx1036 (driver 31.0.22044.1): the layer coordinate is an **absolute index**, and a halfway layer rounds **half to even** — layers 0.5, 1.5 and 2.5 of a four-slice array select slices **0, 2 and 2**. Half-up would give (1, 2, 3) and truncation or half-down would give (0, 1, 2), so those three inputs separate every candidate rule. Integer layers 0-3 read their own slice, and −1.0 and 5.0 clamp to the first and last slice. That matches the half-to-even rule the entry already attributes to Vulkan's array-layer selection, which the emulation reproduces — the measurement confirms the rule rather than changing it. Evidence (script, dump, notes): https://gist.github.com/brumskysb/619a3ea0d55a5a19bc3ccad01e45c8f9 ### Tested - GPU: AMD Radeon(TM) Graphics, integrated RDNA2, `gfx1036`, driver **31.0.22044.1**, Windows 11; harness `tools/hw-oracle`, wave32, 16 lanes per dispatch. - 1D-array T#, type 12, width 4, four slices (`DEPTH` 3), texel values `0x3F000000 + slice*16 + x`, sampled with `image_sample_lz` through a nearest clamp-to-edge S#. - Control first: layers 0, 1, 2, 3 read slices 0, 1, 2, 3. Then 0.5, 1.5, 2.5 and the clamps. ### Notes - The entry is **1,201 characters**, over the 1,000 guideline, so the `debt-length` warning is expected; it was 988 before. Nothing was trimmed, and the "a NaN layer reads slice 0" clause is untouched because no NaN layer was dispatched here. - The convention is worth recording because it cost this campaign a wrong conclusion: for a 1D-array T# the layer coordinate is **absolute**, not normalized, which is visible in the repository's own `ImageOneDimensionalArray.cpp` (`nearbyint` then clamp). Sampling at normalized slice centres therefore dispatches layers 0.125/0.375/0.625/0.875, which round half-to-even to 0/0/1/1 and look exactly like an array with two slices. The descriptor was correct; the coordinate was not. ### Checklist - [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) - [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 (attached 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(TM) Graphics (gfx1036, driver 31.0.22044.1, Windows 11) - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-10 17:48:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-10T17:48:48Z.

Review: COMMENTED


Read 467eaa9ecb against main.

Correctness. The entry is still current on main (docs/dev/debt/libSceAgcDriver.md:394, "unmeasured"). The behaviour it records matches the code: SpirvImageEmitter.cpp:LayerRowsCoord applies GLSLstd450RoundEven to the layer and then NClamp to [0, rows/2 - 1], so 0.5, 1.5, 2.5 select slices 0, 2, 2 and -1.0 / 5.0 clamp to the first and last slice of a four-slice view, and NClamp returns 0 for a NaN. The code and the measured rounding agree, so the sentence "as Vulkan's array layer selection does" now also holds for the hardware. The measurement itself is not checkable here.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5846648757 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16557#pullrequestreview-5846648757). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-10T17:48:48Z. **Review:** COMMENTED --- Read `467eaa9ecb` against `main`. **Correctness.** The entry is still current on `main` (docs/dev/debt/libSceAgcDriver.md:394, "unmeasured"). The behaviour it records matches the code: `SpirvImageEmitter.cpp:LayerRowsCoord` applies `GLSLstd450RoundEven` to the layer and then `NClamp` to `[0, rows/2 - 1]`, so 0.5, 1.5, 2.5 select slices 0, 2, 2 and -1.0 / 5.0 clamp to the first and last slice of a four-slice view, and `NClamp` returns 0 for a NaN. The code and the measured rounding agree, so the sentence "as Vulkan's array layer selection does" now also holds for the hardware. The measurement itself is not checkable here. Not run here; this is from reading the code. AI-assisted: yes.
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!16557
No description provided.