fix(shader): honor explicit LOD on 3D samples of 1D textures #28324

Open
DannyOppenheimer wants to merge 1 commit from upstream-pr/28324 into main
DannyOppenheimer commented 2026-11-30 05:04:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DannyOppenheimer on 2026-11-30T05:04:53Z.


What

A shader that issues image_sample_l with DIM 3D can bind a 1D texture. Main rejects that binding during resource materialization. An RX 5700 XT sampled the same mip as a native DIM 1D instruction when the two instructions shared the descriptor, sampler, u coordinate and explicit LOD.

Allow the exact explicit-LOD sample flag in the existing 3D-on-1D compatibility check. The existing sampling path supplies u and the instruction's LOD to the 1D image. Combined flags, including comparison and offset, retain their existing checks. This extends the plain and level-zero samples covered by #5375.

The overlap check flagged shared tracker lines in #7085 and #28176 (extra mip backing), and #10867 adjusts the compute target in the former refusal test. Those patches address different behavior.

The execution test replaces its explicit-LOD refusal assertion with a three-level texture. Each dispatch requests one mip with u fixed and sweeps v and r independently. It checks RGBA for every lane.

Tested

Hardware oracle. AMD Radeon RX 5700 XT (Navi 10, gfx1010), Windows 11 build 26200, AMD driver 32.0.21045.5002. The probe used a 64-texel linear RGBA8 UNORM 1D texture, point mip filtering, wrap addressing and u = 0.375. Both instructions ran in each lane, with the 1D form as the control. For each requested LOD, v and r independently covered {-0.25, 0, 0.5, 1, 1.5}.

Requested LOD DIM 1D control DIM 3D on the same 1D texture
0 Blue Blue
1 Green Green
2 Red Red

All four raw float channels matched on all 75 rows, in two wave32 runs and one wave64 run. Fractional LODs and other sampler modes were outside this measurement.

Reproduce the native measurement with tools/hw-oracle

Save the following script and run python measure.py <AnyPS5 checkout> with the RX 5700 XT selected via HIP_VISIBLE_DEVICES. It records the per-lane channel bits in results.json next to the script.

import itertools
import json
import os
import struct
import sys
from pathlib import Path

sys.path.insert(0, str(Path(sys.argv[1]).resolve() / "tools/hw-oracle"))
import hw_oracle as oracle

if oracle.target() != "gfx1010":
    raise RuntimeError("Select the RX 5700 XT before running")
coords = [-0.25, 0, 0.5, 1, 1.5]
cases = list(itertools.product(range(3), coords, coords))
modes = dict(ieee=0, dx10_clamp=1, denorm32=3, denorm16=3, round32=0, round16=0, fp16_overflow=0)
rows = [struct.unpack("<4I", struct.pack("<4f", 0.375, v, r, lod)) for lod, v, r in cases]
rows += [rows[0]] * (128 - len(rows))
colors = [bytes((255,0,0,255)), bytes((0,255,0,255)), bytes((0,0,255,255))]
extra = b"".join(color * 64 for color in colors) + bytes(65536)
body = """
s_add_u32 s8, s4, 2048
s_addc_u32 s9, s5, 0
s_lshr_b64 s[8:9], s[8:9], 8
s_or_b32 s9, s9, 0xc3800000
s_mov_b32 s10, 0x8000000f
s_mov_b32 s11, 0x80020fac
s_mov_b32 s12, 0
s_mov_b32 s13, 0x20
s_mov_b32 s14, 0
s_mov_b32 s15, 0
s_mov_b32 s16, 0
s_mov_b32 s17, 0x00200000
s_mov_b32 s18, 0x04000000
s_mov_b32 s19, 0
v_mov_b32 v8, v4
v_mov_b32 v9, v7
image_sample_l v[10:13], v[8:9], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_1D
image_sample_l v[14:17], v[4:7], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_3D
s_waitcnt vmcnt(0)
"""
results = []
for wave64 in (False, False, True):
    data = oracle.run(body, rows, extra, wave64=wave64, **modes)
    results.append(dict(wave=64 if wave64 else 32, rows=[dict(lod=l, v=v, r=r, control=row[:4], volume=row[4:8]) for (l,v,r),row in zip(cases,data)]))
out = Path(__file__).with_name("results.json")
out.write_text(json.dumps(dict(target=oracle.target(), u=0.375, modes=modes, runs=results),indent=2))
for lod in range(3):
    print(lod, {tuple(x["control"]) for x in results[0]["rows"] if x["lod"] == lod}, {tuple(x["volume"]) for x in results[0]["rows"] if x["lod"] == lod})

Vulkan execution. Built the focused target with WinLibs GCC and ran ctest --test-dir build -R '^agc_driver_image_volume_address_on_line$' -V at main 4025563419 and at 53c5f9cdd1 on the same RX 5700 XT. Both passed with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer. Both logs show insertion of validation layer 1.4.369, zero missing-layer warnings and zero VUID- messages. Main exercises the old refusal. The branch checks the sampled colors.

python tools/check_conventions.py passed. No game was tested.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 5700 XT, driver 32.0.21045.5002, Windows 11 10.0.26200
  • AI-assisted: yes

Summary by CodeRabbit

  • New Features
    • Added support for explicit mip-level sampling in applicable 1D texture operations, improving compatibility with content that uses these texture accesses.
  • Bug Fixes
    • Corrected handling of explicit-LOD samples so eligible image accesses can use the appropriate volume-line path.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5559342354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28324). Originally posted by [DannyOppenheimer](https://github.com/DannyOppenheimer) on 2026-11-30T05:04:53Z. --- ### What A shader that issues `image_sample_l` with DIM 3D can bind a 1D texture. Main rejects that binding during resource materialization. An RX 5700 XT sampled the same mip as a native DIM 1D instruction when the two instructions shared the descriptor, sampler, u coordinate and explicit LOD. Allow the exact explicit-LOD sample flag in the existing 3D-on-1D compatibility check. The existing sampling path supplies u and the instruction's LOD to the 1D image. Combined flags, including comparison and offset, retain their existing checks. This extends the plain and level-zero samples covered by #5375. The overlap check flagged shared tracker lines in #7085 and #28176 (extra mip backing), and #10867 adjusts the compute target in the former refusal test. Those patches address different behavior. The execution test replaces its explicit-LOD refusal assertion with a three-level texture. Each dispatch requests one mip with u fixed and sweeps v and r independently. It checks RGBA for every lane. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> **Hardware oracle.** AMD Radeon RX 5700 XT (Navi 10, gfx1010), Windows 11 build 26200, AMD driver 32.0.21045.5002. The probe used a 64-texel linear RGBA8 UNORM 1D texture, point mip filtering, wrap addressing and u = 0.375. Both instructions ran in each lane, with the 1D form as the control. For each requested LOD, v and r independently covered {-0.25, 0, 0.5, 1, 1.5}. | Requested LOD | DIM 1D control | DIM 3D on the same 1D texture | | --- | --- | --- | | 0 | Blue | Blue | | 1 | Green | Green | | 2 | Red | Red | All four raw float channels matched on all 75 rows, in two wave32 runs and one wave64 run. Fractional LODs and other sampler modes were outside this measurement. <details><summary>Reproduce the native measurement with tools/hw-oracle</summary> Save the following script and run `python measure.py <AnyPS5 checkout>` with the RX 5700 XT selected via `HIP_VISIBLE_DEVICES`. It records the per-lane channel bits in `results.json` next to the script. ```python import itertools import json import os import struct import sys from pathlib import Path sys.path.insert(0, str(Path(sys.argv[1]).resolve() / "tools/hw-oracle")) import hw_oracle as oracle if oracle.target() != "gfx1010": raise RuntimeError("Select the RX 5700 XT before running") coords = [-0.25, 0, 0.5, 1, 1.5] cases = list(itertools.product(range(3), coords, coords)) modes = dict(ieee=0, dx10_clamp=1, denorm32=3, denorm16=3, round32=0, round16=0, fp16_overflow=0) rows = [struct.unpack("<4I", struct.pack("<4f", 0.375, v, r, lod)) for lod, v, r in cases] rows += [rows[0]] * (128 - len(rows)) colors = [bytes((255,0,0,255)), bytes((0,255,0,255)), bytes((0,0,255,255))] extra = b"".join(color * 64 for color in colors) + bytes(65536) body = """ s_add_u32 s8, s4, 2048 s_addc_u32 s9, s5, 0 s_lshr_b64 s[8:9], s[8:9], 8 s_or_b32 s9, s9, 0xc3800000 s_mov_b32 s10, 0x8000000f s_mov_b32 s11, 0x80020fac s_mov_b32 s12, 0 s_mov_b32 s13, 0x20 s_mov_b32 s14, 0 s_mov_b32 s15, 0 s_mov_b32 s16, 0 s_mov_b32 s17, 0x00200000 s_mov_b32 s18, 0x04000000 s_mov_b32 s19, 0 v_mov_b32 v8, v4 v_mov_b32 v9, v7 image_sample_l v[10:13], v[8:9], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_1D image_sample_l v[14:17], v[4:7], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_3D s_waitcnt vmcnt(0) """ results = [] for wave64 in (False, False, True): data = oracle.run(body, rows, extra, wave64=wave64, **modes) results.append(dict(wave=64 if wave64 else 32, rows=[dict(lod=l, v=v, r=r, control=row[:4], volume=row[4:8]) for (l,v,r),row in zip(cases,data)])) out = Path(__file__).with_name("results.json") out.write_text(json.dumps(dict(target=oracle.target(), u=0.375, modes=modes, runs=results),indent=2)) for lod in range(3): print(lod, {tuple(x["control"]) for x in results[0]["rows"] if x["lod"] == lod}, {tuple(x["volume"]) for x in results[0]["rows"] if x["lod"] == lod}) ``` </details> **Vulkan execution.** Built the focused target with WinLibs GCC and ran `ctest --test-dir build -R '^agc_driver_image_volume_address_on_line$' -V` at main `4025563419` and at `53c5f9cdd1` on the same RX 5700 XT. Both passed with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`. Both logs show insertion of validation layer 1.4.369, zero missing-layer warnings and zero `VUID-` messages. Main exercises the old refusal. The branch checks the sampled colors. `python tools/check_conventions.py` passed. No game was tested. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 (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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: AMD Radeon RX 5700 XT, driver 32.0.21045.5002, Windows 11 10.0.26200 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added support for explicit mip-level sampling in applicable 1D texture operations, improving compatibility with content that uses these texture accesses. * **Bug Fixes** * Corrected handling of explicit-LOD samples so eligible image accesses can use the appropriate volume-line path. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-30 05:13:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T05:13:24Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 53c5f9cdd18dba7db197c23acc10c09637966f3f. I read the prepared description, commits, diff, manifest, and all added lines in the three changed files, plus the resource materializer compatibility logic. No tests or builds were run by me; the hardware and Vulkan runs described in the PR were author-reported.

Results

Check Result Note
Changed-line review passed All added lines read
Build and tests not run Author reports focused Vulkan test passed

Findings

Blocking

None.

Non-blocking

  • The execution test covers integer LODs 0–2 with point mip filtering. Fractional LODs and other sampler modes remain unverified, as the description notes.

Not verified

I did not run builds, tests, or the hardware oracle. I read all changed files listed in the manifest; no changed files were excluded. The referenced files.json was not available through the reader, so excluded-by-rule details are not verified.

To get this to a good state

Nothing is required. Optional: extend hardware coverage to fractional LODs and additional sampler modes if those are needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6107171261 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28324#pullrequestreview-6107171261). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T05:13:24Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `53c5f9cdd18dba7db197c23acc10c09637966f3f`. I read the prepared description, commits, diff, manifest, and all added lines in the three changed files, plus the resource materializer compatibility logic. No tests or builds were run by me; the hardware and Vulkan runs described in the PR were author-reported. ## Results | Check | Result | Note | | --- | --- | --- | | Changed-line review | passed | All added lines read | | Build and tests | not run | Author reports focused Vulkan test passed | ## Findings ### Blocking None. ### Non-blocking - The execution test covers integer LODs 0–2 with point mip filtering. Fractional LODs and other sampler modes remain unverified, as the description notes. ## Not verified I did not run builds, tests, or the hardware oracle. I read all changed files listed in the manifest; no changed files were excluded. The referenced `files.json` was not available through the reader, so excluded-by-rule details are not verified. ## To get this to a good state Nothing is required. Optional: extend hardware coverage to fractional LODs and additional sampler modes if those are needed.
Plyxen commented 2026-12-03 10:38:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T10:38:45Z.

Review: APPROVED


I read the diff at 53c5f9cdd1. Windows 11, GCC 15.2, merged into main at b97867d3ce6 together with other open PRs (so not an isolated build), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).

  • agc_driver_image_volume_address_on_line: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a VUID- or SYNC-HAZARD line.
  • Control (same tree and tests, the changed files of those PRs put back to main's): fails on both GPUs: "image descriptor is incompatible with the static runtime image interface".

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168120582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28324#pullrequestreview-6168120582). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T10:38:45Z. **Review:** APPROVED --- I read the diff at `53c5f9cdd1`. Windows 11, GCC 15.2, merged into `main` at `b97867d3ce6` together with other open PRs (so not an isolated build), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation` on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2). - `agc_driver_image_volume_address_on_line`: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a `VUID-` or `SYNC-HAZARD` line. - Control (same tree and tests, the changed files of those PRs put back to `main`'s): fails on both GPUs: "image descriptor is incompatible with the static runtime image interface". Not checked: a title. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 14:53:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:53:30Z.

Review: COMMENTED


Ran the GCN scalar-buffer CTest on main and this head integrated using lavapipe. It passed on both runs. The branch's new agc_driver_image_volume_address_on_line test also passed, covering explicit LOD with 3D sampling of a line texture. The requested Khronos validation 1.4.369 layer was inserted in all three logs, with no missing-layer diagnostic or VUID- messages.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6172191759 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28324#pullrequestreview-6172191759). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T14:53:30Z. **Review:** COMMENTED --- Ran the GCN scalar-buffer CTest on `main` and this head integrated using lavapipe. It passed on both runs. The branch's new `agc_driver_image_volume_address_on_line` test also passed, covering explicit LOD with 3D sampling of a line texture. The requested Khronos validation 1.4.369 layer was inserted in all three logs, with no missing-layer diagnostic or `VUID-` messages. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28324:upstream-pr/28324'
git switch 'upstream-pr/28324'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/28324'
git switch 'upstream-pr/28324'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28324'
git switch 'upstream-pr/28324'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28324'
git switch 'main'
git merge --squash 'upstream-pr/28324'
git switch 'main'
git merge --ff-only 'upstream-pr/28324'
git switch 'main'
git merge 'upstream-pr/28324'
git push origin 'main'
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!28324
No description provided.