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
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 (
mainf1efcc67+ #1020 + #1032, which it needs to get this far):The indirect register list (
0x9fpacket, 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_CAPACITYis 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 had0 0 bdcccccd 0 bf800000 3f800000 0 3f800000 .... These are floats:0x3a888889is 2/1920 and0xbaf2b9d6is -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
memcpywriting 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):
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.
Where the number comes from
VIDEO_OUT_FLIP_QUEUE_CAPACITY = 16(core/libs/prx/libSceVideoOut/include/VideoOutDriver.hpp:61) was added ind225df74(the first SDL window commit). I could not find a measurement behind it.WaitForFlipRoom()(VideoOutDriver.cpp:63, called fromDriver::waitForFlipRoom,Submission.cpp:89) only blocks a submission that contains a flip when 16 flips are pending.SubmitFlipreturnsVIDEO_OUT_ERROR_FLIP_QUEUE_FULLat the same count (VideoOutDriver.cpp:341).sceKernelWaitEqueue,sceVideoOutGetFlipStatusorsceVideoOutIsFlipPending, so the only thing holding its CPU side back is the submit blocking.What I don't know
Proposal
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.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.
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.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.elffile offset0x1014b8: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 to0xffffffff(0xffe39..0xfff33). The only other write to those labels is each frame's last packet,RELEASE_MEMof the 64-bit value0xffffffffto0x280000000 + 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_CAPACITYis also the threshold at whichsceVideoOutSubmitFlipreturnsVIDEO_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.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@f6f6f118ebImported 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?
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 implementedabort no longer happens (covered by a newagc_driver_pm4case), and #1038 fixes theNGS2: waveform block 0 does not fit its datastop 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.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?
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-10T20:14:31Z.
Tested Balatro(PPSA21402) version(01.015.000) on current
mainon 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
mainat4a747c48Before the update: an earlier checkout without #1534 and #2219 stopped at startup, in videoout presentation, with:
Updating to current
main, which includes #1534 and #2219, got past it.Thanks for the work on this.
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).