Skip to content

fix(shader): round emulated array sampling half to even - #13415

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Roojool:fix/agc-color-compare-907
Oct 30, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Roojool:fix/agc-color-compare-907

Conversation

@Roojool

@Roojool Roojool commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

What

Carry the RoundEven and unordered NOT_EQUAL fixes from #907 at @ThisIsAkill's invitation, adapted to main da026c70655a. Akhil Moola and the original AI co-author retain commit credit. This replaces #907; the two should not both land.

The shared emulated sampler now rounds array layers half to even. A four-layer converted-unorm sampling regression exposes the live error at 0.49999997, 0.5, 1.5 and 2.5, with bounds cases. The retained NOT_EQUAL arithmetic uses unordered comparison as measured by adriadam10 on RDNA2 gfx1035 in the original review; this is not a new hardware or PS5 measurement.

Current main overrides accepted color comparisons with zero. Keep that behavior, the newer format rules and existing reduction refusal. The old TRUNC_COORD point-sampling refusal no longer applies to this constant-zero path. Test half-float NaN texels/references, signed zero, LESSEQUAL/GREATER/NOT_EQUAL and point/bilinear TRUNC_COORD without restoring the obsolete nonzero comparison expectations. Record these limits in the existing shader debt file.

Overlap: ran tools/pr_overlap.py against the open PRs. It reports no confirmed overlap for mergeable heads and flags shared files on conflicting heads. Targeted inspection of the rounding, comparison and TRUNC_COORD edits identifies #907 as the intended replacement; #12246 adds a separate 1D-array row helper. No prerequisite identified. Those other branch compositions were not runtime-tested.

Tested

Windows 11 Home 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0 / Ninja Release, synthetic shader fixtures:

  • Clean main: 4/4 focused tests pass; zero VUID validation errors.
  • New regression with main's unmodified shader emitter: fails as intended, selecting layer 1 instead of layer 0 (0.250122 instead of 0).
  • Fixed shader and new tests (5a32581256): 4/4 pass; zero VUID errors. The later commit only shortens/splits the debt documentation.
  • Tests: agc_driver, agc_driver_emulated_color_compare, agc_driver_emulated_color_compare_srgb_decode, agc_driver_image_converted_unorm.
  • Both runs use ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, validation 1.4.363, serial verbose CTest with 30-second test bounds. Loader logs confirm layer insertion, with no missing-layer messages.
  • Both comparison runs retain the existing internal skip for unsupported color format 51 on this GPU; no whole test was skipped.
  • Conventions, whitespace and test registration checks pass.

Not tested: PS5, Linux/lavapipe, other GPUs, titles or the full suite. The NaN zero-result tests do not establish nonzero color-comparison semantics.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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: AMD Radeon 780M Graphics, AMD 25.10.30.01 (LLPC) / Windows driver 32.0.21030.1005, Windows 11 Home 10.0.26300
  • AI-assisted: yes (Codex adaptation; original Claude attribution retained)

Roojool and others added 2 commits October 30, 2026 19:27
Carry the RoundEven and unordered NOT_EQUAL fixes from boykopovar#907, with
ThisIsAkill's invitation, onto the current constant-zero comparison path.
Keep TRUNC_COORD accepted for that path and retain the newer format rules.

Exercise array rounding through converted unorm sampling, where selecting
the wrong layer changes the result. Preserve zero comparisons for half-float
NaNs, signed zero, GREATER, NOT_EQUAL and TRUNC_COORD. Record the inherited
RDNA2 measurement basis and the limits of these host tests.

Co-Authored-By: Akhil Moola <24420588+ThisIsAkill@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Oct 30, 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/SpirvBackend/src/SpirvImageEmitter.cpp
PR 5021 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 5371 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6280 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6488 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 6924 docs/dev/debt/shader.md
PR 7392 docs/dev/debt/shader.md
PR 7395 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 7642 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7684 docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 8004 docs/dev/debt/shader.md
PR 9183 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 9387 docs/dev/debt/shader.md
PR 9748 docs/dev/debt/shader.md
PR 10193 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 10233 docs/dev/debt/shader.md
PR 10652 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 10846 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
docs/dev/debt/shader.md
PR 10941 docs/dev/debt/shader.md
PR 11126 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 12246 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 12548 docs/dev/debt/shader.md

@JJenkx

JJenkx commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Windows GPU run of head a6d1bcbd12, merged onto main ad2fbd74cd (clean merge, local only).

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, Radeon RX 6700 XT with AMD proprietary driver 26.10.1 (Vulkan 1.4.315), WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON. Khronos validation layer 1.4.309 requested for every test (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation).

  • agc_driver_emulated_color_compare, agc_driver_emulated_color_compare_srgb_decode, built from the test files this PR changes: pass, 3 of 3 runs each (--repeat until-fail:3), no failures, no skips.
  • They create Vulkan instances on the RX 6700 XT: the validation layer was inserted 6 times across the runs and reported no VUIDs.
  • Negative control: this PR's test files on main sources (one run) fail: agc_driver_emulated_color_compare, agc_driver_emulated_color_compare_srgb_decode. So the test catches what the change fixes on this GPU.

AI-assisted: yes (Claude Code).

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head a6d1bcb merged onto main 9f748f4 · tested 2026-10-30 17:00 UTC · 19 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,308 passed · 3 failed (0 new, 2 also fail on main, 1 unstable on main) · 41 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,352 of 3,021 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (866 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_bda_device 48.4 s, ⚠️ agc_driver_graphics_maps_fallback 32.5 s, ⚠️ agc_driver_graphics 32.5 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_submit_progress_no_timeline: failed in 7 of the last 9 main runs
Failing on main too (2, not counted against this PR)
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 385 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (385 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_array_layer_target_cpu, agc_driver_bda_span_reads_draw_pipeline, agc_driver_bitfield_mask, agc_driver_buffer_atomic_csub, and 377 more
VUID-vkCmdCopyImage-srcImage-01548 (13 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_sampling, and 5 more
VUID-vkCmdCopyImage-srcImage-01551 (13 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_sampling, and 5 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_prepared_exports
Skipped (41)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is eithe
Reproduce
git fetch origin a6d1bcbd122855bbab3c0ac602a43e206ef58431 9f748f4d8e36ce3714f3b95f3386316e110a9b22
git checkout 9f748f4d8e36ce3714f3b95f3386316e110a9b22 && git merge --no-ff a6d1bcbd122855bbab3c0ac602a43e206ef58431
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@adriadam10
adriadam10 merged commit 2d5e012 into boykopovar:main Oct 30, 2026
15 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the array layer rounding (RoundEven) against the RDNA2 gfx1035 measurement from the #907 review, and the new layer test: it selects layer 1 instead of 0 at 0.49999997 and 0.5 without the emitter change, so it pins the fix. Windows (RX 6700 XT, JJenkx) and NVIDIA (RTX 2000 Ada) runs show no new failures or VUIDs; merged.

@Roojool

Roojool commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @adriadam10 for the review and merge, and @JJenkx and @TechLevelZero for the GPU testing! Thanks again @ThisIsAkill for the original fixes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants