fix(agc): color compare emulation: review follow-up to #668 #907
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/907"
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 ThisIsAkill on 2026-10-06T15:40:12Z.
Update after review: rebased onto
maincea1ef13. The reduction check is dropped (#815 has it). The array layer is now round-half-even (measured on RDNA2 by adriadam10), correctingfloor(z + 0.5)from #668. NaN rows were added, and TRUNC_COORD with bilinear is documented. See the reply below for details.What
A follow-up to #668, which was merged before the review fixes were pushed. It carries the changes that answer the four review points from that PR; nothing else. Two commits on current
main:fix(agc): compare NOT_EQUAL unordered and refuse reduction filters and TRUNC_COORD in the color compare emulationtest(agc): cover 2D arrays and GREATER in the color compare emulationHow each review point is addressed
EmulatedColorComparegains a 2D array case (two layers, a different red table per layer): it covers the layer size query and thefloor(z + 0.5)clamp, with layer coordinates below 0, between layers and past the last one.NOT_EQUALis nowOpFUnordNotEqual(true when the reference or the texel is NaN). I could not verify the hardware's NaN behaviour, so the TechnicalDebt entry says so: it is the IEEE!=and as Vulkan defines it for its own depth compare, not confirmed on hardware.FILTER_MODE(word 0 bits 29 to 30) with a min/max reduction mode throws, and so doesTRUNC_COORD(bit 27) with point sampling. The test checks both are rejected and that the default values still run. The TechnicalDebt entry lists both.GREATERas well asLESSEQUAL, which guards the operand order.Notes
main) touchesResourceMaterializer.cpp, which this change edits by four lines. Whichever lands second rebases; the emulated compare then needs the runtime-mode form you described in the review.Tested
Linux, GCC, NVIDIA RTX 3070, on
mainat5895ea72:agc_driver_emulated_color_comparepasses, 4 runs in a row (the new 2D array, GREATER and rejection cases included).ctestpasses: 359 of 359, with one test (agc_driver_pixel_valid_mask) skipping itself.I did not run the new cases against the unfixed code in this round.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-06T18:53:43Z.
Removed code comments per CONVENTIONS.md; no functional change.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T08:33:48Z.
Review: CHANGES_REQUESTED
Thanks for the follow-up. I measured the four points on RDNA2 (gfx1035,
image_sample_c_lzon a 32_FLOAT texture, point sampling) with the HW oracle (tools/hw-oracle/):clamp(roundEven(z), 0, layers - 1), notfloor(z + 0.5): with 4 layers, z = 0.5 → 0, 1.5 → 2, 2.5 → 2, 3.5 → 3, 0.49999997 → 0 (in f32,0.49999997 + 0.5rounds to 1.0, sofloorpicks layer 1 there too).SpirvImageEmitter.cpp:936(from #668) usesFloor(z + 0.5), and the new test pins z = 0.5 → layer 1 (EmulatedColorCompare.cpp:129,Expectedat :168), i.e. it locks in the value the hardware disagrees with.GLSLstd450RoundEven(as Vulkan does for its own array layer) and expected values from round-half-even, with rows 0.5, 1.5, 2.5 and 0.49999997 over at least 3 layers, would fix both.OpFUnordNotEqualmatches. The TechnicalDebt line can say it was measured on RDNA2 instead of "not verified". No test row covers it now (the test never runs NOT_EQUAL, so it passes withOpFOrdNotEqualtoo): a case on an emulated float format (e.g. 16_16_16_16_FLOAT; R32 float takes the native path) with a NaN texel and a NaN reference under NOT_EQUAL would pin it.main: #815 already throws for a min/max reduction sampler inemulatedCompareStateand adds the matchingRejectin this test. Please drop the reduction check, itsRejectand thereductionfield, and keep theTRUNC_COORDpart.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-07T17:25:43Z.
Note: the branch is rebased onto current
main, as requested, so the commit hashes have changed (nowfbbe4789,cfcd3d40,593ffa19).@adriadam10 thanks for measuring this on hardware. All four points are addressed, and the branch is rebased onto current
main(cea1ef13).floor(z + 0.5)came in with #668, so this corrects behaviour that's already onmain. The layer is nowclamp(RoundEven(z), 0, layers - 1)(GLSL.std.450RoundEven, as Vulkan uses for its own array layer). The test now uses 4 layers whose neighbours are far apart in value, with layer coordinates 0.49999997, 0.5, 1.5, 2.5, 3.5, and values below 0 and past the last layer. Expected values use round-half-even. With the oldfloor(z + 0.5)put back, the test fails at z = 0.49999997.OpFUnordNotEqualstays, and TechnicalDebt now says it was measured by you on RDNA2 (gfx1035): NOT_EQUAL is true for NaN and the other functions are false. There are two new rows on a16_16_16_16_FLOATtexture (emulated path), NOT_EQUAL and LESSEQUAL, with NaN, +0 and −0 in both the reference and the texel. WithOpFOrdNotEqualput back, the NOT_EQUAL row fails.Rejectand thereductionfield, since #815 covers them. Kept theTRUNC_COORDrefusal for point sampling.Tests:
agc_driver_emulated_color_comparepasses on Linux with GCC on an RTX 3070. The fullctest(default build) passes, 399 of 399.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:39:30Z.
Ready to merge from my side, but the PR description fails the conventions check:
Please fill those template lines in (only you can answer AI-assisted); it merges once they pass.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:14:48Z.
Conflicts with main in
SpirvImageEmitter.cpp,EmulatedColorCompare.cppand TechnicalDebt; please rebase. Main still hasFloor(z + 0.5)for the layer andOpFOrdNotEqual(SpirvImageEmitter.cpp:1307,:1343), so both fixes are still needed.Imported from boykopovar/AnyPS5. Originally posted by Roojool on 2026-10-14T12:03:18Z.
Hi @ThisIsAkill — following up on oneandonlydean's rebase request (Oct 11). I've rebased your branch onto current
mainand offer the result below; nothing was pushed or posted anywhere — every artifact is yours to take, adapt or ignore.Not obsoleted. I checked first:
mainstill computes the array layer asFloor(z + 0.5)(SpirvImageEmitter.cpp:1308) and still emitsOpFOrdNotEqualfor NOT_EQUAL (:1344), so both of your fixes are still needed, exactly as oneandonlydean said.What moved on
mainsince Oct 6, and how it was resolved (conflicts resolved as union — your semantic changes kept, main's evolution kept):SpirvImageEmitter.cppreplaced yourswitchwith a 6-entryspv::Optable and reworked the texel fetch (runtime swizzle, border select). Your NOT_EQUAL fix is re-applied asOpFOrdNotEqual→OpFUnordNotEqualon the table's entry for compare function 5; theRoundEvenchange (your third commit) applied cleanly.ResourceMaterializer.cppgained theconstantZeroshortcut and the cubeDISABLE_CUBE_WRAPcheck: yourtruncatebit read and the TRUNC_COORD throw slot into the evolvedemulatedCompareStateunchanged.TechnicalDebt.mdtodocs/dev/debt/shader.mdand gained 8-bit sRGB/unorm and cube coverage: your three edits (TRUNC_COORD with point sampling throws; the round-half-even layer + unordered NOT_EQUAL sentence credited to adriadam10's RDNA2 measurements; TRUNC_COORD-with-bilinear named in the full-float-weights sentence) are applied at the new location.compare→function(field order changed): your 2D-array / GREATER / NaN / TRUNC_COORD coverage is re-applied on top — your array program bytes are kept verbatim (asLayerCode, since main'sArrayCodename is taken by its "array instruction on a 2D texture" case), sampler initializers re-mapped to main's field order, andRunLayers/RunNaNfollow the existingRunCuberunner pattern.Rebased commits (authorship, messages and Co-Authored-By lines untouched):
73de775a8fix(agc): compare NOT_EQUAL unordered and refuse TRUNC_COORD with point sampling in the color compare emulation0ebe2c2d8test(agc): cover 2D arrays, GREATER and NaN in the color compare emulation709fbf00bfix(agc): round the color compare array layer half to evenVerification here (Windows, MinGW-w64 via the project toolchain, Ninja/Release, a Vulkan device present — none of the runs skipped):
agc_driver_emulated_color_compare_testsbuilds clean; ctest:agc_driver_emulated_color_comparePassed (1.97 s),agc_driver_emulated_color_compare_srgb_decodePassed (0.91 s); neighboragc_driverPassed (5.07 s) as a sanity link/run of the touched recompiler sources.python -X utf8 tools/check_conventions.py --base refs/remotes/upstream/main: all checks passed.(Setup notes: main added the
3rdparty/libusb-cmakesubmodule — it is initialized in the verification worktree; the ffmpeg prebuilt package was reused from a sibling build directory because cmake's downloader had no CA bundle on this host.)To take it — force-push from my fork's mirror (a rebase rewrites the commits, so only you can land them; they keep you as author):
That branch is exactly the three commits above on top of
mainc9ee728a7; ifmainhas moved again by the time you take it, a plaingit rebase origin/mainfirst should be enough.One small heads-up: as in your original history, the array/NaN test expectations encode round-half-even (
ExpectedLayerusesnearbyint) already in commit 2, while the shader learnsRoundEvenin commit 3 — you validated at the tip, so nothing new, just don't be surprised if you ever bisect into commit 2's tree.AI-assisted template field — this is the only thing adriadam10 still waits on, and only you can answer it, so please edit the PR description yourself. Draft suggestion (your commits carry
Co-Authored-By: Claude Opus 5.5, so if that reflects how they were written): change the last checklist line toThanks again for the careful follow-up — the RDNA2-measured layer rounding and the NaN semantics are exactly the kind of grounding that makes this entry trustworthy.
Pull request closed