Skip to content

AudioOut: expose initialized state until output consumers are closed - #109

Closed
Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/audioout-initialized-lifetime
Closed

Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/audioout-initialized-lifetime

Conversation

@Jpkovas

@Jpkovas Jpkovas commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Some middleware checks the first word of its guest AudioOut object before Stop/Close. The host creates an output without marking that word initialized, so the middleware can skip Close, unmap its PCM storage and leave the old consumer running. In a local LM3 resume failure this ended in SIGBUS while copying from that freed storage, at a footprint well below the earlier memory-limit failure.

Set the guest initialization word after a successful Open; clear it only after Close has stopped/destroyed all consumers and removed the session. Native state remains in objmap. The already-integrated six-channel downmix from #96 is unchanged.

The new regression uses the same guest-side guard for 12 close/unmap/resume/reopen cycles. Old PCM and descriptor pages remain reserved with PROT_NONE so a stale consumer cannot accidentally read a newly allocated buffer at the same address. On the public base the test fails because Open leaves the word zero. With this patch alone it passes with both the silent sink and the real AudioUnit using all-zero, inaudible PCM; existing surround, suspend/resume, watchdog and SPSC coverage remains relevant.

make -C dm/host/tests GAME=0100DCA0064A6000 build/t_audio build/t_audio_spsc
dm/host/tests/build/t_audio
dm/host/tests/build/t_audio_spsc

The regression proves the output lifetime/guard contract. A local combined device update carries the correction, but the real app-switch/resume flow has not yet been accepted on the iPhone. No private module addresses, decompiled game code, buffers or device logs are attached.

Public source base: d979c346b9a188d63ae16ec6f73e099a3c7f5a05. Each patch is independent of the other proposals in this batch.

seedds added a commit that referenced this pull request Oct 24, 2026
…ral, found on Luigi's Mansion 3): no blending on integer targets, primitive restart in fan and quad expansion, partial depth-stencil clears, every name of an upgraded texture, the SDK's AudioOut fields. nvn_mtl.m pso_desc (#105): an integer colour target took the game's blend enable, and Metal refuses such a pipeline with an assertion even without the API validation layer (checked on this Mac); Maxwell ignores blending on integer targets, so it is off for them. draw (#110): indexed triangle fans and quads expanded on the CPU read the restart index as a vertex and joined the polygons across it, and the extra triangles cleared parts of Luigi's Mansion 3's cached shadow depth; nvn_primitive.h ends a polygon at the restart index (compared before the base vertex), at most as many triangles as before. OP_CLEAR_DS (#108): a depth-stencil clear whose scissor does not cover the target, or whose stencil mask is partial, cleared the whole target before the first draw, and a partial stencil mask did so in a pass too; both are drawn as a triangle now (clear_ds_tri), full clears stay load actions. Logs on the T7 show who takes the new path: Tears of the Kingdom clears 8x8 tiles of a 64x64 depth target (each clear wiped the whole target), AI: THE SOMNIUM FILES clears 1280x720 of a 1920x1080 one. tex_upgrade (#107): a texture recreated to add a usage replaced only the asking serial and one sharing-table entry, so other serials on the same storage read the old copy; every entry in g_by_serial, g_ghost and g_alias now moves to the new texture in place, g_alias_set follows, and the old one is retired after the submissions that used it. hle_audio.c (#109, reworked): the host left the guest AudioOut zero, and middleware that checks its first word before Stop / Close skipped the close, freed its PCM and the host's consumer read freed memory (SIGBUS on resume in Luigi's Mansion 3). The PR wrote 1 and cleared it on close; the SDK's OpenAudioOut (SDK 8, 12, 18 and 20 checked) writes sample rate, channel count, sample format and state at +0 / +4 / +8 / +0xc, its getters load from there, and CloseAudioOut only sets the state to stopped, so the host now writes the same (au_info). New tests t_integer_blend (63 checks), t_primitive_restart (37), t_clear_ds (43), t_upgrade_alias (10) in the gfx run list, and an AudioOut fields and lifetime case in t_audio (12 guarded open / close / unmap / resume cycles, silent sink and real output). Checked: the four new tests pass under Metal validation; every other gfx test gives the same result as on main (t_fuse_check, t_reorder_chain, t_defer_chain, t_mip_extent, t_rt_range_ro and t_rt_range fail the same cases on both; t_refl finds no reflection samples in this checkout's shader cache); the host unit tests pass; on the Mac host for 90 s from boot, against main built the same way: Breath of the Wild over the title, 60 fps and the same red lines; AI: THE SOMNIUM FILES (shaders built by the NSP script on this chain), whose 1280x720 depth clears at the start of a pass now take the triangle path too (from pass 119), 60 fps, no red line, 5 long frames against 12. Not taken from this batch: #106 (the stencil-only view of a depth-stencil texture works without format-view usage; only the validation layer asks for it, and the PR would put that usage on every depth-stencil buffer), #111 (an opt-in draft with no memory saving shown), #104 (Mac app bundle)

Co-authored-by: João Karalkovas <[email protected]>
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Ported in bc5ba1b, reworked. The SDK's own OpenAudioOut (checked in SDK 8, 12, 18 and 20) writes sample rate, channel count, sample format and state at +0 / +4 / +8 / +0xc, and its getters read them from there. CloseAudioOut only sets the state to stopped; it doesn't clear the first word. So the host now writes those same fields (au_info in hle_audio.c), not 1 / 0. The first word is still non-zero after Open, which is what your middleware checks. Your lifetime test is kept, adapted to those fields.

@seedds seedds closed this Oct 24, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…eedds#109 and seedds#110 (general, found on Luigi's Mansion 3): no blending on integer targets, primitive restart in fan and quad expansion, partial depth-stencil clears, every name of an upgraded texture, the SDK's AudioOut fields. nvn_mtl.m pso_desc (seedds#105): an integer colour target took the game's blend enable, and Metal refuses such a pipeline with an assertion even without the API validation layer (checked on this Mac); Maxwell ignores blending on integer targets, so it is off for them. draw (seedds#110): indexed triangle fans and quads expanded on the CPU read the restart index as a vertex and joined the polygons across it, and the extra triangles cleared parts of Luigi's Mansion 3's cached shadow depth; nvn_primitive.h ends a polygon at the restart index (compared before the base vertex), at most as many triangles as before. OP_CLEAR_DS (seedds#108): a depth-stencil clear whose scissor does not cover the target, or whose stencil mask is partial, cleared the whole target before the first draw, and a partial stencil mask did so in a pass too; both are drawn as a triangle now (clear_ds_tri), full clears stay load actions. Logs on the T7 show who takes the new path: Tears of the Kingdom clears 8x8 tiles of a 64x64 depth target (each clear wiped the whole target), AI: THE SOMNIUM FILES clears 1280x720 of a 1920x1080 one. tex_upgrade (seedds#107): a texture recreated to add a usage replaced only the asking serial and one sharing-table entry, so other serials on the same storage read the old copy; every entry in g_by_serial, g_ghost and g_alias now moves to the new texture in place, g_alias_set follows, and the old one is retired after the submissions that used it. hle_audio.c (seedds#109, reworked): the host left the guest AudioOut zero, and middleware that checks its first word before Stop / Close skipped the close, freed its PCM and the host's consumer read freed memory (SIGBUS on resume in Luigi's Mansion 3). The PR wrote 1 and cleared it on close; the SDK's OpenAudioOut (SDK 8, 12, 18 and 20 checked) writes sample rate, channel count, sample format and state at +0 / +4 / +8 / +0xc, its getters load from there, and CloseAudioOut only sets the state to stopped, so the host now writes the same (au_info). New tests t_integer_blend (63 checks), t_primitive_restart (37), t_clear_ds (43), t_upgrade_alias (10) in the gfx run list, and an AudioOut fields and lifetime case in t_audio (12 guarded open / close / unmap / resume cycles, silent sink and real output). Checked: the four new tests pass under Metal validation; every other gfx test gives the same result as on main (t_fuse_check, t_reorder_chain, t_defer_chain, t_mip_extent, t_rt_range_ro and t_rt_range fail the same cases on both; t_refl finds no reflection samples in this checkout's shader cache); the host unit tests pass; on the Mac host for 90 s from boot, against main built the same way: Breath of the Wild over the title, 60 fps and the same red lines; AI: THE SOMNIUM FILES (shaders built by the NSP script on this chain), whose 1280x720 depth clears at the start of a pass now take the triangle path too (from pass 119), 60 fps, no red line, 5 long frames against 12. Not taken from this batch: seedds#106 (the stencil-only view of a depth-stencil texture works without format-view usage; only the validation layer asks for it, and the PR would put that usage on every depth-stencil buffer), seedds#111 (an opt-in draft with no memory saving shown), seedds#104 (Mac app bundle)

Co-authored-by: João Karalkovas <[email protected]>
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 11, 2026
…arks and teleport, the build and offsets in its profile' (seedds#109) from Omnicrash/BananaNative-fork:pr/dk-devtools into android

Reviewed-on: https://git.eden-emu.dev/moceure/BananaNative/pulls/109
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 12, 2026
…, seedds#164, seedds#165, seedds#109, seedds#166-seedds#168)

Conflicts: the launcher profile columns 18 (fps_steps) and 19 (mesh_vegetation_cut) are taken,
so variants move to column 20; GAME_SETTINGS keeps hold60, full_vegetation and aspect;
docs/agents/game-patches.md regenerated. moceure#39 (whose old commit 0749171 could not be fetched
from the server) touches no file of this PR but env_switches.tsv, which merges cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants