Skip to content

fix(agc): round the color compare array layer half to even and compare NOT_EQUAL unordered - #5288

Closed
SandstromPL wants to merge 1 commit into
boykopovar:mainfrom
SandstromPL:fix/agc-color-compare-review
Closed

SandstromPL wants to merge 1 commit into
boykopovar:mainfrom
SandstromPL:fix/agc-color-compare-review

Conversation

@SandstromPL

Copy link
Copy Markdown
Contributor

What

This carries #907 by @ThisIsAkill, the review follow-up to #668.

The two fixes, both measured by adriadam10 in #907's review on RDNA2 (gfx1035, image_sample_c_lz on a 32_FLOAT texture):

8-bit UNORM and sRGB textures return 0 for every function (#3438, #4267), so they are not affected.

TRUNC_COORD is not refused. This differs from #907, and from adriadam10's request there on 2026-10-07 ("keep the TRUNC_COORD part"). #907 threw for TRUNC_COORD with point sampling, answering point 3 of #668's review. That throw is left out because of a later measurement. On 2026-10-08, in adriadam10's #1396 review (format 43, image_sample_lz/image_sample_l, gfx1035; non-comparison samples), the setting was measured both ways:

  • "With it set, the hardware matches floor."
  • With it clear, the hardware already reads texel k at t = k - 2^-12 and k - 2^-20, where floor gives k - 1.

The emulation picks a point-sampled texel with floor. So #907's throw refused the case the emulation gets right, and accepted the case it gets wrong.

That #1396 review asked to model the clear case or throw for it. Throwing would refuse the default S#, and modelling it needs the threshold below k, which is not measured. So this PR names the clear case in the debt entry, as adriadam10 suggested in #907 for TRUNC_COORD under bilinear filtering ("either throw for it too or name it in that sentence"). The debt entry also says that TRUNC_COORD changes the bilinear weights on hardware. A new test row samples with TRUNC_COORD set under point filtering and expects floor.

Tested

Ubuntu 24.04, GCC 13.3, Release with BUILD_TESTING=ON, on main 0214069. Locally, the libusb lines were removed from CMakeLists.txt, because the libusb submodule isn't checked out here.

agc_driver_emulated_color_compare gains these cases, adapted from #907:

  • five 2D array rows over 4 layers with different values. The layer coordinates are -0.6, -0.4, 0, 0.49999997, 0.5, 0.99, 1, 1.5, 2.5, 2.49, 3.5, 3.7 and 7; -0.6 is new. The rows are point and bilinear clamp to edge, bilinear wrap, bilinear white border, and point GREATER;
  • two rows on a 16_16_16_16_FLOAT texture (the emulated float path), NOT_EQUAL and LESSEQUAL. NaN, +0 and -0 appear in both the reference and the texel; the -0 texel is new, so +0 and -0 are compared in both directions;
  • GREATER on a 2D texture, point and bilinear with a white border, which guards the operand order;
  • point sampling with TRUNC_COORD set, expecting floor. It replaces fix(agc): color compare emulation: review follow-up to #668 #907's check that this sampler is rejected.

Each fix is needed:

  • On main, the 2D array rows fail: 2D array, point, clamp to edge: thread 4 compared to 1.000000, expected 0.000000 from layer 0 (layer coordinate 0.5). A CPU model of the expected values shows that the rows also catch:
    • floor(z + 0.5) at 0.49999997 and 2.5;
    • round-half-away at 0.5;
    • floor(z) at 0.99 and 1.5.
  • With only the layer fix, the NaN row fails: half float, NOT_EQUAL with NaN and signed zero: thread 1 compared to 0.000000, expected 1.000000.
  • With only the NOT_EQUAL fix, the 2D array row fails as on main.
  • With both, the test passes 5 runs out of 5 on each GPU below. agc_driver_emulated_color_compare_srgb_decode passes too.

Full ctest on the RTX 3050 Ti at this head: 1,067 of 1,069 pass, 7 of them skipping themselves (VideoOut without a display, agc_driver_stencil_ref_export). guest_usbd and patched_libraries are not built, because of the missing libusb submodule.

Other checks:

  • No other open PR changes the same hunks. Every open PR that touches these files, drafts included, was merged with this branch using git merge-tree. This branch adds no conflict to any of them, apart from fix(agc): color compare emulation: review follow-up to #668 #907 itself.
  • No hardware here: the hardware behaviour comes from adriadam10's measurements.
  • tools/check_conventions.py from main passes with this title and body.

Checklist

  • Based on current main; no other open PR implements the same functions (apart from fix(agc): color compare emulation: review follow-up to #668 #907, which this carries)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3050 Ti Laptop GPU, driver 580.178.04, Ubuntu 24.04; lavapipe (Mesa 25.2.8, LLVM 20.1.2), Ubuntu 24.04
  • AI-assisted: yes (Claude Code); I reviewed and tested every line

🤖 Generated with Claude Code

…e NOT_EQUAL unordered

The emulated comparison of a color texture picked the 2D array layer as
floor(z + 0.5) and compared NOT_EQUAL ordered. adriadam10 measured both
on RDNA2 (gfx1035) in boykopovar#907: the hardware selects
clamp(roundEven(z), 0, layers - 1), and NOT_EQUAL is true when the
reference, the texel or both are NaN.

Carried from boykopovar#907 onto main. Its refusal of TRUNC_COORD with point
sampling is left out: in boykopovar#1396, adriadam10 measured with non-comparison
samples that the hardware with TRUNC_COORD set selects floor(t), as the
emulation does, and that with it clear it selects texel k slightly
below k. The debt entry records both TRUNC_COORD cases.

Co-authored-by: Akhil Moola <24420588+ThisIsAkill@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 13, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants