fix(agc): count thread-dimension dispatch groups without wrapping at 2^32 #12200

Merged
MarcZX10 merged 2 commits from upstream-pr/12200 into main 2026-10-28 23:09:53 +00:00
MarcZX10 commented 2026-10-28 03:23:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T03:23:32Z.


What

A DISPATCH_DIRECT with the thread-dimension bit (packet[4] & 0x20) converts each thread count to a group count as (threads + groupThreads - 1) / groupThreads in 32 bits. With a thread count within groupThreads - 1 of 2^32 the sum wraps: 0xffffffff threads in 64-thread groups gave 0 groups instead of 67108864. For a buffer fill that meant zero records, so the guest's clear was skipped while the submission still reported success; BufferCopy copied fewer elements the same way, and the dispatch's thread count used the same expression.

The conversion is now one helper (ThreadDimensionGroups in Driver.hpp) that adds in 64 bits; the quotient always fits in 32 bits. BufferFill.cpp, BufferCopy.cpp and Dispatch.cpp use it.

Two commits: the fix, then the test (testThreadDimensionGroups in Submit.cpp: 0 threads, partial groups, one thread per group at 0xffffffff, and 0xffffffff in 64-thread groups).

Tested

Linux x86-64, a throwaway archive build with the host CPU gate patched, lavapipe. agc_driver_tests passes with the change ("AGC driver submit tests passed"). tools/check_conventions.py --base upstream/main and git diff --check pass. Not run against the unfixed code; the wrap follows from the 32-bit expression.

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: lavapipe (the new test is arithmetic only; no GPU-specific behaviour changed)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5044688363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12200). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T03:23:32Z. --- ### What A `DISPATCH_DIRECT` with the thread-dimension bit (`packet[4] & 0x20`) converts each thread count to a group count as `(threads + groupThreads - 1) / groupThreads` in 32 bits. With a thread count within `groupThreads - 1` of 2^32 the sum wraps: 0xffffffff threads in 64-thread groups gave 0 groups instead of 67108864. For a buffer fill that meant zero records, so the guest's clear was skipped while the submission still reported success; `BufferCopy` copied fewer elements the same way, and the dispatch's thread count used the same expression. The conversion is now one helper (`ThreadDimensionGroups` in `Driver.hpp`) that adds in 64 bits; the quotient always fits in 32 bits. `BufferFill.cpp`, `BufferCopy.cpp` and `Dispatch.cpp` use it. Two commits: the fix, then the test (`testThreadDimensionGroups` in `Submit.cpp`: 0 threads, partial groups, one thread per group at 0xffffffff, and 0xffffffff in 64-thread groups). ### Tested Linux x86-64, a throwaway archive build with the host CPU gate patched, lavapipe. `agc_driver_tests` passes with the change ("AGC driver submit tests passed"). `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. Not run against the unfixed code; the wrap follows from the 32-bit expression. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: lavapipe (the new test is arithmetic only; no GPU-specific behaviour changed) - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12200
No description provided.