Repository navigation
Conversation
The up_begin fix (Little Nightmares II) closes one window of the upload deadlock: an upload batch's commit sits as a record in the open replay block (rec_commit_upload), the submit thread sleeps on a wait only the encode thread can resolve, and nothing hands the open block over mid-submission — the submission cannot end while its own thread blocks. mtl_finish_gpu has the same wait on the same thread: a loader calling nvnQueueFinish inside a submission while upload commits sit recorded in the open block sleeps on g_up_pending forever (the loader this file already documents — Three Houses waits once per resource it uploads — is exactly that shape). Publish the block first, as up_begin now does; the encode thread commits the batches, the completion handlers drop the counter and wake the waiter. Non-submit threads (suspend, diagnostics) cannot publish the submit thread's open block and keep the old behavior. Found analyzing a Hades II save-load freeze on an iPhone 14 Pro where the up_begin path was the one that hung (report: LNPANDY/NX2Apple#4; our independently derived up_begin fix came out word for word the same as yours). Checked: the host builds; Hades II v0 and v1.0.137848 save loads on the Mac host with the encode thread forced on (the iOS default), both smooth. Not checked: an iPhone.
…thread at once (general, from PR #141). With the encode thread on (the iOS default, DM_NVN_ENC_THREAD), an upload batch's commit is a record in the encode thread's current block (rec_commit_upload), which is handed over when the block fills or a submission ends. Outside a submission (no replay command buffer: a texture zeroed at creation, tex_zero_fill, or a packaged texture uploaded between submissions) up_flush meant to commit the batch on the spot, but the record stayed in the block until the next submission, and every wait for it waited for that submission: nvnQueueFinish (mtl_finish_gpu, on any thread) or up_begin on a busy slot. A game whose last submitting thread creates a texture and then calls nvnQueueFinish before it submits again waited for good. up_flush now hands the block over when it runs outside a submission (it runs on the submit thread only, up_owner_check). From PR #141 (LNPANDY, found analysing a Hades II save-load freeze on an iPhone 14 Pro): mtl_finish_gpu hands over the block before it waits when it runs on the submit thread, as up_begin does since 9cb7af3 and q_cb does; nvnQueueFinish cannot run inside a submission (one nvnQueueSubmitCommands call, which ends with rec_drain), so that line matters for the window above and for the diagnostics that wait mid-submission (td_dump, DM_NVN_T2T_TRACE). Checked: dmhost builds for Super Mario Bros. Wonder (NVN) and Hades (Vulkan), the host unit tests pass, the graphics run list passes, and with DM_NVN_ENC_THREAD=1 every test passes but t_rt_range, which stops on main alike (DmRecEnc has no stand-in for the copyFromTexture:...toBuffer:...options: form). Not checked: a game, the iPhone
|
Thanks! Ported in b87a0cc with your
To cover every waiter, Checked: the host builds, the host unit tests and the graphics run list pass, and so do the graphics tests with |
|
Thank you for the port and the correction — much appreciated. Your analysis of the window is cleaner than mine: I had reasoned from the Three Houses comment that QueueFinish could arrive mid-submission, but as you say a submission is one We'll relay a result from the reporter as soon as he rebuilds (his device is an iPhone 14 Pro on iOS 26.7.1). |
…thread at once (general, from PR seedds#141). With the encode thread on (the iOS default, DM_NVN_ENC_THREAD), an upload batch's commit is a record in the encode thread's current block (rec_commit_upload), which is handed over when the block fills or a submission ends. Outside a submission (no replay command buffer: a texture zeroed at creation, tex_zero_fill, or a packaged texture uploaded between submissions) up_flush meant to commit the batch on the spot, but the record stayed in the block until the next submission, and every wait for it waited for that submission: nvnQueueFinish (mtl_finish_gpu, on any thread) or up_begin on a busy slot. A game whose last submitting thread creates a texture and then calls nvnQueueFinish before it submits again waited for good. up_flush now hands the block over when it runs outside a submission (it runs on the submit thread only, up_owner_check). From PR seedds#141 (LNPANDY, found analysing a Hades II save-load freeze on an iPhone 14 Pro): mtl_finish_gpu hands over the block before it waits when it runs on the submit thread, as up_begin does since 874c7c5 and q_cb does; nvnQueueFinish cannot run inside a submission (one nvnQueueSubmitCommands call, which ends with rec_drain), so that line matters for the window above and for the diagnostics that wait mid-submission (td_dump, DM_NVN_T2T_TRACE). Checked: dmhost builds for Super Mario Bros. Wonder (NVN) and Hades (Vulkan), the host unit tests pass, the graphics run list passes, and with DM_NVN_ENC_THREAD=1 every test passes but t_rt_range, which stops on main alike (DmRecEnc has no stand-in for the copyFromTexture:...toBuffer:...options: form). Not checked: a game, the iPhone
The up_begin fix (Little Nightmares II) closes one window of the upload deadlock: an upload batch's commit sits as a record in the open replay block (
rec_commit_upload), the submit thread sleeps on a wait only the encode thread can resolve, and nothing hands the open block over mid-submission — the submission cannot end while its own thread blocks.The sibling window this PR closes.
mtl_finish_gpu(nvnQueueFinish) waits ong_up_pendingthe same way, on the submit thread, mid-submission: a loader that calls QueueFinish inside a submission while one or more upload commits sit recorded in the open block sleeps forever. The loader this file already documents — Fire Emblem: Three Houses "submits a copy and calls QueueFinish for each resource it uploads" — is exactly that shape.The fix is the same publish up_begin now does: hand the open block to the encode thread before the wait, so the pending upload batches commit, their completion handlers drop the counter and wake the waiter. Non-submit threads (suspend, diagnostics) cannot publish the submit thread's open block and keep the old behavior.
How it was found: analyzing a Hades II save-load freeze on an iPhone 14 Pro (iOS 26.7.1) where the hung stack was the up_begin path (report: LNPANDY/NX2Apple#4). The up_begin half of the fix was derived independently from that report and came out word for word the same as yours — this PR builds on your version and adds the
mtl_finish_gpuhalf.Checked: the host builds with the change; Hades II v0 and v1.0.137848 save loads on the Mac host with the encode thread forced on (
DM_NVN_ENC_THREAD=1, the iOS default), both smooth, no regression. Not checked: an iPhone (the reporter is testing the full fix on one).