docs(shader): measure explicit-LOD gather level selection on gfx1036 #23856

Merged
brumskysb merged 1 commit from upstream-pr/23856 into main 2026-11-19 20:31:22 +00:00
brumskysb commented 2026-11-19 19:22:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brumskysb on 2026-11-19T19:22:54Z.


What

Measures the level selection of the [Explicit-LOD gathers] entry of docs/dev/debt/shader.md (added by #12790): "(image_gather4_l, 2D, no offset or depth compare) are emulated, not measured on hardware" and its "Unverified there:" list. No code changes.

Measured on gfx1036 (driver 31.0.22044.1) with the hardware oracle, wave32. Fixture: image_gather4_l DIM 2D through a 2D T# over the surface of ImageGatherLod.cpp (16x16, 5 levels, 8_8_8_8_UNORM, linear, every level's 2x2 footprint distinct so the returned words name the level), T#/S# words from a generator; image_sample_l siblings as controls. 128 LODs per dispatch: -1 to 5 in 1/16 steps, the exact n + 0.5 ties, and probes just below and above them.

  • Controls and mip ladder (step 1, 7 dispatches): v_mov_b32 v10, 0x2a probe 32 of 32; image_load_mip reads each of the 5 levels 32 of 32 (levels stored smallest-first; a largest-first control is 32 of 32 wrong); image_sample_l and image_gather4_l at integer LOD 0..4 each read their own level 32 of 32.
  • LOD sweep (step 2, 8 dispatches, 1,024 lanes): the level changes at exactly n + 0.5 and the tie goes up (0.5 -> 1, 1.5 -> 2, 2.5 -> 3, 3.5 -> 4); probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5 also go up, 1/256 below 0.5 stays at 0. LOD_BIAS (+1.0, -0.5, +0.25) is added before the S# MIN_LOD/MAX_LOD clamps; image_sample_l picks the same level as the gather 128 of 128.
  • Filters and T# MIN_LOD (step 3, 13 dispatches, 1,664 lanes): MIP_FILTER none reads the T# MIN_LOD rounded down (1.75 -> 1, 2.5 -> 2) at every LOD; the T# MIN_LOD is applied after the S# MAX_LOD; linear MIP_FILTER gather returns the same words as point 128 of 128 (the image_sample_l control blends, so the field is live); LOD_BIAS_SEC raw 0x08/0x10/0x30 changes nothing (384 of 384 lanes).
  • Checker (step 4): the entry's rule disagrees with the hardware on 351 of 2,560 lanes, every one at a tie (0 at non-ties); every other listed rule holds, each against an alternative the data rejects (bias after the clamps: 68 lanes off; T# MIN_LOD before S# MAX_LOD: 128). 18 mutation controls fire, no-op silent.
  • Determinism (step 5, 42 dispatches): all 21 sweep dispatches re-run in two fresh windows: 0 of 86,016 words differ from the archive.
  • Independent recount (verify_lod.py, imports neither the fixture nor the checker; rebuilds the surface and asserts its hash, decodes every T#/S# from the bodies, predicts all 16 output words per lane): 0 of 43,008 words off, the 84 linear-blend image_sample_l lanes within 0.074/255; it also rejects MIP_FILTER none rounding the T# MIN_LOD (256 lanes off); 19 mutation controls each fire from that passing baseline. A model that also rounds the LOD to 1/256 first matches every lane; that is a fit to the sub-1/256 probes, not a measured mechanism, and is not written into the entry.

Code reading (not a measurement): the shader rounds with GLSLstd450Ceil of lod + 0.5 minus 1 (core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:1083), so it gathers one level lower than the hardware at an exact tie. This PR records that in the entry and does not change the code.

Evidence (runners, every dump, claims worksheets, checker, verifier, overlap sweeps, SHA-256 ledger): https://gist.github.com/brumskysb/a8b17ad91187303d26c28b05510a6a50

Tested

  • GPU: AMD Radeon(TM) Graphics, integrated RDNA2, gfx1036, driver 31.0.22044.1, Windows 11. Harness: tools/hw-oracle via the campaign's rigio.py (in the gist).
  • Dispatches: 7 + 8 + 13 + 42 = 70. Fixture descriptor: 2D (T# type 9, DIM 2D).
  • Merge check: one commit on aa698cdc08, the main fetched before the edit; it changes only line 307 of docs/dev/debt/shader.md.

The edit removes "not measured on hardware" and the "Unverified there:" lead, keeps the shader's rules verbatim as the description of what the emulation does, and adds one measured sentence after them.

Before:

Explicit-LOD gathers (image_gather4_l, 2D, no offset or depth compare) are emulated, not measured on hardware: no SPIR-V gather takes an LOD without SPV_AMD_texture_gather_bias_lod, so the four footprint texels are fetched at a level chosen in the shader. Unverified there: the LOD plus LOD_BIAS, raised to the S# MIN_LOD, lowered to its MAX_LOD, raised to the T# MIN_LOD above the base level, rounded to the nearest level with ties down (ceil(lod + 0.5) - 1); for MIP_FILTER none, the T# MIN_LOD rounded down; a linear MIP_FILTER taken as nearest; LOD_BIAS_SEC ignored; the mirror-once clamp modes taken as mirror-clamp to edge; coordinates clamped to +-2^24 texels. Images or samplers from a table, the border clamp modes (4, 6), offsets, depth compares, 2D arrays, 3D and cube images, and image_gather4_b still gather the base level; on 1D images image_gather4_l throws.

After:

Explicit-LOD gathers (image_gather4_l, 2D, no offset or depth compare) are emulated: no SPIR-V gather takes an LOD without SPV_AMD_texture_gather_bias_lod, so the four footprint texels are fetched at a level chosen in the shader: the LOD plus LOD_BIAS, raised to the S# MIN_LOD, lowered to its MAX_LOD, raised to the T# MIN_LOD above the base level, rounded to the nearest level with ties down (ceil(lod + 0.5) - 1); for MIP_FILTER none, the T# MIN_LOD rounded down; a linear MIP_FILTER taken as nearest; LOD_BIAS_SEC ignored; the mirror-once clamp modes taken as mirror-clamp to edge; coordinates clamped to +-2^24 texels. Measured on RDNA2 (gfx1036, AMD Windows driver 31.0.22044.1) with the hardware oracle in wave32 at base level 0, the level the hardware gathers from follows these rules except at ties: an LOD of exactly n + 0.5, and probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5, select level n + 1, so the shader's rule picks another level on 351 of 2,560 lanes, all at ties; LOD_BIAS_SEC was checked for three raw values only, and mirror-once, +-2^24, wave64 and the PS5's gfx1013 are not measured. Images or samplers from a table, the border clamp modes (4, 6), offsets, depth compares, 2D arrays, 3D and cube images, and image_gather4_b still gather the base level; on 1D images image_gather4_l throws.

Added sentence:

Measured on RDNA2 (gfx1036, AMD Windows driver 31.0.22044.1) with the hardware oracle in wave32 at base level 0, the level the hardware gathers from follows these rules except at ties: an LOD of exactly n + 0.5, and probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5, select level n + 1, so the shader's rule picks another level on 351 of 2,560 lanes, all at ties; LOD_BIAS_SEC was checked for three raw values only, and mirror-once, +-2^24, wave64 and the PS5's gfx1013 are not measured.

CHANGE SUMMARY (from the gate):

- removed: emulated, not measured on hardware:
- removed: shader. Unverified there:
+ added:   emulated:
+ added:   shader:
+ added:   Measured on RDNA2 (gfx1036, AMD Windows driver 31.0.22044.1) with the hardware oracle in wave32 at base level 0, the level the hardware gathers from follows these rules except at ties: an LOD of exactly n + 0.5, and probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5, select level n + 1, so the shader's rule picks another level on 351 of 2,560 lanes, all at ties; `LOD_BIAS_SEC` was checked for three raw values only, and mirror-once, +-2^24, wave64 and the PS5's gfx1013 are not measured.

Removed phrases declared to the gate: emulated, not measured on hardware:, shader. Unverified there:. "emulated" and "shader" are re-added; "not measured" is re-added for mirror-once, +-2^24, wave64 and the PS5's gfx1013. The sentences on tables, border modes, offsets, compares, arrays, 3D, cube, image_gather4_b and 1D are unchanged.

Notes

  • debt-length: the entry grows from 975 to 1,425 characters, over the 1,000 guideline (CI warning). It was already at 975, and every added clause is a measured condition or a still-unmeasured scope; trimming it is left to a separate PR rather than dropping a condition here.
  • Not covered: mirror-once clamp modes, coordinates near +-2^24, other LOD_BIAS_SEC values, T# base level above 0, other formats and surfaces, wave64, other parts, and the console's gfx1013.
  • Overlap: overlap_sweep.py on aa698cdc08 (2,006 open PRs, 86 candidates, 86 evaluated, 0 hits; controls A/B fire, C silent). No open PR edits this entry.

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:5401455994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23856). Originally posted by [brumskysb](https://github.com/brumskysb) on 2026-11-19T19:22:54Z. --- ### What Measures the level selection of the **[Explicit-LOD gathers]** entry of `docs/dev/debt/shader.md` (added by #12790): "(`image_gather4_l`, 2D, no offset or depth compare) are emulated, not measured on hardware" and its "Unverified there:" list. No code changes. Measured on gfx1036 (driver **31.0.22044.1**) with the hardware oracle, wave32. Fixture: `image_gather4_l` DIM 2D through a 2D T# over the surface of `ImageGatherLod.cpp` (16x16, 5 levels, `8_8_8_8_UNORM`, linear, every level's 2x2 footprint distinct so the returned words name the level), T#/S# words from a generator; `image_sample_l` siblings as controls. 128 LODs per dispatch: -1 to 5 in 1/16 steps, the exact `n + 0.5` ties, and probes just below and above them. - **Controls and mip ladder (step 1, 7 dispatches):** `v_mov_b32 v10, 0x2a` probe 32 of 32; `image_load_mip` reads each of the 5 levels 32 of 32 (levels stored smallest-first; a largest-first control is 32 of 32 wrong); `image_sample_l` and `image_gather4_l` at integer LOD 0..4 each read their own level 32 of 32. - **LOD sweep (step 2, 8 dispatches, 1,024 lanes):** the level changes at exactly `n + 0.5` and the tie goes **up** (0.5 -> 1, 1.5 -> 2, 2.5 -> 3, 3.5 -> 4); probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5 also go up, 1/256 below 0.5 stays at 0. `LOD_BIAS` (+1.0, -0.5, +0.25) is added before the S# `MIN_LOD`/`MAX_LOD` clamps; `image_sample_l` picks the same level as the gather 128 of 128. - **Filters and T# MIN_LOD (step 3, 13 dispatches, 1,664 lanes):** `MIP_FILTER` none reads the T# `MIN_LOD` rounded down (1.75 -> 1, 2.5 -> 2) at every LOD; the T# `MIN_LOD` is applied after the S# `MAX_LOD`; linear `MIP_FILTER` gather returns the same words as point 128 of 128 (the `image_sample_l` control blends, so the field is live); `LOD_BIAS_SEC` raw 0x08/0x10/0x30 changes nothing (384 of 384 lanes). - **Checker (step 4):** the entry's rule disagrees with the hardware on **351 of 2,560** lanes, every one at a tie (0 at non-ties); every other listed rule holds, each against an alternative the data rejects (bias after the clamps: 68 lanes off; T# `MIN_LOD` before S# `MAX_LOD`: 128). 18 mutation controls fire, no-op silent. - **Determinism (step 5, 42 dispatches):** all 21 sweep dispatches re-run in two fresh windows: 0 of 86,016 words differ from the archive. - **Independent recount** (`verify_lod.py`, imports neither the fixture nor the checker; rebuilds the surface and asserts its hash, decodes every T#/S# from the bodies, predicts all 16 output words per lane): 0 of 43,008 words off, the 84 linear-blend `image_sample_l` lanes within 0.074/255; it also rejects `MIP_FILTER` none rounding the T# `MIN_LOD` (256 lanes off); 19 mutation controls each fire from that passing baseline. A model that also rounds the LOD to 1/256 first matches every lane; that is a fit to the sub-1/256 probes, not a measured mechanism, and is not written into the entry. Code reading (not a measurement): the shader rounds with `GLSLstd450Ceil` of `lod + 0.5` minus 1 (`core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:1083`), so it gathers one level lower than the hardware at an exact tie. This PR records that in the entry and does not change the code. Evidence (runners, every dump, claims worksheets, checker, verifier, overlap sweeps, SHA-256 ledger): https://gist.github.com/brumskysb/a8b17ad91187303d26c28b05510a6a50 ### Tested - GPU: AMD Radeon(TM) Graphics, integrated RDNA2, `gfx1036`, driver **31.0.22044.1**, Windows 11. Harness: `tools/hw-oracle` via the campaign's `rigio.py` (in the gist). - Dispatches: 7 + 8 + 13 + 42 = 70. Fixture descriptor: 2D (T# type 9, DIM 2D). - Merge check: one commit on `aa698cdc08`, the `main` fetched before the edit; it changes only line 307 of `docs/dev/debt/shader.md`. The edit removes "not measured on hardware" and the "Unverified there:" lead, keeps the shader's rules verbatim as the description of what the emulation does, and adds one measured sentence after them. Before: > [Explicit-LOD gathers](../../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) (`image_gather4_l`, 2D, no offset or depth compare) are emulated, not measured on hardware: no SPIR-V gather takes an LOD without `SPV_AMD_texture_gather_bias_lod`, so the four footprint texels are fetched at a level chosen in the shader. Unverified there: the LOD plus `LOD_BIAS`, raised to the S# `MIN_LOD`, lowered to its `MAX_LOD`, raised to the T# `MIN_LOD` above the base level, rounded to the nearest level with ties down (`ceil(lod + 0.5) - 1`); for `MIP_FILTER` none, the T# `MIN_LOD` rounded down; a linear `MIP_FILTER` taken as nearest; `LOD_BIAS_SEC` ignored; the mirror-once clamp modes taken as mirror-clamp to edge; coordinates clamped to +-2^24 texels. Images or samplers from a table, the border clamp modes (4, 6), offsets, depth compares, 2D arrays, 3D and cube images, and `image_gather4_b` still gather the base level; on 1D images `image_gather4_l` throws. After: > [Explicit-LOD gathers](../../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) (`image_gather4_l`, 2D, no offset or depth compare) are emulated: no SPIR-V gather takes an LOD without `SPV_AMD_texture_gather_bias_lod`, so the four footprint texels are fetched at a level chosen in the shader: the LOD plus `LOD_BIAS`, raised to the S# `MIN_LOD`, lowered to its `MAX_LOD`, raised to the T# `MIN_LOD` above the base level, rounded to the nearest level with ties down (`ceil(lod + 0.5) - 1`); for `MIP_FILTER` none, the T# `MIN_LOD` rounded down; a linear `MIP_FILTER` taken as nearest; `LOD_BIAS_SEC` ignored; the mirror-once clamp modes taken as mirror-clamp to edge; coordinates clamped to +-2^24 texels. Measured on RDNA2 (gfx1036, AMD Windows driver 31.0.22044.1) with the hardware oracle in wave32 at base level 0, the level the hardware gathers from follows these rules except at ties: an LOD of exactly n + 0.5, and probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5, select level n + 1, so the shader's rule picks another level on 351 of 2,560 lanes, all at ties; `LOD_BIAS_SEC` was checked for three raw values only, and mirror-once, +-2^24, wave64 and the PS5's gfx1013 are not measured. Images or samplers from a table, the border clamp modes (4, 6), offsets, depth compares, 2D arrays, 3D and cube images, and `image_gather4_b` still gather the base level; on 1D images `image_gather4_l` throws. Added sentence: > Measured on RDNA2 (gfx1036, AMD Windows driver 31.0.22044.1) with the hardware oracle in wave32 at base level 0, the level the hardware gathers from follows these rules except at ties: an LOD of exactly n + 0.5, and probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5, select level n + 1, so the shader's rule picks another level on 351 of 2,560 lanes, all at ties; `LOD_BIAS_SEC` was checked for three raw values only, and mirror-once, +-2^24, wave64 and the PS5's gfx1013 are not measured. CHANGE SUMMARY (from the gate): ``` - removed: emulated, not measured on hardware: - removed: shader. Unverified there: + added: emulated: + added: shader: + added: Measured on RDNA2 (gfx1036, AMD Windows driver 31.0.22044.1) with the hardware oracle in wave32 at base level 0, the level the hardware gathers from follows these rules except at ties: an LOD of exactly n + 0.5, and probes 1/4096 to 1/512 below 0.5 and 1/1024 below 1.5, select level n + 1, so the shader's rule picks another level on 351 of 2,560 lanes, all at ties; `LOD_BIAS_SEC` was checked for three raw values only, and mirror-once, +-2^24, wave64 and the PS5's gfx1013 are not measured. ``` Removed phrases declared to the gate: `emulated, not measured on hardware:`, `shader. Unverified there:`. "emulated" and "shader" are re-added; "not measured" is re-added for mirror-once, +-2^24, wave64 and the PS5's gfx1013. The sentences on tables, border modes, offsets, compares, arrays, 3D, cube, `image_gather4_b` and 1D are unchanged. ### Notes - `debt-length`: the entry grows from 975 to 1,425 characters, over the 1,000 guideline (CI warning). It was already at 975, and every added clause is a measured condition or a still-unmeasured scope; trimming it is left to a separate PR rather than dropping a condition here. - Not covered: mirror-once clamp modes, coordinates near +-2^24, other `LOD_BIAS_SEC` values, T# base level above 0, other formats and surfaces, wave64, other parts, and the console's gfx1013. - Overlap: `overlap_sweep.py` on `aa698cdc08` (2,006 open PRs, 86 candidates, 86 evaluated, 0 hits; controls A/B fire, C silent). No open PR edits this entry. ### 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
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!23856
No description provided.