Skip to content

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

Closed
oneandonlydean wants to merge 3 commits into
boykopovar:mainfrom
oneandonlydean:fix/agc-color-compare-rescue
Closed

oneandonlydean wants to merge 3 commits into
boykopovar:mainfrom
oneandonlydean:fix/agc-color-compare-rescue

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Supersedes #907

What

AGC colour-compare emulation (image_sample_c on a colour texture) fixes by @ThisIsAkill, rebased onto current main. The branch is #907's three commits with their authorship kept; Rujul Talekar (@Roojool) posted the resolved rebase in a #907 comment on 14 Oct, and this branch re-applies that resolution on main 86c1784 (the debt note and the test file conflicted again and were resolved the same way).

  • The array layer is the coordinate rounded half to even (RoundEven), where it was Floor(z + 0.5).
  • NOT_EQUAL is unordered (true when the reference or the texel is NaN); the other functions stay false for NaN.
  • TRUNC_COORD with point sampling throws.
  • Tests for 2D arrays, GREATER, NaN and the TRUNC_COORD rejection; the debt note in docs/dev/debt/shader.md is updated.

Both behaviours are the ones @adriadam10 measured on RDNA2 (gfx1035). #907 had no review blocker (adriadam10: "ready to merge from my side", 11 Oct) and the author has not replied since 7 Oct.

Tested

Linux (CachyOS, kernel 7.2.3), NVIDIA GeForce RTX 4090, driver 610.57.04, Release, GCC 16 build from this branch (main 86c1784 + the three commits):

  • ctest -R agc_driver_emulated_color_compare: agc_driver_emulated_color_compare and agc_driver_emulated_color_compare_srgb_decode pass (0.58 s, 0.27 s).
  • The three touched .cpp files (SpirvImageEmitter.cpp, ResourceMaterializer.cpp, EmulatedColorCompare.cpp) pass a g++ 13.5 -fsyntax-only check with the project flags (Linux CI uses GCC 13).
  • Not tested: Windows, other GPUs, a game run (no title was run for this branch), the test against main's shader (the new cases are written to fail there; not run here).

Checklist

  • Based on current main; no other open PR implements the same functions (fix(agc): color compare emulation: review follow-up to #668 #907 is the same change and is superseded)
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux
  • AI-assisted: yes

ThisIsAkill and others added 3 commits October 21, 2026 07:13
…nt sampling in the color compare emulation

NOT_EQUAL is unordered (true when the reference, the texel or both are
NaN) and the other functions are false for NaN, as adriadam10 measured on
RDNA2 in the boykopovar#907 review; OpFUnordNotEqual matches. TRUNC_COORD with point
sampling changes which texel is read, which the emulation does not model,
so the specialization throws for it like the other out-of-scope sampler
state; with bilinear filtering it changes the weights, the same gap as the
full-float weights, and is documented with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ation

A four-layer array view with layer coordinates at the rounding points
(0.49999997, 0.5, 1.5, 2.5, 3.5) and past the clamp, and neighbouring
layers far apart in value, so floor(z + 0.5) and round-half-even give
different results; point, bilinear, wrap and border sampling. GREATER next
to LESSEQUAL. NOT_EQUAL and LESSEQUAL on a 16_16_16_16_FLOAT texture with
NaN and signed-zero references and texels. The TRUNC_COORD rejection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The emulated comparison picked the array layer as floor(z + 0.5). Measured
on RDNA2 (adriadam10, in the boykopovar#907 review), the hardware takes
clamp(roundEven(z), 0, layers - 1): z = 0.5 selects layer 0 and 2.5 layer
2, and 0.49999997, which floor(z + 0.5) rounds up to 1 in f32, selects 0.
GLSL.std.450 RoundEven matches that and is the rule Vulkan uses for its own
array layer. The floor(z + 0.5) came in with boykopovar#668.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean oneandonlydean self-assigned this Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 907 core/libs/prx/libSceAgcDriver/tests/execution/EmulatedColorCompare.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 5021 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 5371 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6010 docs/dev/debt/shader.md
PR 6011 docs/dev/debt/shader.md
PR 6218 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6235 docs/dev/debt/shader.md
PR 6280 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 6412 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 6488 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 6612 docs/dev/debt/shader.md
PR 6879 docs/dev/debt/shader.md
PR 6924 docs/dev/debt/shader.md
PR 6959 docs/dev/debt/shader.md
PR 7085 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 7223 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 7392 docs/dev/debt/shader.md
PR 7395 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 7410 docs/dev/debt/shader.md
PR 7484 docs/dev/debt/shader.md
PR 7550 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7642 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7684 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 7689 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7803 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 7882 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7888 docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 7942 docs/dev/debt/shader.md
PR 8004 docs/dev/debt/shader.md
PR 8055 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 8077 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 8276 docs/dev/debt/shader.md
PR 8277 docs/dev/debt/shader.md
PR 8281 docs/dev/debt/shader.md
PR 8339 docs/dev/debt/shader.md
PR 8403 docs/dev/debt/shader.md
PR 8406 docs/dev/debt/shader.md
PR 8410 docs/dev/debt/shader.md
PR 8425 docs/dev/debt/shader.md
PR 8429 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 8450 docs/dev/debt/shader.md
PR 8458 docs/dev/debt/shader.md
PR 8489 docs/dev/debt/shader.md
PR 8495 docs/dev/debt/shader.md
PR 8518 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8564 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 8612 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 8632 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8639 docs/dev/debt/shader.md
PR 8658 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 8713 docs/dev/debt/shader.md
PR 8716 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 8792 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 8881 docs/dev/debt/shader.md
PR 8883 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8898 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8939 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 8998 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 9020 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 9046 docs/dev/debt/shader.md
PR 9177 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9183 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9193 docs/dev/debt/shader.md
PR 9274 docs/dev/debt/shader.md
PR 9305 docs/dev/debt/shader.md
PR 9335 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 9457 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9508 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 9633 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9671 docs/dev/debt/shader.md
PR 9743 docs/dev/debt/shader.md
PR 9746 docs/dev/debt/shader.md
PR 9748 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
docs/dev/debt/shader.md
PR 9749 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9790 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9889 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9969 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md

@MarcZX10

Copy link
Copy Markdown
Contributor

I checked the overlap against the separate measurements now recorded on #7934. This PR corrects array-layer rounding, NOT_EQUAL NaN behavior, and TRUNC_COORD handling. The GFX10 format split is a distinct behavior: point comparisons return zero for every sampled floating format except codes 7 (16_UNORM) and 22 (32_FLOAT), corroborated on gfx1031 and gfx1036, with gfx1100 also reporting point and bilinear results. The candidate fix changes the format dispatch and the same regression test file touched here, so I won't publish a competing branch. Would you prefer that the format split be stacked as a follow-up to this PR, or kept as a separate PR after this lands?

@oneandonlydean

Copy link
Copy Markdown
Collaborator Author

@MarcZX10 thanks for checking the overlap and for the measurements on #7934. Please keep the format split as a separate PR. This one is queued for testing on its current branch, and stacking would mean starting that over. If you open it now, Depends on: #8625 is fine. It can go in right after this lands, and it'll need its own rebase of the shared test file.

@DavidAmsellem

Copy link
Copy Markdown
Contributor

First AMD run of this PR, on Linux with RADV. Head 8feaa79a7 merged onto main aa1b1bfce (clean merge), built in full and compared with the same main, on the same machine.

AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.

For #8642, which depends on this one: it doesn't merge on top of this head yet (EmulatedColorCompare.cpp and docs/dev/debt/shader.md conflict), as its description says, so I'm testing it on its own against main and will report there.

GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38

AI-assisted: yes

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 20, 2026
@janzezno

Copy link
Copy Markdown
Contributor

Run on AMD hardware.

Host: Arch Linux, kernel 7.2.11, AMD Radeon RX 7900 GRE (RADV NAVI31), Mesa 26.2.5, GCC 16.2.1, Release, BUILD_TESTING=ON.
main e25333e39; PR head 8feaa79a7e merged on top (clean merge).

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R 'compare|denorm|f32|f16|f64|agc_shader_memory|agc_shader_disk_cache|request_serializer|dcc|storage|pm4|indirect' -V

  • main: 137 of 137 pass. PR: 137 of 137 pass, including agc_driver_emulated_color_compare and agc_driver_emulated_color_compare_srgb_decode.
  • The same VUID- set and counts on both; none is new. The validation layer loaded in both runs.

@thuanquang

Copy link
Copy Markdown
Contributor

An AMD proprietary-driver run: RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.5002, Windows 11 26200, MinGW GCC 15.2.0 Release.

  • main 7ab4b2e56 with only this PR's EmulatedColorCompare.cpp: agc_driver_emulated_color_compare and _srgb_decode fail 3 of 3 with 2D array, point, clamp to edge: thread 2 compared to 1.000000, expected 0.000000.
  • main 7ab4b2e56 merged with this head 8feaa79a7 (clean merge): all 5 tests pass 3 of 3: those two plus agc_driver_depth_compare_copy, agc_driver_image_plane_compare_on_line and agc_driver_image_one_dimensional_compare.
  • Khronos validation layer, ctest -V on the same 5: 0 VUID- lines on main and with this PR. The layer was inserted in all 5 test processes on each side.

@oneandonlydean

Copy link
Copy Markdown
Collaborator Author

Closing this as superseded by #8642. Since #8642, these colour compares return a measured zero on main, so the non-zero result this PR asserts no longer matches the code. I'll check separately whether the TRUNC_COORD point-sampling refusal from this PR is still needed on main's path, and if it is, it goes up as its own small PR.

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

Labels

agc libSceAgc* docs needs rebase Conflicts with main, rebase needed shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants