Skip to content

fix(recompiler): start pixel waves without their helper invocations in EXEC - #305

Merged
boykopovar merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/recompiler-pixel-helper-lanes
Oct 3, 2026
Merged

boykopovar merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/recompiler-pixel-helper-lanes

Conversation

@oneandonlydean

@oneandonlydean oneandonlydean commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

What

A pixel wave starts with EXEC holding only its covered pixels. The other lanes of a partly covered quad run as helpers outside EXEC until the shader asks for whole quads (s_wqm). emitEntryPrologue starts every stage with initialExec = true, so a pixel shader starts with Vulkan's helper invocations in EXEC too. Helper invocations take part in subgroup operations, so on main they:

  • count in ballots: v_mbcnt_* ranks, s_bcnt1 of EXEC, v_readfirstlane and the first-lane choices built on them;
  • can be the lane that performs a wave's single ds_append/ds_consume or atomic. An atomic in a helper invocation does nothing and returns an undefined value.

Changes:

  • New StageInputKind::HelperInvocation, declared as the HelperInvocation builtin (bool) and read as 1/0. ShaderInfoCollector collects it and validates its component, and ShaderValidation accepts it as a fragment builtin.
  • The prologue starts a pixel shader's EXEC as HelperInvocation == 0. s_wqm still adds the helpers of every quad with a covered pixel, so derivative code keeps them, as on the GPU.

Found on my integration branch: a PPSA21564 title-screen pixel shader allocates light-list nodes with a GDS ds_append and links them with image_atomic_swap. With helpers in EXEC, a test of that pattern on the RTX 4090 saw waves reuse node indices (867 duplicates among 7817 pixels), which can link a node to itself. Main cannot bind GDS in shaders yet (#285 adds that), but the ballot and atomic cases above apply to any pixel shader.

Tested

  • Linux (CachyOS, RTX 4090, NVIDIA 610.57.04).
  • New agc_driver_pixel_helper_lanes execution test (tests/execution/PixelHelperLanes.cpp, so ctest runs it like the other tests there; it uses no GDS and no mesh shader). Like the other execution tests it exits 77 (skipped) without a Vulkan device, and it also skips on a subgroup narrower than 32 (lavapipe's is 8), which cannot hold a wave32.
    • Draw: a recompiled vertex shader reads 24 triangles of assorted slopes from a vertex buffer. They leave partly covered quads across a 192x128 target.
    • Pixel shader: it stores, at each covered pixel's slot, its v_mbcnt_lo/hi rank in EXEC, the s_bcnt1_i32_b64 count of EXEC and the v_readfirstlane_b32 of the pixel's index.
    • Check: grouped by that first-lane index, every wave's covered pixels must be lanes 0..n-1 of an n-lane EXEC, and the first lane must be one of those pixels. Uncovered pixels must store nothing. This runs 4 passes each in wave64 and wave32.
    • Result: on main it fails with pixel helper lanes wave64: the wave whose first lane is pixel 392 has 25 covered pixels, but pixel 584 is lane 2 of EXEC. With the fix it passes.
  • agc_driver_mesh_tests and agc_driver_bda_device_tests pass.
  • ctest: 106/106 pass, including the execution tests.
  • PPSA21564: this change has been on my integration branch through repeated passes of my visual regression check (from the intro video through the title and save menu into gameplay; checkpoint frames, flicker, video tearing and FPS).

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none. fix(agc): fragment SampleId, Layer, FragDepth and SampleMask interfaces #375 and feat(agc): vertex clip and cull distances #423 edit the same fragment built-in check in ShaderValidation.cpp; whichever merges second keeps both.
  • AI-assisted: yes

@github-actions github-actions Bot added build shader core/shader agc libSceAgc* labels Oct 2, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 2, 2026
…n EXEC

A pixel wave starts with EXEC holding its covered pixels. The other lanes of
a partly covered quad run as helpers outside EXEC until the shader asks for
whole quads with s_wqm. Pixel shaders started with every invocation in EXEC,
Vulkan's helper invocations included. Those take part in subgroup
operations, so they counted in ballots (v_mbcnt, s_bcnt1 of EXEC,
v_readfirstlane), and a wave's single ds_append or atomic could be performed
by one of them: an atomic in a helper invocation does nothing and returns an
undefined value.

The entry prologue now starts a pixel shader's EXEC as !gl_HelperInvocation,
through a new StageInputKind::HelperInvocation builtin input. s_wqm still
adds the helpers of every quad with a covered pixel, so derivative code keeps
them.

The agc_driver_pixel_helper_lanes execution test draws triangles that leave
partly covered quads across the target with a pixel shader that stores each
covered pixel's v_mbcnt rank in EXEC, the s_bcnt1 count of EXEC and the
v_readfirstlane of a pixel id. Every wave's covered pixels must be lanes
0..n-1 of an n-lane EXEC whose first lane is one of them, in wave64 and
wave32. It skips on a subgroup narrower than 32, such as lavapipe's.
@oneandonlydean
oneandonlydean force-pushed the fix/recompiler-pixel-helper-lanes branch from c54c004 to 7ed138d Compare October 2, 2026 08:12
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 2, 2026
@boykopovar
boykopovar merged commit de3344a into boykopovar:main Oct 3, 2026
3 checks passed
@oneandonlydean
oneandonlydean deleted the fix/recompiler-pixel-helper-lanes branch October 3, 2026 07:02
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 3, 2026
…oykopovar#304 boykopovar#305 boykopovar#306 boykopovar#322 boykopovar#409 boykopovar#416, boykopovar#276 boykopovar#277 boykopovar#275 boykopovar#307, shader ops boykopovar#226 boykopovar#255 boykopovar#260 boykopovar#280 boykopovar#308 boykopovar#309 boykopovar#311 boykopovar#318 boykopovar#320 boykopovar#324 boykopovar#326 boykopovar#379 boykopovar#384 boykopovar#399, boykopovar#261, kernel boykopovar#335 boykopovar#341 boykopovar#349 boykopovar#355, libs boykopovar#227 boykopovar#244 boykopovar#245 boykopovar#273 boykopovar#274 boykopovar#279 boykopovar#286 boykopovar#287 boykopovar#289 boykopovar#296 boykopovar#300 boykopovar#328 boykopovar#358 boykopovar#402) into astrobot

Where our PR merged in a revised form, main's version is taken; where
astrobot carries the same work plus later local commits, astrobot's code
stays and main's additions appear once.

Conflicts:
- AvPlayer (Export.cpp both libs, include/AvPlayer.hpp, src/Player.cpp,
  src/Source.cpp, AvPlayerLibrary.cmake, CMakeLists.txt, SceTypes.hpp,
  tests/GuestAvPlayer.cpp): main's boykopovar#307 (our reviewed squash, which carries
  9c8e7fd e9ea5c8 adcede3 fb4eeb9 953057c ac456ee). It links the
  shared ffmpeg-core target, so astrobot's second FFmpeg build goes:
  3rdparty/FFmpeg submodule, core/libs/FFmpeg.cmake and src/Exports.cpp.
- libScePngEnc: main's boykopovar#227 (supersedes OverkillLabs' encoder).
- libScePad Export.cpp: main's boykopovar#287 tilt correction (supersedes 49d45f5).
- libSceAudioPropagation Export.cpp: astrobot's object model, which
  defines every function boykopovar#289 declares as a stub.
- libSceSaveData.native Export.cpp: both (SaveDataHoldWrites and boykopovar#289's
  unknown exports).
- VideoOutDriver.cpp: astrobot's (2546bd1 counters around boykopovar#416's
  lastFlipVblank store, same value). tests/Flip.cpp: boykopovar#416's pacing test and
  boykopovar#417's after-GPU test both kept.
- boykopovar#278 files (DisplayFormat, VulkanDevice, GpuColorTransfer,
  ResidentPresent, agc CMakeLists): main's comment-free boykopovar#278 plus
  astrobot's P5 present-direct (b29728d), which removed DetileImage,
  ResidentPresent.hpp and the recorder-test hook; the resident present test
  stays its own executable.
- VulkanDevice.cpp/.hpp: astrobot's GDS, local memory probe, sample dumps
  and P5 code; boykopovar#303/boykopovar#409 comments as main has them; main's shader clock
  (boykopovar#324) and DepthSurface-free includes.
- RequestSerializer.cpp: version stays 8 (6 mesh passthrough, 7
  nonConstantImageOffsets, 8 astrobot's later field). boykopovar#303's auto-merged
  second write and read of nonConstantImageOffsets removed.
- SpirvEmitter.hpp, SpirvEmitterState.hpp, Recompiler.hpp/.cpp, StageIO.hpp,
  SpirvOptimizer.cpp, InstructionTranslator.cpp, ShaderReplay.cpp: local
  fields kept, boykopovar#303/boykopovar#305 comments as main has them.
- SpirvAluEmitterMath.cpp: v_readlane keeps the split-wave path and takes
  boykopovar#322's wrap at the wave size for the others.
- SpirvEmitter.cpp: astrobot's single-lane layout check.
- SpirvFlowEmitter.cpp: boykopovar#304 as merged (the second lane emits a shared
  value itself when the first lane defined nothing).
- SpirvImageEmitter.cpp: main's Offset operand placed before MinLod.
- boykopovar#304: main's WaveUniformValues (SpirvAnalysis.cpp) replaces astrobot's
  copy in SpirvWaveExchange.cpp.
- Recorder.hpp/.cpp, Draw.hpp, Graphics Draw.cpp, ShaderResources.cpp:
  astrobot's boykopovar#276/boykopovar#277 with its later snapshot work (per-use budgets,
  stale-snapshot refresh, profile counters, boykopovar#410, boykopovar#424, fan GS); boykopovar#409/boykopovar#306
  comments as main has them.
- PacketMemory.cpp: boykopovar#409 as merged plus astrobot's two opt-outs.
- tests: ShaderMemory.cpp takes boykopovar#303's and boykopovar#304's new tests; Recorder.cpp
  takes boykopovar#409's afterRecordedWorkTests and drops main's copies of the
  boykopovar#276/boykopovar#277 tests astrobot already has; Structurizer.cpp keeps boykopovar#413's case.

boykopovar#143 (NGG passthrough) stays as on astrobot: upstream did not touch its
files since the boykopovar#258 revert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants