Balatro PPSA21402 on Windows: the title overwrites its own register lists when more than 2 flips are pending (VIDEO_OUT_FLIP_QUEUE_CAPACITY is 16) #1034

Closed
opened 2026-10-07 02:41:01 +00:00 by gjonn · 8 comments
gjonn commented 2026-10-07 02:41:01 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-07T02:41:01Z.


Summary

Balatro (PPSA21402) aborts 8-10 s after start on Windows (main f1efcc67 + #1020 + #1032, which it needs to get this far):

terminate called after throwing an instance of 'std::runtime_error'
  what():  extended register semantics are not implemented (offset dword 0x3a888889)

The indirect register list (0x9f packet, 85 pairs) that the GPU worker reads has had its first 72 bytes replaced by the game's own projection constants. The offset dword in the message varies between runs (0x3a888889, 0xbdcccccd).

If at most 2 flips may be pending, the crash does not happen. VIDEO_OUT_FLIP_QUEUE_CAPACITY is 16, so whenever the GPU worker stalls (the first use of the menu's pipelines, or an artificial slowdown) the game's CPU side gets several frames ahead and writes into memory the worker has not read yet. I don't know the real console's depth, so I'm asking before changing the constant.

Evidence

1. A list is valid, then it isn't. The list at one address is read once per 3 frames (the game rotates 3 frame slots). Ten consecutive reads had the head 1b1 2 1c3 4 1c2 1 207 0 2d3 1 2e4 0 .... The eleventh read had 0 0 bdcccccd 0 bf800000 3f800000 0 3f800000 .... These are floats: 0x3a888889 is 2/1920 and 0xbaf2b9d6 is -2/1080, a 1920x1080 orthographic projection.

2. The CPU writes come from the game. Hardware data breakpoints on the list heads (all threads) show the writer. In normal frames it is the game's libc memcpy writing the list. In the failing frame it is a game function that takes 0x68 bytes of per-draw uniform data from a per-frame allocator and copies the constants into it, and the allocator returned the list's address.

3. Timeline (ms relative to the failing read, one of the three slots):

CPU writes list   GPU reads list   CPU writes constants   GPU reads list
      -78              -63                 -31                  0

Normally a list is read about 15 ms after the CPU writes it, and the slot's next write is 47 ms (3 frames) later. Here the constants are written first and the worker reads the list 31 ms later, one frame later than usual.

4. Experiment. Local build; the slowdown was a debug sleep in the queue worker before each submission, not in the tree.

flip limit GPU worker slowed 40 ms result
16 (current) no crash after 8-10 s (2 of 2)
4 yes crash (1 of 1)
3 yes crash (2 of 2)
2 yes no crash, 50 s (2 of 2)
2 no no GPU crash in 8 runs (6 ran the full 60 s at 59-60 FPS; 2 ended at 18 s on an unrelated NGS2 error)

Where the number comes from

  • VIDEO_OUT_FLIP_QUEUE_CAPACITY = 16 (core/libs/prx/libSceVideoOut/include/VideoOutDriver.hpp:61) was added in d225df74 (the first SDL window commit). I could not find a measurement behind it.
  • WaitForFlipRoom() (VideoOutDriver.cpp:63, called from Driver::waitForFlipRoom, Submission.cpp:89) only blocks a submission that contains a flip when 16 flips are pending. SubmitFlip returns VIDEO_OUT_ERROR_FLIP_QUEUE_FULL at the same count (VideoOutDriver.cpp:341).
  • The title's import table has no sceKernelWaitEqueue, sceVideoOutGetFlipStatus or sceVideoOutIsFlipPending, so the only thing holding its CPU side back is the submit blocking.
  • #416 and #417 are related but different: they make a flip complete only after the frame's GPU work. This is about how many flips may be pending.

What I don't know

  • The PS5's real queue depth, and what the console does when a flip packet inside a DCB meets a full queue (block? fail?).
  • Whether other titles rely on a deeper queue. A limit that is too small could cost throughput for a title that wants three frames in flight.
  • Why 2 is enough. My reading of the traces is that the title's per-frame memory assumes at most 2 frames in flight, but that is an inference. The experiment above is what I'm sure of.

Proposal

  1. If someone with a console can measure the depth (for example a homebrew that submits flips back to back with the display held and counts how many are accepted before SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL, and also what a flip packet in a DCB does at that point), the constant should be set to that.
  2. Otherwise I can open a PR that lowers it to 2, the largest value I found that works for this title, or one that makes it overridable with an APS5_ environment variable like the other switches while the real value is unknown. Which do you prefer?

Windows 11, Intel Core Ultra 9 275HX, NVIDIA GeForce RTX 5090 Mobile (laptop GPU), MinGW-w64 GCC 15.2.0.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5738486982 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-07T02:41:01Z. --- ### Summary Balatro (PPSA21402) aborts 8-10 s after start on Windows (`main` f1efcc67 + #1020 + #1032, which it needs to get this far): ``` terminate called after throwing an instance of 'std::runtime_error' what(): extended register semantics are not implemented (offset dword 0x3a888889) ``` The indirect register list (`0x9f` packet, 85 pairs) that the GPU worker reads has had its first 72 bytes replaced by the game's own projection constants. The offset dword in the message varies between runs (`0x3a888889`, `0xbdcccccd`). If at most 2 flips may be pending, the crash does not happen. `VIDEO_OUT_FLIP_QUEUE_CAPACITY` is 16, so whenever the GPU worker stalls (the first use of the menu's pipelines, or an artificial slowdown) the game's CPU side gets several frames ahead and writes into memory the worker has not read yet. I don't know the real console's depth, so I'm asking before changing the constant. ### Evidence **1. A list is valid, then it isn't.** The list at one address is read once per 3 frames (the game rotates 3 frame slots). Ten consecutive reads had the head `1b1 2 1c3 4 1c2 1 207 0 2d3 1 2e4 0 ...`. The eleventh read had `0 0 bdcccccd 0 bf800000 3f800000 0 3f800000 ...`. These are floats: `0x3a888889` is 2/1920 and `0xbaf2b9d6` is -2/1080, a 1920x1080 orthographic projection. **2. The CPU writes come from the game.** Hardware data breakpoints on the list heads (all threads) show the writer. In normal frames it is the game's libc `memcpy` writing the list. In the failing frame it is a game function that takes 0x68 bytes of per-draw uniform data from a per-frame allocator and copies the constants into it, and the allocator returned the list's address. **3. Timeline** (ms relative to the failing read, one of the three slots): ``` CPU writes list GPU reads list CPU writes constants GPU reads list -78 -63 -31 0 ``` Normally a list is read about 15 ms after the CPU writes it, and the slot's next write is 47 ms (3 frames) later. Here the constants are written first and the worker reads the list 31 ms later, one frame later than usual. **4. Experiment.** Local build; the slowdown was a debug sleep in the queue worker before each submission, not in the tree. | flip limit | GPU worker slowed 40 ms | result | |---|---|---| | 16 (current) | no | crash after 8-10 s (2 of 2) | | 4 | yes | crash (1 of 1) | | 3 | yes | crash (2 of 2) | | 2 | yes | no crash, 50 s (2 of 2) | | 2 | no | no GPU crash in 8 runs (6 ran the full 60 s at 59-60 FPS; 2 ended at 18 s on an unrelated NGS2 error) | ### Where the number comes from - `VIDEO_OUT_FLIP_QUEUE_CAPACITY = 16` (`core/libs/prx/libSceVideoOut/include/VideoOutDriver.hpp:61`) was added in d225df74 (the first SDL window commit). I could not find a measurement behind it. - `WaitForFlipRoom()` (`VideoOutDriver.cpp:63`, called from `Driver::waitForFlipRoom`, `Submission.cpp:89`) only blocks a submission that contains a flip when 16 flips are pending. `SubmitFlip` returns `VIDEO_OUT_ERROR_FLIP_QUEUE_FULL` at the same count (`VideoOutDriver.cpp:341`). - The title's import table has no `sceKernelWaitEqueue`, `sceVideoOutGetFlipStatus` or `sceVideoOutIsFlipPending`, so the only thing holding its CPU side back is the submit blocking. - #416 and #417 are related but different: they make a flip complete only after the frame's GPU work. This is about how many flips may be pending. ### What I don't know - The PS5's real queue depth, and what the console does when a flip packet inside a DCB meets a full queue (block? fail?). - Whether other titles rely on a deeper queue. A limit that is too small could cost throughput for a title that wants three frames in flight. - Why 2 is enough. My reading of the traces is that the title's per-frame memory assumes at most 2 frames in flight, but that is an inference. The experiment above is what I'm sure of. ### Proposal 1. If someone with a console can measure the depth (for example a homebrew that submits flips back to back with the display held and counts how many are accepted before `SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL`, and also what a flip packet in a DCB does at that point), the constant should be set to that. 2. Otherwise I can open a PR that lowers it to 2, the largest value I found that works for this title, or one that makes it overridable with an `APS5_` environment variable like the other switches while the real value is unknown. Which do you prefer? Windows 11, Intel Core Ultra 9 275HX, NVIDIA GeForce RTX 5090 Mobile (laptop GPU), MinGW-w64 GCC 15.2.0.
oneandonlydean commented 2026-10-07 03:45:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T03:45:50Z.


Thanks for the careful trace; the timeline and the decoded projection constants make the overwrite clear.

Before changing the constant, I'd like to know what the title waits on. On the console the command processor also reads that register list some time after the CPU wrote it, so the title must have some way to tell that a frame slot is free before its allocator hands the memory out again. It imports none of the flip-status or event-queue calls, so my guess is a label: an end-of-pipe write (RELEASE_MEM or EVENT_WRITE_EOP, or a WRITE_DATA at the end of the DCB) that the CPU polls. If that's it, the real question is when our driver writes that label. If it lands before the worker has read that frame's list, the title sees the slot as free one frame early, which would match your timeline.

Could you check what the title reads before it reuses a slot (the address its frame allocator polls, or a data breakpoint on its "slot free" path), and when the driver writes that value relative to the list read?

On the two options: an APS5_ override would be a per-title setting, which the project avoids. Lowering the constant to 2 would be easy to accept if the console's depth were known to be 2, but tuned to one title it may only hide the ordering problem. If the label doesn't explain it, a PR with your measurements is still worth discussing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6030480348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6030480348). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T03:45:50Z. --- Thanks for the careful trace; the timeline and the decoded projection constants make the overwrite clear. Before changing the constant, I'd like to know what the title waits on. On the console the command processor also reads that register list some time after the CPU wrote it, so the title must have some way to tell that a frame slot is free before its allocator hands the memory out again. It imports none of the flip-status or event-queue calls, so my guess is a label: an end-of-pipe write (RELEASE_MEM or EVENT_WRITE_EOP, or a WRITE_DATA at the end of the DCB) that the CPU polls. If that's it, the real question is when our driver writes that label. If it lands before the worker has read that frame's list, the title sees the slot as free one frame early, which would match your timeline. Could you check what the title reads before it reuses a slot (the address its frame allocator polls, or a data breakpoint on its "slot free" path), and when the driver writes that value relative to the list read? On the two options: an `APS5_` override would be a per-title setting, which the project avoids. Lowering the constant to 2 would be easy to accept if the console's depth were known to be 2, but tuned to one title it may only hide the ordering problem. If the label doesn't explain it, a PR with your measurements is still worth discussing.
gookie-dev commented 2026-10-07 17:16:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by gookie-dev on 2026-10-07T17:16:58Z.


I traced what the title waits on before it reuses a frame slot (Linux, main + #1020, #861, #1038).

The title's slot wait never blocks. It keeps three frame slots. After each submit it busy-waits on one slot's label (Balatro.elf file offset 0x1014b8: while (*slot.label != slot.expected), a 64-bit compare). At startup it zeroes the label block and then sets every label and every expected value to 0xffffffff (0xffe39..0xfff33). The only other write to those labels is each frame's last packet, RELEASE_MEM of the 64-bit value 0xffffffff to 0x280000000 + 0x20 * slot. Hardware watchpoints on the labels show no other CPU write, and no other packet writes them. So the label never changes value and the poll passes immediately, on the console as well. The driver does not write it early; the title simply has no effective fence. Its CPU side is held back only by its own frame pacing and by submit blocking (WaitForFlipRoom).

The same overwrite also causes black frames and flicker, not only the abort. With #1100 (register lists read at submit) the abort is gone, but while the worker lags the title still rewrites per-frame data the worker has not read yet. The visible result is draws skipped with vertex fetch exceeds descriptor record count: each draw's 4-record vertex descriptor no longer matches its indices (4k..4k+3). When that happens to the final canvas-to-display draw, the frame is presented black. In a 50 s run, 429 of 900 presented frames were black, often in a 3-lit/2-black rhythm. About 1100 such skips occurred in 40 s with 16 pending flips allowed, and none with the limit at 2.

On the trade-off: VIDEO_OUT_FLIP_QUEUE_CAPACITY is also the threshold at which sceVideoOutSubmitFlip returns VIDEO_OUT_ERROR_FLIP_QUEUE_FULL, so lowering it would also change what CPU-flipping titles see. If a lower limit is wanted while the console's depth is unknown, it could apply only to blocking DCB submissions with a flip (WaitForFlipRoom) and keep 16 for the error. That still needs a number, and 2 is what this title needs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6043005853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6043005853). Originally posted by [gookie-dev](https://github.com/gookie-dev) on 2026-10-07T17:16:58Z. --- I traced what the title waits on before it reuses a frame slot (Linux, `main` + #1020, #861, #1038). **The title's slot wait never blocks.** It keeps three frame slots. After each submit it busy-waits on one slot's label (`Balatro.elf` file offset `0x1014b8`: `while (*slot.label != slot.expected)`, a 64-bit compare). At startup it zeroes the label block and then sets every label and every expected value to `0xffffffff` (`0xffe39`..`0xfff33`). The only other write to those labels is each frame's last packet, `RELEASE_MEM` of the 64-bit value `0xffffffff` to `0x280000000 + 0x20 * slot`. Hardware watchpoints on the labels show no other CPU write, and no other packet writes them. So the label never changes value and the poll passes immediately, on the console as well. The driver does not write it early; the title simply has no effective fence. Its CPU side is held back only by its own frame pacing and by submit blocking (`WaitForFlipRoom`). **The same overwrite also causes black frames and flicker, not only the abort.** With #1100 (register lists read at submit) the abort is gone, but while the worker lags the title still rewrites per-frame data the worker has not read yet. The visible result is draws skipped with `vertex fetch exceeds descriptor record count`: each draw's 4-record vertex descriptor no longer matches its indices (`4k..4k+3`). When that happens to the final canvas-to-display draw, the frame is presented black. In a 50 s run, 429 of 900 presented frames were black, often in a 3-lit/2-black rhythm. About 1100 such skips occurred in 40 s with 16 pending flips allowed, and none with the limit at 2. On the trade-off: `VIDEO_OUT_FLIP_QUEUE_CAPACITY` is also the threshold at which `sceVideoOutSubmitFlip` returns `VIDEO_OUT_ERROR_FLIP_QUEUE_FULL`, so lowering it would also change what CPU-flipping titles see. If a lower limit is wanted while the console's depth is unknown, it could apply only to blocking DCB submissions with a flip (`WaitForFlipRoom`) and keep 16 for the error. That still needs a number, and 2 is what this title needs.
mrzacarias commented 2026-10-10 02:19:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by mrzacarias on 2026-10-10T02:19:33Z.


Confirming on macOS (M1 Pro, MoltenVK): with the limit at 2 for blocking DCB submissions with a flip, and 16 kept for sceVideoOutSubmitFlip's queue-full error, the vertex-descriptor overwrite is gone. No other workaround needed, ~33 FPS. Change: github.com/mrzacarias/AnyPS5@f6f6f118eb

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092647523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6092647523). Originally posted by [mrzacarias](https://github.com/mrzacarias) on 2026-10-10T02:19:33Z. --- Confirming on macOS (M1 Pro, MoltenVK): with the limit at 2 for blocking DCB submissions with a flip, and 16 kept for `sceVideoOutSubmitFlip`'s queue-full error, the vertex-descriptor overwrite is gone. No other workaround needed, ~33 FPS. Change: https://github.com/mrzacarias/AnyPS5/commit/f6f6f118eb2648922daebf89de0ed2df90ec9e9e
oneandonlydean commented 2026-10-10 03:08:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:08:44Z.


#1745 holds a queue 0 submission with a flip until the worker has reached every earlier flip, so the title can no longer get further ahead than the worker has read. Could you check Balatro with it instead of the lower limit?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093152872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6093152872). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:08:44Z. --- #1745 holds a queue 0 submission with a flip until the worker has reached every earlier flip, so the title can no longer get further ahead than the worker has read. Could you check Balatro with it instead of the lower limit?
adriadam10 commented 2026-10-10 08:46:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:46:02Z.


Partly addressed by #1100: indirect register lists are read when the command buffer is submitted, so the extended register semantics are not implemented abort no longer happens (covered by a new agc_driver_pm4 case), and #1038 fixes the NGS2: waveform block 0 does not fit its data stop the title hit next; still open: the flip queue depth question (title runs a frame slot ahead, other per-frame data can still be read late), where #1745 is open.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095809140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6095809140). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T08:46:02Z. --- Partly addressed by #1100: indirect register lists are read when the command buffer is submitted, so the `extended register semantics are not implemented` abort no longer happens (covered by a new `agc_driver_pm4` case), and #1038 fixes the `NGS2: waveform block 0 does not fit its data` stop the title hit next; still open: the flip queue depth question (title runs a frame slot ahead, other per-frame data can still be read late), where #1745 is open.
oneandonlydean commented 2026-10-10 10:59:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T10:59:34Z.


#1745 is merged: a flip now waits until the frame it shows has been rendered. Does Balatro still garble on current main?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096795254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6096795254). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T10:59:34Z. --- #1745 is merged: a flip now waits until the frame it shows has been rendered. Does Balatro still garble on current main?
THEMANnt commented 2026-10-10 20:14:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-10T20:14:31Z.


Tested Balatro(PPSA21402) version(01.015.000) on current main on Windows: full gameplay at ~60 FPS, no lag, and no errors or aborts. No garbled draws, black frames or flicker noticed. Audio works. Played about 10 minutes.

Setup

  • AnyPS5 main at 4a747c48
  • Windows 11 Pro 10.0.26200, AMD Ryzen 7 7800X3D 8-Core Processor
  • NVIDIA GeForce RTX 5070 Ti, driver 616.92 (an AMD integrated GPU is also present; the NVIDIA card was selected)
  • MinGW-w64 GCC 15.3.0 (WinLibs; the docs pin 15.2.0, so this is a different build than documented), Release build

Before the update: an earlier checkout without #1534 and #2219 stopped at startup, in videoout presentation, with:

depth/stencil clear, copy, resummarize or decompress draws (DB_RENDER_CONTROL) is unsupported (register 0x0 = 0x00000002)

Updating to current main, which includes #1534 and #2219, got past it.

Thanks for the work on this.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101737128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6101737128). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-10T20:14:31Z. --- Tested Balatro(PPSA21402) version(01.015.000) on current `main` on Windows: full gameplay at ~60 FPS, no lag, and no errors or aborts. No garbled draws, black frames or flicker noticed. Audio works. Played about 10 minutes. **Setup** - AnyPS5 `main` at 4a747c48 - Windows 11 Pro 10.0.26200, AMD Ryzen 7 7800X3D 8-Core Processor - NVIDIA GeForce RTX 5070 Ti, driver 616.92 (an AMD integrated GPU is also present; the NVIDIA card was selected) - MinGW-w64 GCC 15.3.0 (WinLibs; the docs pin 15.2.0, so this is a different build than documented), Release build **Before the update:** an earlier checkout without #1534 and #2219 stopped at startup, in videoout presentation, with: ``` depth/stencil clear, copy, resummarize or decompress draws (DB_RENDER_CONTROL) is unsupported (register 0x0 = 0x00000002) ``` Updating to current `main`, which includes #1534 and #2219, got past it. Thanks for the work on this.
oneandonlydean commented 2026-10-11 01:08:35 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:35Z.


Closing: #1745 fixed it, and it plays without garbled frames on current main (above).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104054528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1034#issuecomment-6104054528). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T01:08:35Z. --- Closing: #1745 fixed it, and it plays without garbled frames on current main (above).
Sign in to join this conversation.
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#1034
No description provided.