feat(libSceAgcDriver): support secondary LOD bias and relax unnormalized coordinate filters #5156
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5156"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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
Checklist
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.
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:Unnormalized Bias Test:
Added a dedicated unnormalized test case with non-zero primary (
lodBiasRaw = 256) and secondary (lodBiasSec = 8) LOD bias inGuestSamplerResource.cpp, asserting that hostresult.lodBiasremains0.0fto explicitly lock in and document that deliberate approximation.maxSamplerLodBiasDebt Documentation:Updated
docs/dev/debt/libSceAgcDriver.mdto document that hostVkSamplerCreateInfo::mipLodBiasclamps to devicemaxSamplerLodBias(typically 15.0 to 16.0), whereas GFX10 adds secondary bias post-clamp or inside hardware register limits, so any combined sum exceeding hostmaxSamplerLodBiaswill be clamped by Vulkan.Conventions & CI:
Passes
python tools/check_conventions.py --base origin/mainwith 0 findings and 0 errors.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.
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
main18c438b10plus #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:Its
ExpectFailurefor 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:
guest sampler descriptor combines a min or max reduction with anisotropic filtering, which is not implemented;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.
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-oracleon 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×6432_FLOATlinear texture held in the oracle's extra input bytes, then reads backimage_sample_land implicitimage_sample. The script is below.XY_MAG_FILTER≠XY_MIN_FILTER_lat LOD 0 and for implicit LOD. Mag point / min bilinear returns point results; mag bilinear / min point returns bilinear.LOD_BIAS_SEC(word 2, bits 14–19)LOD_BIASLOD_BIAS, leave the effective LOD unchanged for_land for implicit LOD.LOD_BIASitself 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_MODEmin 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>)Tested and written by Claude (AI assistant) on a contributor's machine.
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 runtime5.7.1-2build1. This is hardware-oracle evidence for the semantics in headae96ad5f454, 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:LOD_BIAS_SECvalue0x01..0x3f, both alone and combined with primaryLOD_BIAS=0x40, left the raw sampled words bit-identical to the corresponding SEC=0 control. Tested explicitimage_sample_lat LOD 0/0.25/0.5 and implicitimage_samplewith 2×2 quad steps 1/2^0.25/2^0.5. Wave32 and wave64, three repeats each: 756 secondary-bias configurations.0x40added 0.25,0x80added 0.5, and0x3fc0subtracted 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.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.
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_SEChad no measurable effect across explicit and implicit samples, with primaryLOD_BIAScontrols 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 considerLOD_BIAS_SECaddition validated. The unnormalized filter and clamp remaps have separate supporting oracle evidence.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_SECvalues 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.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.
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 touchesProveUnnormalizedonly; commit9c17bcc08).AI-assisted: yes.
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:162adds the decodedLOD_BIAS_SECtolodBias, but on hardware it has no effect. I sampled a 4-level texture with a point mip filter throughimage_sample_lon gfx1035, withLOD_BIAS_SEC0..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 withstatic_cast<void>), and change the decoder tests attests/GuestSamplerResource.cpp:460-470to assert thatlodBiasis unaffected by a nonzero secondary bias. Update the debt entry atdocs/dev/debt/libSceAgcDriver.md:59accordingly (it currently says the value is added), and drop themaxSamplerLodBiasclamp 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_unnormalizedfails with this change:tests/execution/ImageSampleUnnormalized.cpp:338and:339still 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 wholelibSceAgcDriverctest, not onlyGuestSamplerResource.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:Secondary LOD Bias Ignored:
GuestSamplerResource.cpp,lodBiasSecis accepted and left ignored (result.lodBias = toSignedLodBias(lodBiasRaw)), matching the hardware measurements on gfx1030, gfx1035, and gfx1036.tests/GuestSamplerResource.cppto assert thatlodBiasremains 0.0f (or primary bias) unaffected by nonzerolodBiasSec.docs/dev/debt/libSceAgcDriver.md, documenting thatLOD_BIAS_SECis accepted and ignored per RDNA2 hardware measurements, and dropped themaxSamplerLodBiasclamp sentence.Unnormalized Positive Checks in
ImageSampleUnnormalized.cpp:Rebase & Pre-Flight Verification:
origin/main(23be5a02b).python tools/check_conventions.py --base origin/mainwith 0 findings and 0 errors.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:44:08Z.
Review: APPROVED
Re-checked against
e1d402c6c:LOD_BIAS_SECis accepted and ignored, with the decoder tests and the debt entry updated to match the gfx1030/gfx1035/gfx1036 measurements.ImageSampleUnnormalized.cppnow checks the unequal-filter and clamp-mode-0 samplers against the mag-filter / clamp-to-edge references;agc_driver_image_sample_unnormalizedpasses.GuestSamplerResource.cppis reverted.Merging once CI is green.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T11:59:39Z.
@adriadam10 CI checks on updated commit
e1d402c6chave now completed and are all green. Ready for merge whenever you have a moment.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:12:56Z.
Re-checked
e1d402c6c:LOD_BIAS_SECis 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, andagc_driver_image_sample_unnormalizedpasses locally and fails withGuestSamplerResource.cppreverted. Merging once the full Build is green.