fix(agc): sample the base level of mipmapped views with unnormalized coordinates #1377

Merged
gjonn merged 2 commits from upstream-pr/1377 into main 2026-10-11 09:17:06 +00:00
gjonn commented 2026-10-08 01:06:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T01:06:50Z.


What

A sampled image used with an unnormalized-coordinate sampler had to be a single-level view starting at mip 0, otherwise binding it threw. A title samples full mip chains this way from compute shaders during start-up: a 10-level 2D view at base level 0, and a 7-level view at base level 3 (a downsample chain).

Vulkan accepts unnormalized samplers only on single-level views, and the hardware samples the view's base level in that mode (the existing test already checks that image_sample_l and sampler LOD bias/clamps do not move it off level 0).

  • Texture keeps the create info for a one-level, one-layer view of the descriptor's base mip (1D, 2D, or the first layer of a 2D array) when the sampled view has more than one level, and creates that view on first use.
  • ShaderResources binds that view for unnormalized samplers instead of throwing. Views with more than one layer, other view types and a minimum LOD clamp still throw.
  • The base-level restriction is dropped: unnormalized coordinates address the view's base mip, which is what the one-level view samples.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, RTX 5090: agc_driver_image_sample_unnormalized passes with two new cases for every sampler and instruction: a full 4-level view samples like a 1-level image, and a 3-level view starting at mip 1 samples mip 1 in mip-1 texel coordinates (mip 1 now holds its own pattern).
  • A title that samples these views no longer aborts on either view and continues to the next start-up issue.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4780388855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1377). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-08T01:06:50Z. --- ### What A sampled image used with an unnormalized-coordinate sampler had to be a single-level view starting at mip 0, otherwise binding it threw. A title samples full mip chains this way from compute shaders during start-up: a 10-level 2D view at base level 0, and a 7-level view at base level 3 (a downsample chain). Vulkan accepts unnormalized samplers only on single-level views, and the hardware samples the view's base level in that mode (the existing test already checks that `image_sample_l` and sampler LOD bias/clamps do not move it off level 0). - `Texture` keeps the create info for a one-level, one-layer view of the descriptor's base mip (1D, 2D, or the first layer of a 2D array) when the sampled view has more than one level, and creates that view on first use. - `ShaderResources` binds that view for unnormalized samplers instead of throwing. Views with more than one layer, other view types and a minimum LOD clamp still throw. - The base-level restriction is dropped: unnormalized coordinates address the view's base mip, which is what the one-level view samples. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, RTX 5090: `agc_driver_image_sample_unnormalized` passes with two new cases for every sampler and instruction: a full 4-level view samples like a 1-level image, and a 3-level view starting at mip 1 samples mip 1 in mip-1 texel coordinates (mip 1 now holds its own pattern). - A title that samples these views no longer aborts on either view and continues to the next start-up issue. ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
adriadam10 commented 2026-10-08 12:39:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T12:39:16Z.

Review: CHANGES_REQUESTED


Measured on RDNA2 hardware (gfx1035 via our HW oracle; 2D T# with 4 levels, BASE_LEVEL 0..3, the same instructions and S# words as this test). Probe: sample_unnormalized_mips.py, happy to share it.

  • image_sample_lz with an S# that has no MIN_LOD/bias does read BASE_LEVEL, with coordinates in that level's texels (0 mismatches over every row, clamp and border modes included). So your one-level base view is exact for that case.
  • It is not exact for the rest. With unnormalized coordinates the hardware still selects a LOD:
    • image_sample_l with LOD 2.7 reads mip 3 (base 0, 1 and 2 alike).
    • image_sample picks the level from the derivatives. Lanes in the same dispatch read mips 0 to 3.
    • The MIN_LOD 1, LOD bias 1.5 sampler moves even image_sample_lz off the base level (base 0 → a blend of mips 1 and 2, base 2 → mip 3).
  • ImageSampleUnnormalized.cpp:248-251 requires the base level for all 3 instructions and all 5 samplers on chain and fromLevelOne. It pins results the hardware doesn't produce. main threw in these cases, and now they return a plausible but wrong value.
  • A possible direction: accept levels > 1 only when the result is exact. That means every sample through the binding is an _lz form (the recompiler would need to flag that next to imageUnnormalized), and the S# has MIN_LOD 0 and no positive bias. Keep throwing otherwise. In the test, check the exact case and use ExpectFailure for the others.
  • Minor: the llvmpipe skip leaves the mip-1 case untested on Linux CI. On RADV it passes here.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5456691002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1377#pullrequestreview-5456691002). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T12:39:16Z. **Review:** CHANGES_REQUESTED --- Measured on RDNA2 hardware (gfx1035 via our HW oracle; 2D T# with 4 levels, BASE_LEVEL 0..3, the same instructions and S# words as this test). Probe: `sample_unnormalized_mips.py`, happy to share it. - `image_sample_lz` with an S# that has no MIN_LOD/bias does read BASE_LEVEL, with coordinates in that level's texels (0 mismatches over every row, clamp and border modes included). So your one-level base view is exact for that case. - It is not exact for the rest. With unnormalized coordinates the hardware still selects a LOD: - `image_sample_l` with LOD 2.7 reads mip 3 (base 0, 1 and 2 alike). - `image_sample` picks the level from the derivatives. Lanes in the same dispatch read mips 0 to 3. - The `MIN_LOD 1, LOD bias 1.5` sampler moves even `image_sample_lz` off the base level (base 0 → a blend of mips 1 and 2, base 2 → mip 3). - `ImageSampleUnnormalized.cpp:248-251` requires the base level for all 3 instructions and all 5 samplers on `chain` and `fromLevelOne`. It pins results the hardware doesn't produce. `main` threw in these cases, and now they return a plausible but wrong value. - A possible direction: accept `levels > 1` only when the result is exact. That means every sample through the binding is an `_lz` form (the recompiler would need to flag that next to `imageUnnormalized`), and the S# has MIN_LOD 0 and no positive bias. Keep throwing otherwise. In the test, check the exact case and use `ExpectFailure` for the others. - Minor: the llvmpipe skip leaves the mip-1 case untested on Linux CI. On RADV it passes here.
fisherjoey commented 2026-10-08 19:12:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:12:54Z.


Linux results, since this was tested on Windows only. Everything passes here.

Nobara 44 (Linux 7.2), GCC 16.2.1, Release, BUILD_TESTING=ON. This PR merged onto main 29e533ac.

main 29e533ac main + this PR
RTX 5070 Ti, driver 595.91.07, ctest -R agc_driver -j1 183 / 183 183 / 183
RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1, same 183 / 183 183 / 183
CPU tests (-E agc_driver) 279 / 280 279 / 280

The CPU failure is guest_dynamic_loader, which fails the same way on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067192545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1377#issuecomment-6067192545). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T19:12:54Z. --- Linux results, since this was tested on Windows only. Everything passes here. Nobara 44 (Linux 7.2), GCC 16.2.1, Release, `BUILD_TESTING=ON`. This PR merged onto `main` 29e533ac. | | `main` 29e533ac | `main` + this PR | |---|---|---| | RTX 5070 Ti, driver 595.91.07, `ctest -R agc_driver -j1` | 183 / 183 | 183 / 183 | | RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1, same | 183 / 183 | 183 / 183 | | CPU tests (`-E agc_driver`) | 279 / 280 | 279 / 280 | The CPU failure is `guest_dynamic_loader`, which fails the same way on `main`.
adriadam10 commented 2026-10-11 09:12:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:12:51Z.

Review: APPROVED


Thanks @fisherjoey for the Linux runs. Checked this on RDNA2 hardware (gfx1035): with unnormalized coordinates the base level is only read by image_sample_lz through an S# without MIN_LOD or LOD bias; image_sample_l, image_sample and biased samples pick other mips on a mipmapped view.

Added on your branch, since it had no push after the review:

  • Rebased onto current main.
  • Multi-level views, and views starting above mip 0, are bound as their base level only when every use of the image is image_sample_lz through an unnormalized S# with MIN_LOD 0 and bias 0 (imageUnnormalizedBaseLevel, proved in DescriptorBindingBuilder; new SamplerUseNonZeroLod use bit). Selected-LOD, implicit-LOD and texel-offset uses keep throwing.
  • Shader disk cache FormatVersion 26 → 27 and the layout checks for the new field and the wider uses.
  • ImageSampleUnnormalized: an image_sample_lz-only program on the 4-level view and on the view from mip 1, and ExpectFailure cases for _l/image_sample, a view from mip 1 with them, texel offsets, and an S# with MIN_LOD and bias. ShaderMemory/ShaderDiskCache cover the new flag.

agc_driver_image_sample_unnormalized, agc_shader_memory and agc_shader_disk_cache pass on RADV; a mutant that accepts _l is caught. The mip 1 case is still skipped on llvmpipe, so CI does not cover it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482707468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1377#pullrequestreview-5482707468). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:12:51Z. **Review:** APPROVED --- Thanks @fisherjoey for the Linux runs. Checked this on RDNA2 hardware (gfx1035): with unnormalized coordinates the base level is only read by `image_sample_lz` through an S# without MIN_LOD or LOD bias; `image_sample_l`, `image_sample` and biased samples pick other mips on a mipmapped view. Added on your branch, since it had no push after the review: - Rebased onto current `main`. - Multi-level views, and views starting above mip 0, are bound as their base level only when every use of the image is `image_sample_lz` through an unnormalized S# with MIN_LOD 0 and bias 0 (`imageUnnormalizedBaseLevel`, proved in `DescriptorBindingBuilder`; new `SamplerUseNonZeroLod` use bit). Selected-LOD, implicit-LOD and texel-offset uses keep throwing. - Shader disk cache `FormatVersion` 26 → 27 and the layout checks for the new field and the wider `uses`. - `ImageSampleUnnormalized`: an `image_sample_lz`-only program on the 4-level view and on the view from mip 1, and `ExpectFailure` cases for `_l`/`image_sample`, a view from mip 1 with them, texel offsets, and an S# with MIN_LOD and bias. `ShaderMemory`/`ShaderDiskCache` cover the new flag. `agc_driver_image_sample_unnormalized`, `agc_shader_memory` and `agc_shader_disk_cache` pass on RADV; a mutant that accepts `_l` is caught. The mip 1 case is still skipped on llvmpipe, so CI does not cover it.
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!1377
No description provided.