feat(agc): implement unnormalized sampler coordinates on single-level 1D and 2D views #799

Merged
Celegans12 merged 1 commit from upstream-pr/799 into main 2026-10-07 06:50:17 +00:00
Celegans12 commented 2026-10-06 03:04:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T03:04:42Z.


What

A sampled S# with FORCE_UNNORMALIZED (word0 bit 15) throws in DecodeSamplerResource: guest sampler descriptor uses unnormalized coordinates which are not implemented.

  • Recompiler: ShaderInfoCollector records each sampler's live uses with the emitter's explicit-LOD predicate. Populate flags a direct S# with the bit and its paired images only if every use is an explicit-LOD image_sample (_lz, _l; outside pixel shaders also image_sample, _b, _cl, _b_cl) of a direct 1D or 2D image without format conversion; otherwise it throws and names the use. No specialization is added.
  • Driver: the S# needs equal, non-anisotropic XY filters, clamp-to-last-texel or clamp-to-border on X and Y, and no TRUNC_COORD or MC_COORD_TRUNC; its VkSampler gets unnormalizedCoordinates, nearest mips and a zero LOD range. The view must be a single-level, single-layer 1D or 2D view of mip 0. Without the proof the old message stays.
  • Exactness: the S# (RDNA2 ISA: coordinates in [0, dim)) and Vulkan (textures.adoc; VUIDs 01072-01077, 08609-08611, 09635) then address the same texels, as radv relies on, and with one level the LOD fields cannot matter. As on the normalized path, nearest-filter 1/256 rounding and filter arithmetic are not modelled, and opaque borders use the existing integer border colors. shadPS4 (PS4 reference) divides in the shader; Kyty (PS4 reference) passes the flag through.
  • Still throws: gathers, image_get_lod, implicit-LOD pixel samples, offsets, comparison, derivatives, _a, run-time-selected, array, 3D, cube, MSAA and converted images, and multi-level views. TechnicalDebt gets three lines; the shader disk cache format becomes 5.
  • PPSA26344 v1.008: compute shader 0x800040a500 (a 5-tap blur over 120x67 R8 images) samples with image_sample_lz through S# 00008092 00fff000 05500000 00000000.
  • #757 (with #758 and #759 stacked on it) edits the same files, also at FormatVersion 5, so whichever lands second moves to 6; the other conflicts are textual, and its table S#s stay unproven. #639 rewrites the same binding code; the proof here is a ShaderInfo field plus binding flags, not a specialization.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main b10f5701: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 343/343 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 342/342 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_driver_image_sample_unnormalized (GPU; RTX 3080 Laptop GPU, Intel UHD Graphics): image_sample_lz, _l and image_sample at quarter-texel coordinates against the Vulkan formulas, with bilinear and point S#s, clamp-to-last-texel and transparent-black clamp-to-border; the first level of a 4-level image matches; a 3-level view, unequal filters and clamp mode 0 throw. Fails on main.
  • agc_driver_graphics, agc_shader_memory and agc_shader_disk_cache are extended (accepted and rejected S# fields and uses, SPIR-V operand masks, the new cache fields); they do not build on main.
  • PPSA26344 v1.008: the box blur 0x800040a500 dispatches twice through one unnormalized VkSampler; the title then stops at compute shader 0x8000265d00: sampled image descriptor uses an unsupported format.
  • Not tested: Linux (CI), console behaviour.

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:4753578955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/799). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T03:04:42Z. --- ### What A sampled S# with `FORCE_UNNORMALIZED` (word0 bit 15) throws in `DecodeSamplerResource`: `guest sampler descriptor uses unnormalized coordinates which are not implemented`. - **Recompiler:** `ShaderInfoCollector` records each sampler's live uses with the emitter's explicit-LOD predicate. `Populate` flags a direct S# with the bit and its paired images only if every use is an explicit-LOD `image_sample` (`_lz`, `_l`; outside pixel shaders also `image_sample`, `_b`, `_cl`, `_b_cl`) of a direct 1D or 2D image without format conversion; otherwise it throws and names the use. No specialization is added. - **Driver:** the S# needs equal, non-anisotropic XY filters, clamp-to-last-texel or clamp-to-border on X and Y, and no `TRUNC_COORD` or `MC_COORD_TRUNC`; its `VkSampler` gets `unnormalizedCoordinates`, nearest mips and a zero LOD range. The view must be a single-level, single-layer 1D or 2D view of mip 0. Without the proof the old message stays. - **Exactness:** the S# (RDNA2 ISA: coordinates in [0, dim)) and Vulkan (`textures.adoc`; VUIDs 01072-01077, 08609-08611, 09635) then address the same texels, as radv relies on, and with one level the LOD fields cannot matter. As on the normalized path, nearest-filter 1/256 rounding and filter arithmetic are not modelled, and opaque borders use the existing integer border colors. shadPS4 (PS4 reference) divides in the shader; Kyty (PS4 reference) passes the flag through. - **Still throws:** gathers, `image_get_lod`, implicit-LOD pixel samples, offsets, comparison, derivatives, `_a`, run-time-selected, array, 3D, cube, MSAA and converted images, and multi-level views. TechnicalDebt gets three lines; the shader disk cache format becomes 5. - PPSA26344 v1.008: compute shader 0x800040a500 (a 5-tap blur over 120x67 R8 images) samples with `image_sample_lz` through S# `00008092 00fff000 05500000 00000000`. - #757 (with #758 and #759 stacked on it) edits the same files, also at `FormatVersion` 5, so whichever lands second moves to 6; the other conflicts are textual, and its table S#s stay unproven. #639 rewrites the same binding code; the proof here is a `ShaderInfo` field plus binding flags, not a specialization. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` b10f5701: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 343/343 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 342/342 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_driver_image_sample_unnormalized` (GPU; RTX 3080 Laptop GPU, Intel UHD Graphics): `image_sample_lz`, `_l` and `image_sample` at quarter-texel coordinates against the Vulkan formulas, with bilinear and point S#s, clamp-to-last-texel and transparent-black clamp-to-border; the first level of a 4-level image matches; a 3-level view, unequal filters and clamp mode 0 throw. Fails on `main`. - `agc_driver_graphics`, `agc_shader_memory` and `agc_shader_disk_cache` are extended (accepted and rejected S# fields and uses, SPIR-V operand masks, the new cache fields); they do not build on `main`. - PPSA26344 v1.008: the box blur 0x800040a500 dispatches twice through one unnormalized `VkSampler`; the title then stops at compute shader 0x8000265d00: `sampled image descriptor uses an unsupported format`. - Not tested: Linux (CI), console behaviour. ### 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 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
oneandonlydean commented 2026-10-06 05:34:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:00Z.


Thanks, this looks right to me. I checked the conditions against the Vulkan rules for unnormalizedCoordinates:

  • The sampler side is covered: equal min/mag filters, no anisotropy, clamp-to-edge or clamp-to-border on U/V, nearest mips, and a zero LOD range. Compare is refused in Sampler.
  • The shader side is covered too: only explicit-LOD samples are accepted, with no Dref, bias operand or offsets. Outside pixel shaders, _b emits Lod 0 and _cl emits FMax into the Lod operand, so neither adds a bias or MinLod operand.
  • The view check (one level, one layer, 1D/2D, base level 0, no min LOD) runs where the texture is resolved.
  • The proof is recomputed from each snapshot in materializeResult, like guestDescriptor, so a cached variant doesn't carry the flag from a normalized S# to an unnormalized one or back.

One small point. An image paired with both an unnormalized and a normalized sampler gets imageUnnormalized and must then be single-level, even when the other sampler is the one that matters. That throws rather than producing wrong output, so it's fine, but it might be worth half a sentence in the second TechnicalDebt line.

As you noted, this and #757-#759 both move FormatVersion to 5 and touch Resources.hpp, DescriptorBindingBuilder.cpp and ShaderDiskCache.cpp. Whichever lands second will need a rebase and version 6.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010062424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/799#issuecomment-6010062424). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T05:34:00Z. --- Thanks, this looks right to me. I checked the conditions against the Vulkan rules for `unnormalizedCoordinates`: - The sampler side is covered: equal min/mag filters, no anisotropy, clamp-to-edge or clamp-to-border on U/V, nearest mips, and a zero LOD range. Compare is refused in `Sampler`. - The shader side is covered too: only explicit-LOD samples are accepted, with no Dref, bias operand or offsets. Outside pixel shaders, `_b` emits `Lod 0` and `_cl` emits `FMax` into the `Lod` operand, so neither adds a bias or MinLod operand. - The view check (one level, one layer, 1D/2D, base level 0, no min LOD) runs where the texture is resolved. - The proof is recomputed from each snapshot in `materializeResult`, like `guestDescriptor`, so a cached variant doesn't carry the flag from a normalized S# to an unnormalized one or back. One small point. An image paired with both an unnormalized and a normalized sampler gets `imageUnnormalized` and must then be single-level, even when the other sampler is the one that matters. That throws rather than producing wrong output, so it's fine, but it might be worth half a sentence in the second TechnicalDebt line. As you noted, this and #757-#759 both move `FormatVersion` to 5 and touch `Resources.hpp`, `DescriptorBindingBuilder.cpp` and `ShaderDiskCache.cpp`. Whichever lands second will need a rebase and version 6.
Celegans12 commented 2026-10-06 05:43:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T05:43:56Z.


Thanks. Added to the second TechnicalDebt line: the single-level view is required "even when the image is also sampled through a normalized S#". Force-pushed (one commit, ctest 343/343 on Windows and lavapipe). The FormatVersion 5 clash with #757 is noted in the description; whichever lands second moves to 6.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010169011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/799#issuecomment-6010169011). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T05:43:56Z. --- Thanks. Added to the second TechnicalDebt line: the single-level view is required "even when the image is also sampled through a normalized S#". Force-pushed (one commit, ctest 343/343 on Windows and lavapipe). The `FormatVersion` 5 clash with #757 is noted in the description; whichever lands second moves to 6.
github-actions[bot] commented 2026-10-07 05:59:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T05:59:29Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#896 core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp L244
core/shader/recompiler/ShaderDiskCache.cpp L67
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6031978952 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/799#issuecomment-6031978952). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T05:59:29Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #896 | `core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp` [L244](https://github.com/boykopovar/AnyPS5/blob/a9ec7be28726162b5af04664c98cc61f2dc4eba2/core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp#L244)<br>`core/shader/recompiler/ShaderDiskCache.cpp` [L67](https://github.com/boykopovar/AnyPS5/blob/a9ec7be28726162b5af04664c98cc61f2dc4eba2/core/shader/recompiler/ShaderDiskCache.cpp#L67) | | |
adriadam10 commented 2026-10-07 06:50:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T06:50:13Z.


Checked on the HW oracle (gfx1035, single-level 2D f32 texture): image_sample_lz, image_sample_l and compute image_sample with bilinear/point × clamp-to-last-texel/clamp-to-border S#s (plus MIN_LOD 1 + LOD bias 1.5) over 144 coordinates including out-of-range and quarter-texel rows match the Vulkan unnormalized formulas, apart from the 1/256 bilinear weight quantization already noted. Build + ctest 384/384 on RADV, CI green; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6032613780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/799#issuecomment-6032613780). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T06:50:13Z. --- Checked on the HW oracle (gfx1035, single-level 2D f32 texture): `image_sample_lz`, `image_sample_l` and compute `image_sample` with bilinear/point × clamp-to-last-texel/clamp-to-border S#s (plus MIN_LOD 1 + LOD bias 1.5) over 144 coordinates including out-of-range and quarter-texel rows match the Vulkan unnormalized formulas, apart from the 1/256 bilinear weight quantization already noted. Build + ctest 384/384 on RADV, CI green; merging.
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!799
No description provided.