Skip to content

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

Open
DannyOppenheimer wants to merge 1 commit into
boykopovar:mainfrom
DannyOppenheimer:fix/volume-line-explicit-lod
Open

DannyOppenheimer wants to merge 1 commit into
boykopovar:mainfrom
DannyOppenheimer:fix/volume-line-explicit-lod

Conversation

@DannyOppenheimer

@DannyOppenheimer DannyOppenheimer commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Explicit LOD sampling

Layer / File(s) Summary
Resource compatibility
core/shader/recompiler/Optimization/src/ResourceTracker.cpp
Merge(ImageResource&, ...) now includes explicit-LOD samples in the flat-volume-line compatibility condition. The packed-image and element-access exclusions remain.
Explicit-LOD execution test and measurements
core/libs/prx/libSceAgcDriver/tests/execution/ImageVolumeAddressOnLine.cpp, docs/dev/debt/changes/volume-line-explicit-lod.md
The test now runs explicit-LOD samples against a three-level 1D mip chain and checks each level’s color instead of requiring the operation to be refused. The documentation records hardware measurements, unverified cases, and unsupported operations.

Suggested reviewers: michongoddijn231849, marczx10

Change: Bug fix

Merge Risk: Minimal · up to 53c5f

This change lets shaders that sample a 1D texture through a 3D image with an explicit LOD run instead of being refused. The execution test checks the returned colors at each mip level, and the author reports a matching hardware comparison at integer LODs. Fractional LOD behavior was not measured, but nothing inspected shows it differs, so no merge-blocking risk remains.

Security architecture risk: Minimal · up to 53c5f

The change allows a narrowly defined read-only sample that was previously rejected. It still uses the bound texture and its existing mip limits. No new access rights or material weakening of isolation was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new reachability is a sampled read from the already bound 1D image in guest modes where classification previously refused it. The predicate grants no storage-write mode and does not widen the sampled view.

Trust Boundaries and Controls

  • observed — Runtime matching still checks the decoded image dimension and resource attributes. The texture constructor checks snapshot or import coverage against descriptor-derived geometry and builds the normal sampled view from the descriptor's base mip and bounded level count, not from the shader's LOD operand.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fc89a666-07c1-4684-bc06-093651ff40b3
Commits

Reviewing files that changed from the base of the PR and between 63ee1c1 and 53c5f9c.

Files selected for processing: 3

  • core/libs/prx/libSceAgcDriver/tests/execution/ImageVolumeAddressOnLine.cpp
  • core/shader/recompiler/Optimization/src/ResourceTracker.cpp
  • docs/dev/debt/changes/volume-line-explicit-lod.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6280 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 6488 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7085 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7642 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7684 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9633 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9790 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9852 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9897 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9969 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 10193 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 10867 core/libs/prx/libSceAgcDriver/tests/execution/ImageVolumeAddressOnLine.cpp
PR 13928 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 13929 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 14032 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 14853 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 14944 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 15555 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 18106 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 18107 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 21745 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 21763 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 22424 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 23242 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 26012 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 28176 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 28470 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 28487 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 28673 core/shader/recompiler/Optimization/src/ResourceTracker.cpp

@JJenkx

JJenkx commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Windows at this head (53c5f9cdd18d): agc_driver_image_volume_address_on_line passes, 3/3 runs. This is the CTest of the executable that compiles the changed ImageVolumeAddressOnLine.cpp.

Setup:

  • Windows 11 22621, Ryzen 9 5950X, MinGW-w64 GCC 15.2 UCRT r7, Release.
  • The exact PR head was built (not merged into main).
  • 3 runs through the shared FIFO.

The added test lines are not inside a platform guard.

AI-assisted: yes.

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@upipibi

upipibi commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Windows/NVIDIA run of head 53c5f9cdd1, merged with --no-ff onto main e3c0f62f67 (clean merge): RTX 3070, driver 621.40 (Vulkan), Ryzen 9 5950X, Windows 11 Pro 10.0.26100, WinLibs MinGW GCC, Release, -DBUILD_TESTING=ON with ANYPS5_AGC_EXECUTION_TESTS empty. Ran with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, Vulkan SDK 1.4.363 layer, ctest -V --timeout 120, 3 runs per tree. The loader log shows the layer inserted 1 time per run and never missing.

Tests: agc_driver_image_volume_address_on_line (the tests added by the PR or built from a file it changes).

tree result VUID- / SYNC-HAZARD
main e3c0f62f67 (the 1 that exist there) 1 passed, 0 failed, each run 0 / 0
this PR merged onto it 1 passed, 0 failed, each run 0 / 0

Not tested: Linux, AMD or Intel drivers, a title run.

AI-assisted: yes. Claude Code (Claude Opus 5.5) ran the build and the tests and wrote this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants