Repository navigation
fix(shader): read explicit-LOD and level-zero 2D-array samples through 1D T#s as measured - #5841
Conversation
|
The probe and the raw output of the measurement. The runner is 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 outputimage_sample_lz outputimage_load outputAI-assisted: yes (Claude Code). |
|
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
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. |
|
Rebased onto
Tested again on Windows 11 Pro 26200, Release:
|
afb8151 to
d4aeaf4
Compare
d4aeaf4 to
40b6523
Compare
…h 1D T#s as measured Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased onto |
40b6523 to
63db31f
Compare
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:#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_landimage_sample_lzonly, as measured.Source: hardware measurement on RDNA2 (gfx1036, Ryzen iGPU),
tools/hw-oracle/template.sassembled by the AMD Windows driver'samd_comgr_2.dlland launched through itsamdhip64_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_sampleand the other 2D-array accesses through a 1D T# also keep throwing. The PS5's gfx1013 is not measured.Tested
main0afa6a6 (fix(shader): read explicit-LOD 2D samples through 1D T#s as measured #5583 merged; the line-sample condition keepsmain's comparison mask for non-array accesses):ctest -R "agc|shader|video_out"on the RTX 5070: 601/601 pass;mainon this GPU.agc_driver_image_plane_address_on_linegainsCheckArray:image_sample_landimage_sample_lzwith 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 withimage_sample_lDIM 1D. It passes on the RTX 5070 and on the AMD iGPU. Without the change it fails with the title's message.python tools/check_conventions.py --base upstream/main: passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file — not applicable.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code