feat(libSceAgcDriver): support secondary LOD bias and relax unnormalized coordinate filters #5156

Merged
pushkarreddyy merged 1 commit from upstream-pr/5156 into main 2026-10-14 12:13:05 +00:00
pushkarreddyy commented 2026-10-13 13:06:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-13T13:06:13Z.


What

Decodes secondary LOD bias (LOD_BIAS_SEC, DWORD 2 bits [19:14]) in sampler resource descriptors as signed 2.4 fixed point (((raw ^ 0x20u) - 0x20u) / 16.0f) and adds it to the primary LOD bias.

Additionally, relaxes unnormalized coordinate sampler validation:

  • When minification and magnification filters differ (xyMagFilter != xyMinFilter), assigns xyMagFilter for both filters to satisfy Vulkan's unnormalized coordinates constraint (minFilter == magFilter at LOD 0).
  • Maps clamp mode 0 (repeat) on X and Y to VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE as required for unnormalized sampling.

In High on Life (PPSA15388, #4736), the title renders the home base and city with samplers specifying LOD_BIAS_SEC and unnormalized coordinates with clamp mode 0 and differing min/mag filters. Previously, DecodeSamplerResource threw std::runtime_error("guest sampler descriptor uses a secondary LOD bias which is not implemented") and aborted.

Tested

  • Updated unit tests in core/libs/prx/libSceAgcDriver/tests/GuestSamplerResource.cpp validating positive, negative, and combined primary/secondary LOD bias decoding, differing min/mag filter assignment under unnormalized coordinates, and clamp mode 0 mapping to clamp-to-edge.
  • Ran python tools/check_conventions.py --base origin/main with 0 findings.

Checklist

  • Depends on: none
  • AI-assisted: yes
  • Unblocks: PPSA15388 #4736
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4843685423 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-13T13:06:13Z. --- ### What Decodes secondary LOD bias (LOD_BIAS_SEC, DWORD 2 bits [19:14]) in sampler resource descriptors as signed 2.4 fixed point (((raw ^ 0x20u) - 0x20u) / 16.0f) and adds it to the primary LOD bias. Additionally, relaxes unnormalized coordinate sampler validation: - When minification and magnification filters differ (xyMagFilter != xyMinFilter), assigns xyMagFilter for both filters to satisfy Vulkan's unnormalized coordinates constraint (minFilter == magFilter at LOD 0). - Maps clamp mode 0 (repeat) on X and Y to VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE as required for unnormalized sampling. In *High on Life* (PPSA15388, #4736), the title renders the home base and city with samplers specifying LOD_BIAS_SEC and unnormalized coordinates with clamp mode 0 and differing min/mag filters. Previously, DecodeSamplerResource threw std::runtime_error("guest sampler descriptor uses a secondary LOD bias which is not implemented") and aborted. ### Tested - Updated unit tests in core/libs/prx/libSceAgcDriver/tests/GuestSamplerResource.cpp validating positive, negative, and combined primary/secondary LOD bias decoding, differing min/mag filter assignment under unnormalized coordinates, and clamp mode 0 mapping to clamp-to-edge. - Ran python tools/check_conventions.py --base origin/main with 0 findings. ### Checklist - [x] Depends on: none - [x] AI-assisted: yes - [x] Unblocks: PPSA15388 #4736
MarcZX10 commented 2026-10-13 13:10:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T13:10:21Z.

Review: COMMENTED


Reviewed the descriptor decode against AMD’s published sampler resource layout: LOD_BIAS_SEC is signed S1.4 and is added after primary LOD bias, so the bit decode and additive path look correct. The unnormalized remaps also satisfy Vulkan’s sampler-create requirements. One gap in the new tests: all secondary-bias assertions use normalized coordinates, while DecodeSamplerResource intentionally zeroes the result.lodBias for FORCE_UNNORMALIZED; please add an unnormalized case with nonzero LOD_BIAS_SEC (and ideally both biases) asserting that the host bias is zero, so that deliberate loss is locked in and documented as an approximation. Also, since LOD_BIAS_SEC is documented as applying after primary bias, please confirm whether Vulkan/device mip-bias clamping at maxSamplerLodBias can alter the sum; if so, could note this limit in debt docs. The issue report currently calls the HoL workaround guesses, so a runtime confirmation against the reported scene would strengthen the behavior claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5504016063 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#pullrequestreview-5504016063). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T13:10:21Z. **Review:** COMMENTED --- Reviewed the descriptor decode against AMD’s published sampler resource layout: LOD_BIAS_SEC is signed S1.4 and is added after primary LOD bias, so the bit decode and additive path look correct. The unnormalized remaps also satisfy Vulkan’s sampler-create requirements. One gap in the new tests: all secondary-bias assertions use normalized coordinates, while DecodeSamplerResource intentionally zeroes the result.lodBias for FORCE_UNNORMALIZED; please add an unnormalized case with nonzero LOD_BIAS_SEC (and ideally both biases) asserting that the host bias is zero, so that deliberate loss is locked in and documented as an approximation. Also, since LOD_BIAS_SEC is documented as applying after primary bias, please confirm whether Vulkan/device mip-bias clamping at maxSamplerLodBias can alter the sum; if so, could note this limit in debt docs. The issue report currently calls the HoL workaround guesses, so a runtime confirmation against the reported scene would strengthen the behavior claim.
pushkarreddyy commented 2026-10-13 13:54:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-13T13:54:12Z.


@MarcZX100 Thanks for the review! Addressed all points in updated commit ae96ad5f4:

  1. Unnormalized Bias Test:
    Added a dedicated unnormalized test case with non-zero primary (lodBiasRaw = 256) and secondary (lodBiasSec = 8) LOD bias in GuestSamplerResource.cpp, asserting that host result.lodBias remains 0.0f to explicitly lock in and document that deliberate approximation.

  2. maxSamplerLodBias Debt Documentation:
    Updated docs/dev/debt/libSceAgcDriver.md to document that host VkSamplerCreateInfo::mipLodBias clamps to device maxSamplerLodBias (typically 15.0 to 16.0), whereas GFX10 adds secondary bias post-clamp or inside hardware register limits, so any combined sum exceeding host maxSamplerLodBias will be clamped by Vulkan.

  3. Conventions & CI:
    Passes python tools/check_conventions.py --base origin/main with 0 findings and 0 errors.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147159731 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6147159731). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-13T13:54:12Z. --- @MarcZX100 Thanks for the review! Addressed all points in updated commit `ae96ad5f4`: 1. **Unnormalized Bias Test**: Added a dedicated unnormalized test case with non-zero primary (`lodBiasRaw = 256`) and secondary (`lodBiasSec = 8`) LOD bias in `GuestSamplerResource.cpp`, asserting that host `result.lodBias` remains `0.0f` to explicitly lock in and document that deliberate approximation. 2. **`maxSamplerLodBias` Debt Documentation**: Updated `docs/dev/debt/libSceAgcDriver.md` to document that host `VkSamplerCreateInfo::mipLodBias` clamps to device `maxSamplerLodBias` (typically 15.0 to 16.0), whereas GFX10 adds secondary bias post-clamp or inside hardware register limits, so any combined sum exceeding host `maxSamplerLodBias` will be clamped by Vulkan. 3. **Conventions & CI**: Passes `python tools/check_conventions.py --base origin/main` with 0 findings and 0 errors.
MarcZX10 commented 2026-10-13 19:16:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:16:23Z.


Thanks for the update. I reviewed the revised diff: the new unnormalized case covers nonzero primary and secondary bias, and the debt entry records the host maxSamplerLodBias clamp, so both requested follow-ups are addressed. I have not run the reported title scene; that runtime evidence remains as reported by the issue author.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153257395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6153257395). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T19:16:23Z. --- Thanks for the update. I reviewed the revised diff: the new unnormalized case covers nonzero primary and secondary bias, and the debt entry records the host maxSamplerLodBias clamp, so both requested follow-ups are addressed. I have not run the reported title scene; that runtime evidence remains as reported by the issue author.
Tamalero commented 2026-10-13 21:01:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T21:01:54Z.


Validated in High on Life (PPSA15388), as asked on #4736. On main 18c438b10 plus #4487 and this PR (ae96ad5f4), the home base loads and renders with no sampler aborts. This PR replaced my three local workarounds for the same three stops, and they used the same maths. The scene renders as it did with the workarounds.

One test fails with this PR on main: agc_driver_image_sample_unnormalized (tests/execution/ImageSampleUnnormalized.cpp). It still expects these samplers to be refused:

unequal minification and magnification filters was accepted

Its ExpectFailure for an unnormalized S# with clamp mode 0 ("wrap on X") will fail the same way, so both cases need to become positive checks. Locally I compared each sample against the same S# with the magnification filter, or with clamp mode 2.

Two more unnormalized-sampler stops in the same scenes are outside this PR. I worked around both locally, unmeasured:

  • a sampler combining a min or max reduction with anisotropic filtering: guest sampler descriptor combines a min or max reduction with anisotropic filtering, which is not implemented;
  • a 9-level view read through an unnormalized S# by a sample other than image_sample_lz, #1418's single-level limit: guest texture sampled with unnormalized coordinates is not a single-layer 1D or 2D view ... (base level 0, levels 9, layers 1, view type 1).

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155124722 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6155124722). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-13T21:01:54Z. --- Validated in High on Life (PPSA15388), as asked on #4736. On `main` `18c438b10` plus #4487 and this PR (`ae96ad5f4`), the home base loads and renders with no sampler aborts. This PR replaced my three local workarounds for the same three stops, and they used the same maths. The scene renders as it did with the workarounds. One test fails with this PR on `main`: `agc_driver_image_sample_unnormalized` (`tests/execution/ImageSampleUnnormalized.cpp`). It still expects these samplers to be refused: ``` unequal minification and magnification filters was accepted ``` Its `ExpectFailure` for an unnormalized S# with clamp mode 0 ("wrap on X") will fail the same way, so both cases need to become positive checks. Locally I compared each sample against the same S# with the magnification filter, or with clamp mode 2. Two more unnormalized-sampler stops in the same scenes are outside this PR. I worked around both locally, unmeasured: - a sampler combining a min or max reduction with anisotropic filtering: `guest sampler descriptor combines a min or max reduction with anisotropic filtering, which is not implemented`; - a 9-level view read through an unnormalized S# by a sample other than `image_sample_lz`, `#1418`'s single-level limit: `guest texture sampled with unnormalized coordinates is not a single-layer 1D or 2D view ... (base level 0, levels 9, layers 1, view type 1)`. *Tested and written by Claude (AI assistant) on a contributor's machine.*
Tamalero commented 2026-10-13 21:10:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T21:10:33Z.


Hardware measurements for this PR's three cases, from tools/hw-oracle on an RDNA2 card: a Radeon PRO V620 (gfx1030), ROCm 6.3.3. Each probe is a compute shader that builds its own T# and S# in SGPRs over a 64×64 32_FLOAT linear texture held in the oracle's extra input bytes, then reads back image_sample_l and implicit image_sample. The script is below.

Case This PR gfx1030
Unnormalized S#, XY_MAG_FILTER ≠ XY_MIN_FILTER uses the mag filter for both Confirmed. The mag filter decides, for _l at LOD 0 and for implicit LOD. Mag point / min bilinear returns point results; mag bilinear / min point returns bilinear.
Unnormalized S#, clamp mode 0 (wrap) clamp-to-edge Confirmed. u = 74.5 on a 64-wide texture reads texel 63, and u = −10.5 reads texel 0.
Unnormalized S#, mirror (1) and mirror-once (3) not covered Both behave as mirror-once: u = −10.5 reads texel 10, and u = 74.5 reads texel 63.
LOD_BIAS_SEC (word 2, bits 14–19) signed 2.4, added to LOD_BIAS No effect. Values 0x01–0x3f (incl. 0x10, 0x1f, 0x20, 0x3f), alone or with LOD_BIAS, leave the effective LOD unchanged for _l and for implicit LOD. LOD_BIAS itself is s5.8 and applies to both: 0x40 = +0.25, 0x80 = +0.5, 0x3fc0 = −0.25.

How the LOD was read: the texture has 2 levels, and on gfx1030 a linear texture's levels share one base address with the same pitch. Each texel holds its own index. At uv = 32.5/64, mip 0 reads 2080 and mip 1 reads 1040. Min/mag are point and the mip filter is linear, so the effective LOD = (2080 − result) / 1040. Implicit LOD came from 2×2 quads stepped 1, 2^0.25 and 2^0.5 texels apart; they gave LOD 0, 0.25 and 0.5 before any bias.

So on this card the secondary bias should be accepted and ignored, not added. A native PS5 readout would settle whether the PS5 differs.

Related data for #1418's limit (cc @gjonn): on a 2-level view, unnormalized coordinates do select the level. An explicit LOD of 1 reads mip 1, and an implicit LOD from a 2-texel quad step reads mip 1 too, in mip 1's own texel coordinates. "Samples the base level" holds only for single-level views, which is the restriction #1418 keeps. I had a local approximation that bound such views at their base level; it is wrong and I'm dropping it.

Min/max reduction with anisotropic filters, partial: with zero derivatives, FILTER_MODE min or max with aniso-linear (3, ratio 2) returns exactly the bilinear min/max, and aniso-point returns the point result. This doesn't test a real anisotropic footprint.

Caveats: gfx1030 is RDNA2 and the PS5 GPU is a related custom part. These are compute-shader samples of a linear texture.

Probe script (put it in the checkout root and run python3 sampler_probe.py <probe>)
#!/usr/bin/env python3
"""Measure GFX10.3 sampler semantics with tools/hw-oracle: LOD_BIAS_SEC, and unnormalized
coordinates with unequal min/mag filters and with wrapping clamp modes."""
import struct, sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent / "tools/hw-oracle"))
import hw_oracle

MODES = dict(ieee=1, denorm32=3, denorm16=3, dx10_clamp=1, round32=0, round16=0, fp16_overflow=0)
W = H = 64

def f2u(x): return struct.unpack("<I", struct.pack("<f", x))[0]
def u2f(u): return struct.unpack("<f", struct.pack("<I", u))[0]

def tsharp(last_level):
    d1 = (22 << 20) | (((W - 1) & 3) << 30)                 # format 32_FLOAT, width low bits
    d2 = ((W - 1) >> 2) | ((H - 1) << 14)
    d3 = 0xfac | (0 << 12) | (last_level << 16) | (0 << 20) | (9 << 28)  # dst_sel RGBA, levels, SW_LINEAR, 2D
    d4 = (W - 1)                                             # pitch - 1 for a 2D linear texture
    return d1, d2, d3, d4

def body(t, s, ops):
    d1, d2, d3, d4 = t
    lines = [
        "  s_add_u32 s8, s4, 1024", "  s_addc_u32 s9, s5, 0", "  s_lshr_b64 s[8:9], s[8:9], 8",
        "  s_and_b32 s9, s9, 0xff", f"  s_or_b32 s9, s9, 0x{d1:08x}",
        f"  s_mov_b32 s10, 0x{d2:08x}", f"  s_mov_b32 s11, 0x{d3:08x}", f"  s_mov_b32 s12, 0x{d4:08x}",
        "  s_mov_b32 s13, 0", "  s_mov_b32 s14, 0", "  s_mov_b32 s15, 0",
        f"  s_mov_b32 s16, 0x{s[0]:08x}", f"  s_mov_b32 s17, 0x{s[1]:08x}", f"  s_mov_b32 s18, 0x{s[2]:08x}", f"  s_mov_b32 s19, 0x{s[3]:08x}",
    ]
    lines += ops + ["  s_waitcnt vmcnt(0)"]
    return "\n".join(lines) + "\n"

SAMPLE_L = "  image_sample_l v[10:13], v[4:6], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_2D"
SAMPLE = "  image_sample v[14:17], v[4:5], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_2D"

def run(t, s, rows, extra, ops=(SAMPLE_L, SAMPLE)):
    rows = rows + [(0, 0, 0, 0)] * (64 - len(rows))
    out = hw_oracle.run(body(t, s, list(ops)), rows, extra, wave64=True, **MODES)
    return out

def mip_texture():
    # mip 0 = 0.0, everything after it = 1.0 (so the result reads the effective LOD under linear mip filtering)
    return struct.pack(f"<{W*H}f", *([0.0] * (W * H))) + struct.pack(f"<{W*H}f", *([1.0] * (W * H)))

def ramp_texture():
    return struct.pack(f"<{W*H}f", *[float(x) for y in range(H) for x in range(W)])

def lod_bias_sec():
    print("== LOD_BIAS_SEC (word2 bits 14-19); mip0=0, mip1=1, bilinear + linear mip; result = effective LOD clamped to [0,1]")
    t = tsharp(1)
    lods = [0.0, 0.25, 0.5]
    rows = [(f2u(0.5), f2u(0.5), f2u(l), 0) for l in lods]
    for label, bias, sec in [("none", 0, 0), ("LOD_BIAS=0x40 (0.25 if s5.8)", 0x40, 0), ("SEC=1", 0, 1), ("SEC=4", 0, 4),
                             ("SEC=8", 0, 8), ("SEC=0x10", 0, 0x10), ("SEC=0x1f", 0, 0x1f), ("SEC=0x20", 0, 0x20),
                             ("SEC=0x30", 0, 0x30), ("SEC=0x3f", 0, 0x3f), ("LOD_BIAS=0x40+SEC=4", 0x40, 4)]:
        s = (0x92, 0x00fff000, bias | (sec << 14) | (1 << 20) | (1 << 22) | (2 << 26), 0)
        out = run(t, s, rows, mip_texture())
        res = "  ".join(f"lod {l:.2f}: _l {u2f(o[0]):.4f} implicit {u2f(o[4]):.4f}" for l, o in zip(lods, out))
        print(f"  {label:28s} {res}")

def unnormalized_filters():
    print("== FORCE_UNNORMALIZED, min vs mag filter; texel x holds x; sample u between texel centres")
    t = tsharp(0)
    us = [10.75, 10.5, 10.25]
    rows = [(f2u(u), f2u(5.5), f2u(0.0), 0) for u in us]
    for label, mag, mn in [("mag point, min point", 0, 0), ("mag bilinear, min bilinear", 1, 1),
                           ("mag point, min bilinear", 0, 1), ("mag bilinear, min point", 1, 0)]:
        s = (0x92 | 0x8000, 0x00000000, (mag << 20) | (mn << 22), 0)
        out = run(t, s, rows, ramp_texture())
        res = "  ".join(f"u {u}: _l {u2f(o[0]):.4f} implicit {u2f(o[4]):.4f}" for u, o in zip(us, out))
        print(f"  {label:28s} {res}")

def unnormalized_wrap():
    print("== FORCE_UNNORMALIZED, clamp modes on X; point filter; width 64")
    t = tsharp(0)
    us = [10.5, 64.0 + 10.5, -0.5 - 10.0, 63.5, 64.5]
    rows = [(f2u(u), f2u(5.5), f2u(0.0), 0) for u in us]
    for label, clamp in [("0 wrap", 0), ("1 mirror", 1), ("2 clamp last texel", 2), ("3 mirror once last texel", 3), ("6 clamp border", 6)]:
        s = (clamp | (2 << 3) | (2 << 6) | 0x8000, 0x00000000, 0, 0)
        out = run(t, s, rows, ramp_texture())
        res = "  ".join(f"u {u}: {u2f(o[0]):.4f}" for u, o in zip(us, out))
        print(f"  {label:28s} {res}")


def mip_layout():
    print("== linear 64x64 R32F, 2 levels: every dword holds its index; point mip filter; where does mip 1 read from?")
    t = tsharp(1)
    data = struct.pack("<16384f", *[float(i) for i in range(16384)])
    pts = [(0.5 / 32, 0.5 / 32), (1.5 / 32, 0.5 / 32), (0.5 / 32, 1.5 / 32), (0.5, 0.5)]
    for lod in (0.0, 1.0):
        rows = [(f2u(u), f2u(v), f2u(lod), 0) for u, v in pts]
        s = (0x92, 0x00fff000, (0 << 20) | (0 << 22) | (1 << 26), 0)
        out = run(t, s, rows, data, ops=(SAMPLE_L,))
        print(f"  lod {lod}: " + "  ".join(f"({u:.4f},{v:.4f}) -> {u2f(o[0]):.0f}" for (u, v), o in zip(pts, out)))
    for mipf in (0, 1, 2, 3):
        rows = [(f2u(0.5 / 32), f2u(0.5 / 32), f2u(1.0), 0)]
        s = (0x92, 0x00fff000, (mipf << 26), 0)
        out = run(t, s, rows, data, ops=(SAMPLE_L,))
        print(f"  MIP_FILTER {mipf}: lod 1 at texel (0,0) of mip 1 -> {u2f(out[0][0]):.0f}")

def lod_bias_sec2():
    print("== LOD_BIAS / LOD_BIAS_SEC on gfx1030: linear 64x64 R32F, 2 levels sharing one base; texel = its index;")
    print("   point min/mag, LINEAR mip filter; uv=32.5/64 reads 2080 at mip 0 and 1040 at mip 1 => effective LOD = (2080-r)/1040")
    t = tsharp(1)
    data = struct.pack("<16384f", *[float(i) for i in range(16384)])
    lods = [0.0, 0.25, 0.5]
    uv = f2u(32.5 / 64)
    rows = [(uv, uv, f2u(l), 0) for l in lods]
    cases = [("none", 0, 0), ("LOD_BIAS=0x40", 0x40, 0), ("LOD_BIAS=0x80", 0x80, 0), ("LOD_BIAS=0x3fc0 (-0.25 if s5.8)", 0x3fc0, 0),
             ("SEC=1", 0, 1), ("SEC=2", 0, 2), ("SEC=4", 0, 4), ("SEC=8", 0, 8), ("SEC=0x10", 0, 0x10), ("SEC=0x1f", 0, 0x1f),
             ("SEC=0x20", 0, 0x20), ("SEC=0x3c", 0, 0x3c), ("SEC=0x3f", 0, 0x3f), ("LOD_BIAS=0x40 + SEC=4", 0x40, 4)]
    for label, bias, sec in cases:
        s = (0x92, 0x00fff000, bias | (sec << 14) | (2 << 26), 0)
        out = run(t, s, rows, data)
        res = "  ".join(f"L={l:.2f}: _l {(2080 - u2f(o[0])) / 1040:.4f} impl {(2080 - u2f(o[4])) / 1040:.4f}" for l, o in zip(lods, out))
        print(f"  {label:32s} {res}")

SAMPLE_B = "  image_sample_b v[14:17], v[6:8], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_2D"

def lod_bias_sec_implicit():
    print("== implicit-LOD samples with real quad derivatives; lane 0 of each 2x2 quad at uv=32.5/64 (2080 at mip 0, 1040 at mip 1)")
    print("   quad step d texels in u and v => computed LOD ~ log2(d); effective LOD = (2080 - r0)/1040 (clamped to [0,1])")
    t = tsharp(1)
    data = struct.pack("<16384f", *[float(i) for i in range(16384)])
    def quad(d):
        b = 32.5 / 64; e = d / 64
        return [(f2u(b), f2u(b), 0, 0), (f2u(b + e), f2u(b), 0, 0), (f2u(b), f2u(b + e), 0, 0), (f2u(b + e), f2u(b + e), 0, 0)]
    ds = [1.0, 2 ** 0.25, 2 ** 0.5]
    rows = sum((quad(d) for d in ds), [])
    cases = [("none", 0, 0), ("LOD_BIAS=0x40", 0x40, 0), ("SEC=1", 0, 1), ("SEC=4", 0, 4), ("SEC=8", 0, 8), ("SEC=0x10", 0, 0x10),
             ("SEC=0x1f", 0, 0x1f), ("SEC=0x20", 0, 0x20), ("SEC=0x30", 0, 0x30), ("SEC=0x3c", 0, 0x3c), ("SEC=0x3f", 0, 0x3f)]
    for label, bias, sec in cases:
        s = (0x92, 0x00fff000, bias | (sec << 14) | (2 << 26), 0)
        out = run(t, s, rows, data, ops=(SAMPLE,))
        res = "  ".join(f"d={d:.3f}: {(2080 - u2f(out[4 * k][4])) / 1040:.4f}" for k, d in enumerate(ds))
        print(f"  {label:20s} {res}")

def unnormalized_levels():
    print("== FORCE_UNNORMALIZED on a 2-level view (levels share one base): does an explicit LOD 1 read mip 1 or the base level?")
    print("   texel = its index; point filters, mip filter point/linear; u=v=10.5 reads 650 at mip 0; mip 1 at (10,10) would read 650 too,")
    print("   so use u=v=40.5: mip 0 texel (40,40)=2600; mip 1 (32x32) would clamp to (31,31)=2015")
    t = tsharp(1)
    data = struct.pack("<16384f", *[float(i) for i in range(16384)])
    rows = [(f2u(40.5), f2u(40.5), f2u(l), 0) for l in (0.0, 1.0, 2.0)]
    for mipf in (1, 2):
        s = (0x92 | 0x8000, 0x00fff000, (mipf << 26), 0)
        out = run(t, s, rows, data, ops=(SAMPLE_L,))
        print(f"  MIP_FILTER {mipf}: " + "  ".join(f"lod {l}: {u2f(o[0]):.0f}" for l, o in zip((0.0, 1.0, 2.0), out)))

def reduction_aniso():
    print("== min/max reduction (word0 FILTER_MODE bits 29-30) with anisotropic filters (2/3) vs bilinear; ramp texel=x")
    t = tsharp(0)
    us = [10.75, 10.25]
    rows = [(f2u(u / 64), f2u(5.5 / 64), f2u(0.0), 0) for u in us]
    for label, mode, filt, ratio in [("blend bilinear", 0, 1, 0), ("min bilinear", 1, 1, 0), ("max bilinear", 2, 1, 0),
                                     ("min aniso-linear x2", 1, 3, 1), ("max aniso-linear x2", 2, 3, 1), ("min aniso-point x2", 1, 2, 1)]:
        s = (0x92 | (ratio << 9) | (mode << 29), 0x00fff000, (filt << 20) | (filt << 22), 0)
        out = run(t, s, rows, ramp_texture(), ops=(SAMPLE_L,))
        print(f"  {label:22s} " + "  ".join(f"u {u}: {u2f(o[0]):.4f}" for u, o in zip(us, out)))

def unnormalized_levels_implicit():
    print("== FORCE_UNNORMALIZED, 2-level view, IMPLICIT LOD with quad steps of d texels; lane 0 at u=v=40.5 (2600 base, 2015 mip 1)")
    t = tsharp(1)
    data = struct.pack("<16384f", *[float(i) for i in range(16384)])
    def quad(d):
        b = 40.5
        return [(f2u(b), f2u(b), 0, 0), (f2u(b + d), f2u(b), 0, 0), (f2u(b), f2u(b + d), 0, 0), (f2u(b + d), f2u(b + d), 0, 0)]
    ds = [1.0, 2.0, 4.0]
    rows = sum((quad(d) for d in ds), [])
    for mipf in (1, 2):
        s = (0x92 | 0x8000, 0x00fff000, (mipf << 26), 0)
        out = run(t, s, rows, data, ops=(SAMPLE,))
        print(f"  MIP_FILTER {mipf}: " + "  ".join(f"d={d}: {u2f(out[4 * k][4]):.0f}" for k, d in enumerate(ds)))

if __name__ == "__main__":
    print("target:", hw_oracle.target())
    for name in sys.argv[1:] or ["lod_bias_sec", "unnormalized_filters", "unnormalized_wrap"]:
        globals()[name]()

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155265616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6155265616). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-13T21:10:33Z. --- Hardware measurements for this PR's three cases, from `tools/hw-oracle` on an RDNA2 card: a Radeon PRO V620 (gfx1030), ROCm 6.3.3. Each probe is a compute shader that builds its own T# and S# in SGPRs over a 64×64 `32_FLOAT` linear texture held in the oracle's extra input bytes, then reads back `image_sample_l` and implicit `image_sample`. The script is below. | Case | This PR | gfx1030 | |---|---|---| | Unnormalized S#, `XY_MAG_FILTER` ≠ `XY_MIN_FILTER` | uses the mag filter for both | **Confirmed.** The mag filter decides, for `_l` at LOD 0 and for implicit LOD. Mag point / min bilinear returns point results; mag bilinear / min point returns bilinear. | | Unnormalized S#, clamp mode 0 (wrap) | clamp-to-edge | **Confirmed.** u = 74.5 on a 64-wide texture reads texel 63, and u = −10.5 reads texel 0. | | Unnormalized S#, mirror (1) and mirror-once (3) | not covered | Both behave as **mirror-once**: u = −10.5 reads texel 10, and u = 74.5 reads texel 63. | | `LOD_BIAS_SEC` (word 2, bits 14–19) | signed 2.4, added to `LOD_BIAS` | **No effect.** Values 0x01–0x3f (incl. 0x10, 0x1f, 0x20, 0x3f), alone or with `LOD_BIAS`, leave the effective LOD unchanged for `_l` and for implicit LOD. `LOD_BIAS` itself is s5.8 and applies to both: 0x40 = +0.25, 0x80 = +0.5, 0x3fc0 = −0.25. | How the LOD was read: the texture has 2 levels, and on gfx1030 a linear texture's levels share one base address with the same pitch. Each texel holds its own index. At uv = 32.5/64, mip 0 reads 2080 and mip 1 reads 1040. Min/mag are point and the mip filter is linear, so the effective LOD = (2080 − result) / 1040. Implicit LOD came from 2×2 quads stepped 1, 2^0.25 and 2^0.5 texels apart; they gave LOD 0, 0.25 and 0.5 before any bias. So on this card the secondary bias should be **accepted and ignored**, not added. A native PS5 readout would settle whether the PS5 differs. Related data for #1418's limit (cc @gjonn): on a 2-level view, unnormalized coordinates do select the level. An explicit LOD of 1 reads mip 1, and an implicit LOD from a 2-texel quad step reads mip 1 too, in mip 1's own texel coordinates. "Samples the base level" holds only for single-level views, which is the restriction #1418 keeps. I had a local approximation that bound such views at their base level; it is wrong and I'm dropping it. Min/max reduction with anisotropic filters, partial: with zero derivatives, `FILTER_MODE` min or max with aniso-linear (3, ratio 2) returns exactly the bilinear min/max, and aniso-point returns the point result. This doesn't test a real anisotropic footprint. Caveats: gfx1030 is RDNA2 and the PS5 GPU is a related custom part. These are compute-shader samples of a linear texture. <details><summary>Probe script (put it in the checkout root and run <code>python3 sampler_probe.py &lt;probe&gt;</code>)</summary> ```python #!/usr/bin/env python3 """Measure GFX10.3 sampler semantics with tools/hw-oracle: LOD_BIAS_SEC, and unnormalized coordinates with unequal min/mag filters and with wrapping clamp modes.""" import struct, sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent / "tools/hw-oracle")) import hw_oracle MODES = dict(ieee=1, denorm32=3, denorm16=3, dx10_clamp=1, round32=0, round16=0, fp16_overflow=0) W = H = 64 def f2u(x): return struct.unpack("<I", struct.pack("<f", x))[0] def u2f(u): return struct.unpack("<f", struct.pack("<I", u))[0] def tsharp(last_level): d1 = (22 << 20) | (((W - 1) & 3) << 30) # format 32_FLOAT, width low bits d2 = ((W - 1) >> 2) | ((H - 1) << 14) d3 = 0xfac | (0 << 12) | (last_level << 16) | (0 << 20) | (9 << 28) # dst_sel RGBA, levels, SW_LINEAR, 2D d4 = (W - 1) # pitch - 1 for a 2D linear texture return d1, d2, d3, d4 def body(t, s, ops): d1, d2, d3, d4 = t lines = [ " s_add_u32 s8, s4, 1024", " s_addc_u32 s9, s5, 0", " s_lshr_b64 s[8:9], s[8:9], 8", " s_and_b32 s9, s9, 0xff", f" s_or_b32 s9, s9, 0x{d1:08x}", f" s_mov_b32 s10, 0x{d2:08x}", f" s_mov_b32 s11, 0x{d3:08x}", f" s_mov_b32 s12, 0x{d4:08x}", " s_mov_b32 s13, 0", " s_mov_b32 s14, 0", " s_mov_b32 s15, 0", f" s_mov_b32 s16, 0x{s[0]:08x}", f" s_mov_b32 s17, 0x{s[1]:08x}", f" s_mov_b32 s18, 0x{s[2]:08x}", f" s_mov_b32 s19, 0x{s[3]:08x}", ] lines += ops + [" s_waitcnt vmcnt(0)"] return "\n".join(lines) + "\n" SAMPLE_L = " image_sample_l v[10:13], v[4:6], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_2D" SAMPLE = " image_sample v[14:17], v[4:5], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_2D" def run(t, s, rows, extra, ops=(SAMPLE_L, SAMPLE)): rows = rows + [(0, 0, 0, 0)] * (64 - len(rows)) out = hw_oracle.run(body(t, s, list(ops)), rows, extra, wave64=True, **MODES) return out def mip_texture(): # mip 0 = 0.0, everything after it = 1.0 (so the result reads the effective LOD under linear mip filtering) return struct.pack(f"<{W*H}f", *([0.0] * (W * H))) + struct.pack(f"<{W*H}f", *([1.0] * (W * H))) def ramp_texture(): return struct.pack(f"<{W*H}f", *[float(x) for y in range(H) for x in range(W)]) def lod_bias_sec(): print("== LOD_BIAS_SEC (word2 bits 14-19); mip0=0, mip1=1, bilinear + linear mip; result = effective LOD clamped to [0,1]") t = tsharp(1) lods = [0.0, 0.25, 0.5] rows = [(f2u(0.5), f2u(0.5), f2u(l), 0) for l in lods] for label, bias, sec in [("none", 0, 0), ("LOD_BIAS=0x40 (0.25 if s5.8)", 0x40, 0), ("SEC=1", 0, 1), ("SEC=4", 0, 4), ("SEC=8", 0, 8), ("SEC=0x10", 0, 0x10), ("SEC=0x1f", 0, 0x1f), ("SEC=0x20", 0, 0x20), ("SEC=0x30", 0, 0x30), ("SEC=0x3f", 0, 0x3f), ("LOD_BIAS=0x40+SEC=4", 0x40, 4)]: s = (0x92, 0x00fff000, bias | (sec << 14) | (1 << 20) | (1 << 22) | (2 << 26), 0) out = run(t, s, rows, mip_texture()) res = " ".join(f"lod {l:.2f}: _l {u2f(o[0]):.4f} implicit {u2f(o[4]):.4f}" for l, o in zip(lods, out)) print(f" {label:28s} {res}") def unnormalized_filters(): print("== FORCE_UNNORMALIZED, min vs mag filter; texel x holds x; sample u between texel centres") t = tsharp(0) us = [10.75, 10.5, 10.25] rows = [(f2u(u), f2u(5.5), f2u(0.0), 0) for u in us] for label, mag, mn in [("mag point, min point", 0, 0), ("mag bilinear, min bilinear", 1, 1), ("mag point, min bilinear", 0, 1), ("mag bilinear, min point", 1, 0)]: s = (0x92 | 0x8000, 0x00000000, (mag << 20) | (mn << 22), 0) out = run(t, s, rows, ramp_texture()) res = " ".join(f"u {u}: _l {u2f(o[0]):.4f} implicit {u2f(o[4]):.4f}" for u, o in zip(us, out)) print(f" {label:28s} {res}") def unnormalized_wrap(): print("== FORCE_UNNORMALIZED, clamp modes on X; point filter; width 64") t = tsharp(0) us = [10.5, 64.0 + 10.5, -0.5 - 10.0, 63.5, 64.5] rows = [(f2u(u), f2u(5.5), f2u(0.0), 0) for u in us] for label, clamp in [("0 wrap", 0), ("1 mirror", 1), ("2 clamp last texel", 2), ("3 mirror once last texel", 3), ("6 clamp border", 6)]: s = (clamp | (2 << 3) | (2 << 6) | 0x8000, 0x00000000, 0, 0) out = run(t, s, rows, ramp_texture()) res = " ".join(f"u {u}: {u2f(o[0]):.4f}" for u, o in zip(us, out)) print(f" {label:28s} {res}") def mip_layout(): print("== linear 64x64 R32F, 2 levels: every dword holds its index; point mip filter; where does mip 1 read from?") t = tsharp(1) data = struct.pack("<16384f", *[float(i) for i in range(16384)]) pts = [(0.5 / 32, 0.5 / 32), (1.5 / 32, 0.5 / 32), (0.5 / 32, 1.5 / 32), (0.5, 0.5)] for lod in (0.0, 1.0): rows = [(f2u(u), f2u(v), f2u(lod), 0) for u, v in pts] s = (0x92, 0x00fff000, (0 << 20) | (0 << 22) | (1 << 26), 0) out = run(t, s, rows, data, ops=(SAMPLE_L,)) print(f" lod {lod}: " + " ".join(f"({u:.4f},{v:.4f}) -> {u2f(o[0]):.0f}" for (u, v), o in zip(pts, out))) for mipf in (0, 1, 2, 3): rows = [(f2u(0.5 / 32), f2u(0.5 / 32), f2u(1.0), 0)] s = (0x92, 0x00fff000, (mipf << 26), 0) out = run(t, s, rows, data, ops=(SAMPLE_L,)) print(f" MIP_FILTER {mipf}: lod 1 at texel (0,0) of mip 1 -> {u2f(out[0][0]):.0f}") def lod_bias_sec2(): print("== LOD_BIAS / LOD_BIAS_SEC on gfx1030: linear 64x64 R32F, 2 levels sharing one base; texel = its index;") print(" point min/mag, LINEAR mip filter; uv=32.5/64 reads 2080 at mip 0 and 1040 at mip 1 => effective LOD = (2080-r)/1040") t = tsharp(1) data = struct.pack("<16384f", *[float(i) for i in range(16384)]) lods = [0.0, 0.25, 0.5] uv = f2u(32.5 / 64) rows = [(uv, uv, f2u(l), 0) for l in lods] cases = [("none", 0, 0), ("LOD_BIAS=0x40", 0x40, 0), ("LOD_BIAS=0x80", 0x80, 0), ("LOD_BIAS=0x3fc0 (-0.25 if s5.8)", 0x3fc0, 0), ("SEC=1", 0, 1), ("SEC=2", 0, 2), ("SEC=4", 0, 4), ("SEC=8", 0, 8), ("SEC=0x10", 0, 0x10), ("SEC=0x1f", 0, 0x1f), ("SEC=0x20", 0, 0x20), ("SEC=0x3c", 0, 0x3c), ("SEC=0x3f", 0, 0x3f), ("LOD_BIAS=0x40 + SEC=4", 0x40, 4)] for label, bias, sec in cases: s = (0x92, 0x00fff000, bias | (sec << 14) | (2 << 26), 0) out = run(t, s, rows, data) res = " ".join(f"L={l:.2f}: _l {(2080 - u2f(o[0])) / 1040:.4f} impl {(2080 - u2f(o[4])) / 1040:.4f}" for l, o in zip(lods, out)) print(f" {label:32s} {res}") SAMPLE_B = " image_sample_b v[14:17], v[6:8], s[8:15], s[16:19] dmask:0xf dim:SQ_RSRC_IMG_2D" def lod_bias_sec_implicit(): print("== implicit-LOD samples with real quad derivatives; lane 0 of each 2x2 quad at uv=32.5/64 (2080 at mip 0, 1040 at mip 1)") print(" quad step d texels in u and v => computed LOD ~ log2(d); effective LOD = (2080 - r0)/1040 (clamped to [0,1])") t = tsharp(1) data = struct.pack("<16384f", *[float(i) for i in range(16384)]) def quad(d): b = 32.5 / 64; e = d / 64 return [(f2u(b), f2u(b), 0, 0), (f2u(b + e), f2u(b), 0, 0), (f2u(b), f2u(b + e), 0, 0), (f2u(b + e), f2u(b + e), 0, 0)] ds = [1.0, 2 ** 0.25, 2 ** 0.5] rows = sum((quad(d) for d in ds), []) cases = [("none", 0, 0), ("LOD_BIAS=0x40", 0x40, 0), ("SEC=1", 0, 1), ("SEC=4", 0, 4), ("SEC=8", 0, 8), ("SEC=0x10", 0, 0x10), ("SEC=0x1f", 0, 0x1f), ("SEC=0x20", 0, 0x20), ("SEC=0x30", 0, 0x30), ("SEC=0x3c", 0, 0x3c), ("SEC=0x3f", 0, 0x3f)] for label, bias, sec in cases: s = (0x92, 0x00fff000, bias | (sec << 14) | (2 << 26), 0) out = run(t, s, rows, data, ops=(SAMPLE,)) res = " ".join(f"d={d:.3f}: {(2080 - u2f(out[4 * k][4])) / 1040:.4f}" for k, d in enumerate(ds)) print(f" {label:20s} {res}") def unnormalized_levels(): print("== FORCE_UNNORMALIZED on a 2-level view (levels share one base): does an explicit LOD 1 read mip 1 or the base level?") print(" texel = its index; point filters, mip filter point/linear; u=v=10.5 reads 650 at mip 0; mip 1 at (10,10) would read 650 too,") print(" so use u=v=40.5: mip 0 texel (40,40)=2600; mip 1 (32x32) would clamp to (31,31)=2015") t = tsharp(1) data = struct.pack("<16384f", *[float(i) for i in range(16384)]) rows = [(f2u(40.5), f2u(40.5), f2u(l), 0) for l in (0.0, 1.0, 2.0)] for mipf in (1, 2): s = (0x92 | 0x8000, 0x00fff000, (mipf << 26), 0) out = run(t, s, rows, data, ops=(SAMPLE_L,)) print(f" MIP_FILTER {mipf}: " + " ".join(f"lod {l}: {u2f(o[0]):.0f}" for l, o in zip((0.0, 1.0, 2.0), out))) def reduction_aniso(): print("== min/max reduction (word0 FILTER_MODE bits 29-30) with anisotropic filters (2/3) vs bilinear; ramp texel=x") t = tsharp(0) us = [10.75, 10.25] rows = [(f2u(u / 64), f2u(5.5 / 64), f2u(0.0), 0) for u in us] for label, mode, filt, ratio in [("blend bilinear", 0, 1, 0), ("min bilinear", 1, 1, 0), ("max bilinear", 2, 1, 0), ("min aniso-linear x2", 1, 3, 1), ("max aniso-linear x2", 2, 3, 1), ("min aniso-point x2", 1, 2, 1)]: s = (0x92 | (ratio << 9) | (mode << 29), 0x00fff000, (filt << 20) | (filt << 22), 0) out = run(t, s, rows, ramp_texture(), ops=(SAMPLE_L,)) print(f" {label:22s} " + " ".join(f"u {u}: {u2f(o[0]):.4f}" for u, o in zip(us, out))) def unnormalized_levels_implicit(): print("== FORCE_UNNORMALIZED, 2-level view, IMPLICIT LOD with quad steps of d texels; lane 0 at u=v=40.5 (2600 base, 2015 mip 1)") t = tsharp(1) data = struct.pack("<16384f", *[float(i) for i in range(16384)]) def quad(d): b = 40.5 return [(f2u(b), f2u(b), 0, 0), (f2u(b + d), f2u(b), 0, 0), (f2u(b), f2u(b + d), 0, 0), (f2u(b + d), f2u(b + d), 0, 0)] ds = [1.0, 2.0, 4.0] rows = sum((quad(d) for d in ds), []) for mipf in (1, 2): s = (0x92 | 0x8000, 0x00fff000, (mipf << 26), 0) out = run(t, s, rows, data, ops=(SAMPLE,)) print(f" MIP_FILTER {mipf}: " + " ".join(f"d={d}: {u2f(out[4 * k][4]):.0f}" for k, d in enumerate(ds))) if __name__ == "__main__": print("target:", hw_oracle.target()) for name in sys.argv[1:] or ["lod_bias_sec", "unnormalized_filters", "unnormalized_wrap"]: globals()[name]() ``` </details> *Tested and written by Claude (AI assistant) on a contributor's machine.*
simonbbby commented 2026-10-13 21:26:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T21:26:19Z.


Independent confirmation on RDNA2 gfx1036, PCI 1002:13c0 (Ryzen 9950X integrated GPU), Linux, HSA runtime 5.7.1-2build1. This is hardware-oracle evidence for the semantics in head ae96ad5f454, not a title run or a full PR test.

I ran the public probe above (mip_layout, lod_bias_sec2, lod_bias_sec_implicit, unnormalized_filters, unnormalized_wrap), then extended it with assertions:

  • Every nonzero LOD_BIAS_SEC value 0x01..0x3f, both alone and combined with primary LOD_BIAS=0x40, left the raw sampled words bit-identical to the corresponding SEC=0 control. Tested explicit image_sample_l at LOD 0/0.25/0.5 and implicit image_sample with 2×2 quad steps 1/2^0.25/2^0.5. Wave32 and wave64, three repeats each: 756 secondary-bias configurations.
  • Primary bias controls changed the measured LOD as expected for both sample instructions: 0x40 added 0.25, 0x80 added 0.5, and 0x3fc0 subtracted 0.25, with clamping at zero/one in this two-level fixture. The ramp-layout controls read 2080 at mip 0 and 1040 at mip 1. This rules out a fixture that simply cannot observe bias.
  • Unequal unnormalized filters used the magnification filter for both instructions. At u=10.75/10.5/10.25, mag point returned 10/10/10; mag bilinear returned 10.25/10/9.75 regardless of min filter.
  • Unnormalized clamp modes 0 and 2 agreed at u=74.5 and −10.5: 63 and 0. Modes 1 and 3 agreed at those coordinates: 63 and 10. Filter/clamp assertions also passed three times in each wave size.

Same FP modes as the supplied script: IEEE=1, denorm32=3, denorm16=3, DX10_CLAMP=1, both rounding modes=0, FP16 overflow=0.

This independently supports the unnormalized remaps, but contradicts adding signed secondary bias for these normalized compute samples on a second RDNA2 GPU. The decoder tests that assert the sum should be reconciled with this evidence before merging. Native PS5 behavior and other texture layouts/stages remain unmeasured here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155544985 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6155544985). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-13T21:26:19Z. --- Independent confirmation on RDNA2 **gfx1036**, PCI `1002:13c0` (Ryzen 9950X integrated GPU), Linux, HSA runtime `5.7.1-2build1`. This is hardware-oracle evidence for the semantics in head `ae96ad5f454`, not a title run or a full PR test. I ran the public probe above (`mip_layout`, `lod_bias_sec2`, `lod_bias_sec_implicit`, `unnormalized_filters`, `unnormalized_wrap`), then extended it with assertions: - Every nonzero `LOD_BIAS_SEC` value `0x01..0x3f`, both alone and combined with primary `LOD_BIAS=0x40`, **left the raw sampled words bit-identical to the corresponding SEC=0 control**. Tested explicit `image_sample_l` at LOD 0/0.25/0.5 and implicit `image_sample` with 2×2 quad steps 1/2^0.25/2^0.5. Wave32 and wave64, three repeats each: **756 secondary-bias configurations**. - Primary bias controls changed the measured LOD as expected for both sample instructions: `0x40` added 0.25, `0x80` added 0.5, and `0x3fc0` subtracted 0.25, with clamping at zero/one in this two-level fixture. The ramp-layout controls read 2080 at mip 0 and 1040 at mip 1. This rules out a fixture that simply cannot observe bias. - Unequal unnormalized filters used the **magnification** filter for both instructions. At u=10.75/10.5/10.25, mag point returned 10/10/10; mag bilinear returned 10.25/10/9.75 regardless of min filter. - Unnormalized clamp modes 0 and 2 agreed at u=74.5 and −10.5: 63 and 0. Modes 1 and 3 agreed at those coordinates: 63 and 10. Filter/clamp assertions also passed three times in each wave size. Same FP modes as the supplied script: IEEE=1, denorm32=3, denorm16=3, DX10_CLAMP=1, both rounding modes=0, FP16 overflow=0. This independently supports the unnormalized remaps, but contradicts adding signed secondary bias for these normalized compute samples on a second RDNA2 GPU. The decoder tests that assert the sum should be reconciled with this evidence before merging. Native PS5 behavior and other texture layouts/stages remain unmeasured here.
MarcZX10 commented 2026-10-13 22:05:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T22:05:46Z.

Review: COMMENTED


I need to revise my earlier review of the secondary-bias arithmetic. I had relied on the descriptor-field interpretation, but the new gfx1030 and independent gfx1036 oracle runs are stronger evidence for this path: nonzero LOD_BIAS_SEC had no measurable effect across explicit and implicit samples, with primary LOD_BIAS controls proving the fixture could observe bias.

The PR currently adds the signed secondary value to result.lodBias, and its decoder tests assert that sum. The High on Life run establishes that accepting the descriptor gets past the sampler abort and renders the scene; it does not establish that the console applies this arithmetic. Could you reconcile the implementation and tests with the two oracle results, or identify a PS5-specific/stage/layout distinction that explains them? Until then, I don't consider LOD_BIAS_SEC addition validated. The unnormalized filter and clamp remaps have separate supporting oracle evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5510573134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#pullrequestreview-5510573134). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T22:05:46Z. **Review:** COMMENTED --- I need to revise my earlier review of the secondary-bias arithmetic. I had relied on the descriptor-field interpretation, but the new gfx1030 and independent gfx1036 oracle runs are stronger evidence for this path: nonzero `LOD_BIAS_SEC` had no measurable effect across explicit and implicit samples, with primary `LOD_BIAS` controls proving the fixture could observe bias. The PR currently adds the signed secondary value to `result.lodBias`, and its decoder tests assert that sum. The High on Life run establishes that accepting the descriptor gets past the sampler abort and renders the scene; it does not establish that the console applies this arithmetic. Could you reconcile the implementation and tests with the two oracle results, or identify a PS5-specific/stage/layout distinction that explains them? Until then, I don't consider `LOD_BIAS_SEC` addition validated. The unnormalized filter and clamp remaps have separate supporting oracle evidence.
MarcZX10 commented 2026-10-13 22:49:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T22:49:19Z.


One more independent check has now been posted: the gfx1036 run covers both explicit and implicit sampling in wave32 and wave64, exercises all nonzero LOD_BIAS_SEC values with primary-bias controls, and again sees no effect from the secondary field. That strengthens the mismatch with the signed-add implementation and decoder tests. The same report supports the unnormalized filter/clamp remaps but still does not establish PS5 behavior, so please either identify a console-specific distinction or keep the secondary-bias arithmetic out of this change until it can be measured on the target.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156860837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6156860837). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T22:49:19Z. --- One more independent check has now been posted: the gfx1036 run covers both explicit and implicit sampling in wave32 and wave64, exercises all nonzero `LOD_BIAS_SEC` values with primary-bias controls, and again sees no effect from the secondary field. That strengthens the mismatch with the signed-add implementation and decoder tests. The same report supports the unnormalized filter/clamp remaps but still does not establish PS5 behavior, so please either identify a console-specific distinction or keep the secondary-bias arithmetic out of this change until it can be measured on the target.
ymatrix1 commented 2026-10-13 23:59:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ymatrix1 on 2026-10-13T23:59:17Z.


PS5 (gfx1013) measurements for unnormalized samplers on multi-level textures, in case they help here. Kena: Bridge of Spirits (PPSA01746) hits this path.

Method: the PS5 Vulkan probe harness (mihawk-99/PS5_Vulkan) on a console. A 64x64 texture with four mip levels, a distinct marker in each level. A compute shader samples it through a sampler whose descriptor is rewritten to set FORCE_UNNORMALIZED (S# dword 0 bit 15), coordinates in texel units. Counts are of the 256 output texels per level.

S# mip filter LOD bias access level read
point 0 explicit LOD 0 / 1 / 2 / 3 0 / 1 / 2 / 3, 256 of 256 each
point 0 implicit LOD, quad derivative of 8 texels 3
none 7 explicit LOD 2 / explicit LOD 3 / implicit LOD (derivative 8 texels) 0 in all three
point, normalized control 0 same implicit access 3
  • With a point mip filter the hardware picks the level from the LOD (explicit, or derived from the quad derivative of the coordinates). The coordinates are then read in texel units of that selected level: the same coordinate (5.5, 2.5) reads texel (5, 2) at levels 1, 2 and 3.
  • With the mip filter set to none the sampler reads level 0 only, whatever the LOD or bias, and the coordinates are level-0 texels.

So the "implicit LOD samples the base level" shortcut is exact for a sampler with the mip filter off, and for a point mip filter only when the LOD resolves to level 0. Kena's blocking sampler is mip filter none, LOD bias 7, point filters, implicit-LOD use, the exact case, so the base-level path can be taken for it. I have a small change for that rule: ymatrix1:fix/shader-unnormalized-sampler-without-mip-filter (not a PR yet, it touches ProveUnnormalized only; commit 9c17bcc08).

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157753114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6157753114). Originally posted by [ymatrix1](https://github.com/ymatrix1) on 2026-10-13T23:59:17Z. --- PS5 (gfx1013) measurements for unnormalized samplers on multi-level textures, in case they help here. Kena: Bridge of Spirits (PPSA01746) hits this path. Method: the PS5 Vulkan probe harness (mihawk-99/PS5_Vulkan) on a console. A 64x64 texture with four mip levels, a distinct marker in each level. A compute shader samples it through a sampler whose descriptor is rewritten to set FORCE_UNNORMALIZED (S# dword 0 bit 15), coordinates in texel units. Counts are of the 256 output texels per level. | S# mip filter | LOD bias | access | level read | |---|---|---|---| | point | 0 | explicit LOD 0 / 1 / 2 / 3 | 0 / 1 / 2 / 3, 256 of 256 each | | point | 0 | implicit LOD, quad derivative of 8 texels | 3 | | none | 7 | explicit LOD 2 / explicit LOD 3 / implicit LOD (derivative 8 texels) | 0 in all three | | point, normalized control | 0 | same implicit access | 3 | - With a point mip filter the hardware picks the level from the LOD (explicit, or derived from the quad derivative of the coordinates). The coordinates are then read in texel units of that selected level: the same coordinate (5.5, 2.5) reads texel (5, 2) at levels 1, 2 and 3. - With the mip filter set to none the sampler reads level 0 only, whatever the LOD or bias, and the coordinates are level-0 texels. So the "implicit LOD samples the base level" shortcut is exact for a sampler with the mip filter off, and for a point mip filter only when the LOD resolves to level 0. Kena's blocking sampler is `mip filter none, LOD bias 7, point filters, implicit-LOD use`, the exact case, so the base-level path can be taken for it. I have a small change for that rule: [`ymatrix1:fix/shader-unnormalized-sampler-without-mip-filter`](https://github.com/ymatrix1/AnyPS5/tree/fix/shader-unnormalized-sampler-without-mip-filter) (not a PR yet, it touches `ProveUnnormalized` only; commit [`9c17bcc08`](https://github.com/ymatrix1/AnyPS5/commit/9c17bcc08)). AI-assisted: yes.
adriadam10 commented 2026-10-14 11:26:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:26:25Z.

Review: CHANGES_REQUESTED


Thanks, the unnormalized filter/clamp remaps look right (our own run on gfx1035 and the gfx1030/gfx1036 runs above agree on them). Two things to fix:

  • core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp:162 adds the decoded LOD_BIAS_SEC to lodBias, but on hardware it has no effect. I sampled a 4-level texture with a point mip filter through image_sample_l on gfx1035, with LOD_BIAS_SEC 0..63 combined with primary bias 0, 0x80 and 0x100: the level read never changed, while the primary bias did change it. This matches the gfx1030 and gfx1036 results in this thread. Accept the field and ignore it (as it already was with static_cast<void>), and change the decoder tests at tests/GuestSamplerResource.cpp:460-470 to assert that lodBias is unaffected by a nonzero secondary bias. Update the debt entry at docs/dev/debt/libSceAgcDriver.md:59 accordingly (it currently says the value is added), and drop the maxSamplerLodBias clamp sentence that only applied to the sum. If you have a console measurement showing it does apply on PS5, post it and keep the add.
  • agc_driver_image_sample_unnormalized fails with this change: tests/execution/ImageSampleUnnormalized.cpp:338 and :339 still expect the unequal min/mag filter and clamp mode 0 samplers to be refused. Turn them into positive checks, comparing each sample against the same S# with the mag filter (or clamp mode 2). Please run the whole libSceAgcDriver ctest, not only GuestSamplerResource.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5517148032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#pullrequestreview-5517148032). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:26:25Z. **Review:** CHANGES_REQUESTED --- Thanks, the unnormalized filter/clamp remaps look right (our own run on gfx1035 and the gfx1030/gfx1036 runs above agree on them). Two things to fix: - `core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp:162` adds the decoded `LOD_BIAS_SEC` to `lodBias`, but on hardware it has no effect. I sampled a 4-level texture with a point mip filter through `image_sample_l` on gfx1035, with `LOD_BIAS_SEC` 0..63 combined with primary bias 0, 0x80 and 0x100: the level read never changed, while the primary bias did change it. This matches the gfx1030 and gfx1036 results in this thread. Accept the field and ignore it (as it already was with `static_cast<void>`), and change the decoder tests at `tests/GuestSamplerResource.cpp:460-470` to assert that `lodBias` is unaffected by a nonzero secondary bias. Update the debt entry at `docs/dev/debt/libSceAgcDriver.md:59` accordingly (it currently says the value is added), and drop the `maxSamplerLodBias` clamp sentence that only applied to the sum. If you have a console measurement showing it does apply on PS5, post it and keep the add. - `agc_driver_image_sample_unnormalized` fails with this change: `tests/execution/ImageSampleUnnormalized.cpp:338` and `:339` still expect the unequal min/mag filter and clamp mode 0 samplers to be refused. Turn them into positive checks, comparing each sample against the same S# with the mag filter (or clamp mode 2). Please run the whole `libSceAgcDriver` ctest, not only `GuestSamplerResource`.
pushkarreddyy commented 2026-10-14 11:39:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T11:39:25Z.


@adriadam10 @MarcZX100 Thanks for the detailed review and hardware-oracle test results! Addressed all points in updated commit e1d402c6c:

  1. Secondary LOD Bias Ignored:

    • In GuestSamplerResource.cpp, lodBiasSec is accepted and left ignored (result.lodBias = toSignedLodBias(lodBiasRaw)), matching the hardware measurements on gfx1030, gfx1035, and gfx1036.
    • Updated tests/GuestSamplerResource.cpp to assert that lodBias remains 0.0f (or primary bias) unaffected by nonzero lodBiasSec.
    • Updated technical debt documentation in docs/dev/debt/libSceAgcDriver.md, documenting that LOD_BIAS_SEC is accepted and ignored per RDNA2 hardware measurements, and dropped the maxSamplerLodBias clamp sentence.
  2. Unnormalized Positive Checks in ImageSampleUnnormalized.cpp:

    • Turned lines 338 and 339 into positive checks comparing samples with unequal min/mag filters and clamp mode 0 against reference runs with the magnification filter (and clamp mode 2), asserting exact match.
  3. Rebase & Pre-Flight Verification:

    • Rebased cleanly on latest origin/main (23be5a02b).
    • Verified python tools/check_conventions.py --base origin/main with 0 findings and 0 errors.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167474228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6167474228). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-14T11:39:25Z. --- @adriadam10 @MarcZX100 Thanks for the detailed review and hardware-oracle test results! Addressed all points in updated commit `e1d402c6c`: 1. **Secondary LOD Bias Ignored**: - In `GuestSamplerResource.cpp`, `lodBiasSec` is accepted and left ignored (`result.lodBias = toSignedLodBias(lodBiasRaw)`), matching the hardware measurements on gfx1030, gfx1035, and gfx1036. - Updated `tests/GuestSamplerResource.cpp` to assert that `lodBias` remains 0.0f (or primary bias) unaffected by nonzero `lodBiasSec`. - Updated technical debt documentation in `docs/dev/debt/libSceAgcDriver.md`, documenting that `LOD_BIAS_SEC` is accepted and ignored per RDNA2 hardware measurements, and dropped the `maxSamplerLodBias` clamp sentence. 2. **Unnormalized Positive Checks in `ImageSampleUnnormalized.cpp`**: - Turned lines 338 and 339 into positive checks comparing samples with unequal min/mag filters and clamp mode 0 against reference runs with the magnification filter (and clamp mode 2), asserting exact match. 3. **Rebase & Pre-Flight Verification**: - Rebased cleanly on latest `origin/main` (`23be5a02b`). - Verified `python tools/check_conventions.py --base origin/main` with 0 findings and 0 errors.
adriadam10 commented 2026-10-14 11:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:44:08Z.

Review: APPROVED


Re-checked against e1d402c6c:

  • LOD_BIAS_SEC is accepted and ignored, with the decoder tests and the debt entry updated to match the gfx1030/gfx1035/gfx1036 measurements.
  • ImageSampleUnnormalized.cpp now checks the unequal-filter and clamp-mode-0 samplers against the mag-filter / clamp-to-edge references; agc_driver_image_sample_unnormalized passes.
  • The new decoder and execution checks fail when GuestSamplerResource.cpp is reverted.

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5517333824 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#pullrequestreview-5517333824). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:44:08Z. **Review:** APPROVED --- Re-checked against e1d402c6c: - `LOD_BIAS_SEC` is accepted and ignored, with the decoder tests and the debt entry updated to match the gfx1030/gfx1035/gfx1036 measurements. - `ImageSampleUnnormalized.cpp` now checks the unequal-filter and clamp-mode-0 samplers against the mag-filter / clamp-to-edge references; `agc_driver_image_sample_unnormalized` passes. - The new decoder and execution checks fail when `GuestSamplerResource.cpp` is reverted. Merging once CI is green.
pushkarreddyy commented 2026-10-14 11:59:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T11:59:39Z.


@adriadam10 CI checks on updated commit e1d402c6c have now completed and are all green. Ready for merge whenever you have a moment.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167828295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6167828295). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-14T11:59:39Z. --- @adriadam10 CI checks on updated commit e1d402c6c have now completed and are all green. Ready for merge whenever you have a moment.
adriadam10 commented 2026-10-14 12:12:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:12:56Z.


Re-checked e1d402c6c: LOD_BIAS_SEC is accepted and ignored as measured on gfx1030/1035/1036, the unnormalized min/mag filter and clamp-mode-0 remaps are covered by the decoder and execution tests, and agc_driver_image_sample_unnormalized passes locally and fails with GuestSamplerResource.cpp reverted. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6168061392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5156#issuecomment-6168061392). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T12:12:56Z. --- Re-checked e1d402c6c: `LOD_BIAS_SEC` is accepted and ignored as measured on gfx1030/1035/1036, the unnormalized min/mag filter and clamp-mode-0 remaps are covered by the decoder and execution tests, and `agc_driver_image_sample_unnormalized` passes locally and fails with `GuestSamplerResource.cpp` reverted. Merging once the full Build is green.
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!5156
No description provided.