Skip to content

fix(shader): read explicit-LOD and level-zero 2D-array samples through 1D T#s as measured - #5841

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
simonbronk:feat/line-reads-through-2d-array
Oct 15, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
simonbronk:feat/line-reads-through-2d-array

Conversation

@simonbronk

@simonbronk simonbronk commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Onimusha: Way of the Sword (PPSA27836) samples a 1D T# (8_8_8_8 UNORM, from a bindless material table) through a 2D-array image_sample_l, and preparation stops:

image descriptor is incompatible with the static runtime image interface: descriptor format 56 decodes to {class 1, dim 1, ...}; modes: {class 1, dim 5, ...} {class 1, dim 3, ...} ...

#5583 (merged) gives 2D explicit-LOD samples through a 1D T# the 1D runtime mode. This extends that mode to 2D-array accesses, for image_sample_l and image_sample_lz only, as measured.

Source: hardware measurement on RDNA2 (gfx1036, Ryzen iGPU), tools/hw-oracle/template.s assembled by the AMD Windows driver's amd_comgr_2.dll and launched through its amdhip64_6.dll (the runner posted in #1281, with the template's newer placeholders filled). Each row samples the same TYPE 1D T# with DIM 2D_ARRAY and with DIM 1D and compares the results bit for bit. 16-texel 8_8_8_8 UNORM T# filled with distinct words; 1 or 5 levels, the 5-level one also with HEIGHT 3 or DEPTH 3; u of 0.03125, 0.33125, 0.96875, 0, 1, -0.2, 1.3 and 0.6; v of 0, 0.5, 1, -0.25 and 3; slices 0, 1, 2.7, -1 and 5; LOD -1, 0, 1, 1.25, 2.75 and 6; point and linear filtering with point and linear mips under clamp, wrap and border addressing.

  • image_sample_l: 24000/24000 rows equal.
  • image_sample_lz: 24000/24000 rows equal.
  • image_load (not enabled here): DIM 2D_ARRAY returns the DIM 1D texel only at slice 0 and zeros at slices 1, 2, 5 and -1, even with DEPTH 3 (600 rows). It keeps throwing, and the debt entry records it.

The plain image_sample and the other 2D-array accesses through a 1D T# also keep throwing. The PS5's gfx1013 is not measured.

Tested

  • Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, rebased on main 0afa6a6 (fix(shader): read explicit-LOD 2D samples through 1D T#s as measured #5583 merged; the line-sample condition keeps main's comparison mask for non-array accesses):
  • agc_driver_image_plane_address_on_line gains CheckArray: image_sample_l and image_sample_lz with DIM 2D_ARRAY through the 5-level 1D T#, slices 0, 1, 2.7, -1 and 5, under the five sampler cases, compared bit for bit with image_sample_l DIM 1D. It passes on the RTX 5070 and on the AMD iGPU. Without the change it fails with the title's message.
  • PPSA27836 on Windows (RTX 5070), on a local branch with the fixes in Onimusha: Way of the Sword (PPSA27836) #5769: the program prepares, and the title reaches its first presentation.
  • python tools/check_conventions.py --base upstream/main: passes.

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 — not applicable
  • 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 — not applicable
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA27836 Onimusha: Way of the Sword (PPSA27836) #5769
  • GPUs tested: NVIDIA GeForce RTX 5070, driver 617.42 (32.0.16.1742); AMD Radeon(TM) Graphics, Ryzen iGPU gfx1036, driver 32.0.21036.18; both Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

@simonbronk

Copy link
Copy Markdown
Contributor Author

The probe and the raw output of the measurement. The runner is hw_oracle_win.py from #1281 with one change: assemble also fills the template's newer placeholders (@DX10_CLAMP@ 1, @ROUND32@ 0, @ROUND16@ 0, @FP16_OVERFLOW@ 0, @LDS@ 4096). Run as python probe_1d_as_2darray.py image_sample_l (or image_sample_lz, image_load) next to it and template.s.

probe_1d_as_2darray.py
"""image_sample_l with DIM 2D_ARRAY on a TYPE 1D T#, compared with the same sample with DIM 1D.

Each row is (u, v, slice, lod) as f32. The texture is 16 texels wide, format 8_8_8_8 UNORM, linear,
filled with distinct words, so any difference in the texels read shows in the result.
"""
import itertools
import struct
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
import hw_oracle_win as oracle

ROWS = 1024
TEXTURE_OFFSET = ROWS * 16
TEXTURE_BYTES = 16384
WIDTH = 16
FORMAT_8888_UNORM = 56
TYPE_1D = 8

U = [0.03125, 0.33125, 0.96875, 0.0, 1.0, -0.2, 1.3, 0.6]
V = [0.0, 0.5, 1.0, -0.25, 3.0]
SLICE = [0.0, 1.0, 2.7, -1.0, 5.0]
LOD = [-1.0, 0.0, 1.0, 1.25, 2.75, 6.0]

SAMPLERS = [
    ("point, point mips, clamp to edge", 2, 0, 1),
    ("point, point mips, wrap", 0, 0, 1),
    ("linear, linear mips, clamp to edge", 2, 1, 2),
    ("linear, linear mips, wrap", 0, 1, 2),
    ("linear, linear mips, clamp to border", 6, 1, 2),
]
TEXTURES = [
    ("1 level", 1, 0, 0),
    ("5 levels", 5, 0, 0),
    ("5 levels, HEIGHT 3", 5, 3, 0),
    ("5 levels, DEPTH 3", 5, 0, 3),
]


def bits(value):
    return struct.unpack("<I", struct.pack("<f", value))[0]


def body(mips, height, depth, clamp, xy_filter, mip_filter, ops):
    dw1 = (FORMAT_8888_UNORM << 20) | (((WIDTH - 1) & 3) << 30)
    dw2 = ((WIDTH - 1) >> 2) | (height << 14)
    dw3 = 0xFAC | ((mips - 1) << 16) | (TYPE_1D << 28)
    dw4 = depth
    dw5 = (mips - 1) << 4
    sdw0 = clamp | (clamp << 3) | (clamp << 6)
    sdw1 = 0xFFF << 12
    sdw2 = (xy_filter << 20) | (xy_filter << 22) | (mip_filter << 26)
    return f"""
  s_add_u32 s8, s4, {TEXTURE_OFFSET:#x}
  s_addc_u32 s9, s5, 0
  s_lshr_b64 s[8:9], s[8:9], 8
  s_mov_b32 s16, s8
  s_and_b32 s17, s9, 0xff
  s_or_b32 s17, s17, {dw1:#x}
  s_mov_b32 s18, {dw2:#x}
  s_mov_b32 s19, {dw3:#x}
  s_mov_b32 s20, {dw4:#x}
  s_mov_b32 s21, {dw5:#x}
  s_mov_b32 s22, 0
  s_mov_b32 s23, 0
  s_mov_b32 s24, {sdw0:#x}
  s_mov_b32 s25, {sdw1:#x}
  s_mov_b32 s26, {sdw2:#x}
  s_mov_b32 s27, 0
  v_mov_b32 v26, v4
  v_mov_b32 v27, v7
  @OPS@
  s_waitcnt vmcnt(0)
""".replace("@OPS@", ops)


OPS = {
    "image_sample_l": ("image_sample_l v[10:13], v[4:7], s[16:23], s[24:27] dmask:0xf dim:SQ_RSRC_IMG_2D_ARRAY\n  image_sample_l v[14:17], v[26:27], s[16:23], s[24:27] dmask:0xf dim:SQ_RSRC_IMG_1D", True),
    "image_sample_lz": ("image_sample_lz v[10:13], v[4:6], s[16:23], s[24:27] dmask:0xf dim:SQ_RSRC_IMG_2D_ARRAY\n  image_sample_lz v[14:17], v26, s[16:23], s[24:27] dmask:0xf dim:SQ_RSRC_IMG_1D", True),
    "image_load": ("image_load v[10:13], v[4:6], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_2D_ARRAY unorm\n  image_load v[14:17], v26, s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D unorm", False),
}
LOAD_X = [0, 3, 15, 16, 20, 0xFFFFFFFF]
LOAD_Y = [0, 1, 3, 0xFFFFFFFF, 7]
LOAD_SLICE = [0, 1, 2, 5, 0xFFFFFFFF]


def texture():
    return b"".join(struct.pack("<I", (index * 0x9E3779B1 + 0x12345) & 0xFFFFFFFF) for index in range(TEXTURE_BYTES // 4))


def main():
    extra = texture()
    which = sys.argv[1] if len(sys.argv) > 1 else "image_sample_l"
    ops, sampled = OPS[which]
    if sampled:
        grid = [tuple(bits(x) for x in row) for row in itertools.product(U, V, SLICE, LOD)]
        cases = list(itertools.product(TEXTURES, SAMPLERS))
    else:
        grid = [(x, y, z, 0) for x, y, z in itertools.product(LOAD_X, LOAD_Y, LOAD_SLICE)]
        cases = [(texture_case, SAMPLERS[0]) for texture_case in TEXTURES]
    padded = grid + [(0, 0, 0, 0)] * (-len(grid) % ROWS)
    print(f"target {oracle.target()}; {len(grid)} rows per case; {which} DIM 2D_ARRAY vs DIM 1D on a TYPE 1D T#")
    total_rows = 0
    total_mismatch = 0
    for (tname, mips, height, depth), (sname, clamp, xy, mip) in cases:
        results = oracle.run(body(mips, height, depth, clamp, xy, mip, ops), padded, extra, coarse=True)[:len(grid)]
        mismatches = [(grid[i], r) for i, r in enumerate(results) if tuple(r[0:4]) != tuple(r[4:8])]
        untouched = sum(1 for r in results if r[0] == 0xEEEEEEEE or r[4] == 0xEEEEEEEE)
        total_rows += len(grid)
        total_mismatch += len(mismatches)
        distinct = len({tuple(r[4:8]) for r in results if any(r[4:8])})
        print(f"{tname}; {sname}: {len(grid) - len(mismatches)}/{len(grid)} rows equal, {untouched} unwritten, {distinct} distinct non-zero 1D results")
        for row, r in mismatches[:3]:
            values = [struct.unpack('<f', struct.pack('<I', w))[0] for w in row]
            print(f"  u={values[0]} v={values[1]} slice={values[2]} lod={values[3]}: 2d_array {' '.join(f'{w:08x}' for w in r[0:4])} 1d {' '.join(f'{w:08x}' for w in r[4:8])}")
    print(f"total: {total_rows - total_mismatch}/{total_rows} rows equal")


if __name__ == "__main__":
    main()
image_sample_l output
target gfx1036; 1200 rows per case; image_sample_l DIM 2D_ARRAY vs DIM 1D on a TYPE 1D T#
1 level; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
1 level; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
1 level; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
1 level; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 7 distinct non-zero 1D results
1 level; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 11 distinct non-zero 1D results
5 levels; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 14 distinct non-zero 1D results
5 levels; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 17 distinct non-zero 1D results
5 levels; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 29 distinct non-zero 1D results
5 levels; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 31 distinct non-zero 1D results
5 levels, HEIGHT 3; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 11 distinct non-zero 1D results
5 levels, HEIGHT 3; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 14 distinct non-zero 1D results
5 levels, HEIGHT 3; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 17 distinct non-zero 1D results
5 levels, HEIGHT 3; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 29 distinct non-zero 1D results
5 levels, HEIGHT 3; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 31 distinct non-zero 1D results
5 levels, DEPTH 3; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 11 distinct non-zero 1D results
5 levels, DEPTH 3; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 14 distinct non-zero 1D results
5 levels, DEPTH 3; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 17 distinct non-zero 1D results
5 levels, DEPTH 3; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 29 distinct non-zero 1D results
5 levels, DEPTH 3; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 31 distinct non-zero 1D results
total: 24000/24000 rows equal
image_sample_lz output
target gfx1036; 1200 rows per case; image_sample_lz DIM 2D_ARRAY vs DIM 1D on a TYPE 1D T#
1 level; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
1 level; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
1 level; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
1 level; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 7 distinct non-zero 1D results
1 level; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
5 levels; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
5 levels; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 7 distinct non-zero 1D results
5 levels; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels, HEIGHT 3; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
5 levels, HEIGHT 3; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels, HEIGHT 3; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
5 levels, HEIGHT 3; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 7 distinct non-zero 1D results
5 levels, HEIGHT 3; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels, DEPTH 3; point, point mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
5 levels, DEPTH 3; point, point mips, wrap: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
5 levels, DEPTH 3; linear, linear mips, clamp to edge: 1200/1200 rows equal, 0 unwritten, 4 distinct non-zero 1D results
5 levels, DEPTH 3; linear, linear mips, wrap: 1200/1200 rows equal, 0 unwritten, 7 distinct non-zero 1D results
5 levels, DEPTH 3; linear, linear mips, clamp to border: 1200/1200 rows equal, 0 unwritten, 6 distinct non-zero 1D results
total: 24000/24000 rows equal
image_load output
target gfx1036; 150 rows per case; image_load DIM 2D_ARRAY vs DIM 1D on a TYPE 1D T#
1 level; point, point mips, clamp to edge: 90/150 rows equal, 0 unwritten, 3 distinct non-zero 1D results
  u=0.0 v=0.0 slice=1.401298464324817e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3e0c8c8d 3b808081 00000000
  u=0.0 v=0.0 slice=2.802596928649634e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3e0c8c8d 3b808081 00000000
  u=0.0 v=0.0 slice=7.006492321624085e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3e0c8c8d 3b808081 00000000
5 levels; point, point mips, clamp to edge: 90/150 rows equal, 0 unwritten, 3 distinct non-zero 1D results
  u=0.0 v=0.0 slice=1.401298464324817e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3f54d4d5 3ef4f4f5 3e5cdcdd
  u=0.0 v=0.0 slice=2.802596928649634e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3f54d4d5 3ef4f4f5 3e5cdcdd
  u=0.0 v=0.0 slice=7.006492321624085e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3f54d4d5 3ef4f4f5 3e5cdcdd
5 levels, HEIGHT 3; point, point mips, clamp to edge: 90/150 rows equal, 0 unwritten, 3 distinct non-zero 1D results
  u=0.0 v=0.0 slice=1.401298464324817e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3f058586 3e808081 3eb2b2b3 3f45c5c6
  u=0.0 v=0.0 slice=2.802596928649634e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3f058586 3e808081 3eb2b2b3 3f45c5c6
  u=0.0 v=0.0 slice=7.006492321624085e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3f058586 3e808081 3eb2b2b3 3f45c5c6
5 levels, DEPTH 3; point, point mips, clamp to edge: 90/150 rows equal, 0 unwritten, 3 distinct non-zero 1D results
  u=0.0 v=0.0 slice=1.401298464324817e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3f54d4d5 3ef4f4f5 3e5cdcdd
  u=0.0 v=0.0 slice=2.802596928649634e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3f54d4d5 3ef4f4f5 3e5cdcdd
  u=0.0 v=0.0 slice=7.006492321624085e-45 lod=0.0: 2d_array 00000000 00000000 00000000 00000000 1d 3e8a8a8b 3f54d4d5 3ef4f4f5 3e5cdcdd
total: 360/600 rows equal

AI-assisted: yes (Claude Code).

@jotitadev

Copy link
Copy Markdown
Contributor

Run on an Apple GPU, as a third device next to the RTX 5070 and the AMD iGPU.

GPUs tested: Apple M2 Max, MoltenVK 1.4.2 (Vulkan 1.4.357), macOS 27.2, x86-64 under Rosetta

main does not run the GPU tests on macOS yet, so I tested on macos-port at b7eb6b6b (mugurc/AnyPS5) with this PR's diff applied, not on main. Release build, LunarG Vulkan SDK 1.4.363.0. The suite is ctest -R agc -E 'flip|display|lds_atomics64' -j1 --timeout 30. Without the PR, 22 tests fail on this branch, all of them known macOS failures listed in #1. Head afb8151ac, which includes #5583's commit. The diff applies cleanly, except docs/.

  • agc_driver_image_plane_address_on_line passes, including CheckArray through the 5-level 1D T#. With only the test file applied to the unchanged branch, it fails with descriptor format 56 decodes to {class 1, dim 1, ...}, so the new cases do run here. This is relevant on MoltenVK because Metal 1D textures have no mip levels, and MoltenVK normally backs them with 2D textures (texture1DAs2D).
  • Suite: the same 22 failures with and without the PR. None are new and none are fixed.
  • I also ran fix(shader): read explicit-LOD 2D samples through 1D T#s as measured #5583 alone (head a98b06534): same result, the test fails without the change and passes with it.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 14, 2026
@simonbronk

Copy link
Copy Markdown
Contributor Author

Rebased onto main 411e5e6 (d4aeaf4). main now has bd09862 (3D accesses through 1D T#s), which changed the same lines:

  • ResourceTracker.cpp: flatVolumeLineCompatible from main is kept as it is. This PR's explicit-LOD and 2D-array cases still only widen flatLineCompatible.
  • docs/dev/debt/shader.md: kept the new "3D image accesses bound to a 1D T#" entry beside this PR's updated 2D entry.

Tested again on Windows 11 Pro 26200, Release:

@simonbronk
simonbronk force-pushed the feat/line-reads-through-2d-array branch from afb8151 to d4aeaf4 Compare October 14, 2026 19:57
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 14, 2026
@simonbronk
simonbronk force-pushed the feat/line-reads-through-2d-array branch from d4aeaf4 to 40b6523 Compare October 15, 2026 09:09
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 15, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 15, 2026
…h 1D T#s as measured

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto main (mechanical conflict in ResourceMaterializer.cpp with the cube-face block; kept both). Measured on gfx1035 with the HW oracle (your probe, IEEE off): image_sample_l and image_sample_lz DIM 2D_ARRAY match DIM 1D on 24000/24000 rows each, and 2D-array image_load returns zeros at slice ≠ 0, so keeping it throwing is right. agc_driver_image_plane_address_on_line fails without the change and passes with it on RADV; merging.

@adriadam10
adriadam10 force-pushed the feat/line-reads-through-2d-array branch from 40b6523 to 63db31f Compare October 15, 2026 13:42
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 15, 2026
@adriadam10
adriadam10 merged commit 7758aba into boykopovar:main Oct 15, 2026
8 checks passed
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.

3 participants