From 91c6768df6d894df7fac184e98f8bba5f1106ccd Mon Sep 17 00:00:00 2001 From: UwUCammie Date: Tue, 24 Nov 2026 18:42:16 +0000 Subject: [PATCH] runtime: warn at start when the host has no default audio output (RT-NO-AUDIO-ENDPOINT-DEADLOCK) With no default audio render endpoint the retail title skips its audio device setup and later stops on a loading screen after the first-run screens: its per-frame audio update returns early while holding a lock, the frame thread waits on that lock for good, the frame counter stops and the main thread waits for frames that never come. Nothing crashes, so the cause is hard to find from the logs. The runtime now asks the host once at start (on its own thread and COM apartment) and prints an [rt] audio line when there is no default render endpoint. docs/boot.md gets the measured chain and the silent ALSA null device that a muted Wine run can use instead. --- docs/README.md | 2 +- docs/boot.md | 41 ++++++++++++++++- runtime/src/audio_endpoint_probe.h | 70 ++++++++++++++++++++++++++++++ runtime/src/main.cpp | 8 ++++ 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 runtime/src/audio_endpoint_probe.h diff --git a/docs/README.md b/docs/README.md index d78fca3fbf..b77ab6b900 100644 --- a/docs/README.md +++ b/docs/README.md @@ -70,7 +70,7 @@ method, scope and caveats. No game data is included. | [d3d12_vulkan.md](d3d12_vulkan.md) | Xbox D3D12 to Vulkan plan and status; device proxy, queues, command lists, barriers, copies. | | [mobile.md](mobile.md) | arm64/mobile path: the x86-64 → arm64 static-recompiler groundwork (`tools/x64_recomp.py`), the `.pdata` coverage census (`tools/recomp_census.py`), and what still blocks iOS. | | [first_run_ui.md](first_run_ui.md) | Build the Windows integration and display the offline first-run controller prompts; the scripted-pad route through the first-run pages to the story load. | -| [boot.md](boot.md) | The first real boot: the `gta6rt --trace`/`--trace-d3d12` runbook, the startup + D3D12 trace summary (`tools/boot_trace.py`), the triage order and the Q1–Q22 checklist. | +| [boot.md](boot.md) | The first real boot: the `gta6rt --trace`/`--trace-d3d12` runbook, the startup + D3D12 trace summary (`tools/boot_trace.py`), the triage order, the Q1–Q22 checklist and the stop on a loading screen when the host has no audio output. | | [retail_boot_chain.md](retail_boot_chain.md) | How far `gta6rt --run` gets with the retail executable: the stops in order and what clears each, the physical-page export shapes, device slots 26, 48 and 73, and the device slots the executable calls, counted from the file (`tools/d3d12_device_calls.py`). | | [retail_boot_intel_host.md](retail_boot_intel_host.md) | The retail boot on an Intel host with 16 GB: which stops of the two boot pages hold there with #7111, the commit-limit stop at the 6.1 GiB physical-page request that #7556 clears, the frame loop to the 900 s timeout with stub pipelines, and what the layer refuses at that depth (the console mesh-shader subobject among it). | | [modding.md](modding.md) | The mod format: a `mods//mod.json` next to `gta6rt.exe` or under `--mods DIR`, swapping a named (or `joaat`) archetype for another; the `tools/leonida_mods.py` manager (`Mods.bat` on Windows, `Mods.sh` on Linux and macOS); load order, the start-up log, and the fact that a swap waits for the executable's archetype lookup address (RT-5). | diff --git a/docs/boot.md b/docs/boot.md index 2afbb51ec9..742ba666e0 100644 --- a/docs/boot.md +++ b/docs/boot.md @@ -283,7 +283,46 @@ order. It maps each question to the event to look for; it does not answer them. does not affect these outcomes. * `exit` is the game's own code, not the loader's. A crash after the first frame is the next layer question. -## 6. Limits +## 6. No audio output device + +The title needs a default audio output. With none it does not fail at once: it stops after the first-run screens +(the account, privacy and terms screens), on a dark loading screen that keeps being drawn. Nothing crashes and no +`unimplemented_call` or `exception` points at it. The runtime prints an `[rt] audio:` line at start when the host has +no default render endpoint (`runtime/src/audio_endpoint_probe.h`). A Wine prefix with `winealsa.drv` and +`winepulse.drv` disabled, or a sandbox without `/dev/snd` and the sound server's sockets, is the usual way to get +there, and so is a muted test run. + +Measured on the Xbox package 1.0.2.1 under Wine 11.22, with breakpoints and hit counts (`LEONIDA_BREAK`): + +1. While it starts its audio, the title asks for the default render endpoint once + (`IMMDeviceEnumerator::GetDefaultAudioEndpoint(eRender, eConsole)`, RVA `0x43aec05`). When that fails it skips its + audio device setup (RVA `0x1e7f580`, which activates `IAudioClient` and `ISpatialAudioClient`), so the audio + object's list of outputs stays empty. +2. The per-frame audio update (RVA `0x5267720`) takes that object's lock, finds no outputs and returns without + releasing it (its early return at RVA `0x5267cfb`). It ran on a pool worker that then went back to waiting for + jobs while still owning the lock. +3. The frame thread takes the same lock (RVA `0x5594650`, called from RVA `0x1e95161`) and waits on it for good. The + frame tick (RVA `0x43ae230`, which advances the frame counter and wakes threads parked on it) ran once in the + whole run. +4. The main thread parks in a startup step (RVA `0x2431600`) until the frame counter moves on and is never woken. + Every streaming update the main thread drives stops with it, so a later synchronous streaming request (the loop + at RVA `0x3a158a9`) waits for ever. + +With an output device, the same build gets past this point: the audio setup runs, the early return is never taken +and the frame tick keeps running. A console always has an output, so the early return is not reached there. + +A silent device is enough. For a muted run under Wine, keep `winealsa.drv` enabled and point ALSA at its null +plugin, which needs no sound card and plays nothing: + +```sh +printf 'pcm.!default { type null }\npcm.null { type null }\nctl.!default { type hw card 0 }\n' > null-alsa.conf +WINEDLLOVERRIDES='winepulse.drv=d' ALSA_CONFIG_PATH="$PWD/null-alsa.conf" wine gta6rt.exe --run ... +``` + +`ALSA_CONFIG_PATH` replaces ALSA's own configuration, so the file must stand alone. A list that adds it after the +system file does not work: the sound server's default from the system configuration still wins. + +## 7. Limits The retail executable is not in the package, so this page is untested against it; the tool and the trace formats are tested on synthetic fixtures and on `tiny_game` (which has no D3D12 calls). The present slots (Q6) and the diff --git a/runtime/src/audio_endpoint_probe.h b/runtime/src/audio_endpoint_probe.h new file mode 100644 index 0000000000..d697ca4832 --- /dev/null +++ b/runtime/src/audio_endpoint_probe.h @@ -0,0 +1,70 @@ +// Whether the host has a default audio render endpoint (docs/boot.md, "No audio output device"). +// +// The retail title asks for the default render endpoint (IMMDeviceEnumerator::GetDefaultAudioEndpoint(eRender, +// eConsole)) once while it starts its audio. Without one it skips its audio device setup, runs on, and stops after the +// first-run screens: its per-frame audio update returns early while it still holds a lock, the frame thread waits on +// that lock for good, and the frame counter the loading code waits on never moves again. Nothing crashes and the +// loading screen keeps being drawn, so the cause is easy to miss. A console always has an output, so the runtime says +// so at start when the host has none; a Wine prefix with its audio drivers off, or no sound device, is the usual case. +// +// The probe runs on its own short-lived thread, in its own COM apartment, so the thread that later runs the title +// starts with no COM state of ours. +#pragma once + +#include + +#include + +namespace rt::audio_probe { + +enum class Endpoint { + present, // a default render endpoint exists + missing, // the enumerator answered, and there is no default render endpoint + unknown, // COM or the enumerator itself failed; nothing is reported +}; + +namespace detail { +struct ProbeResult { + Endpoint endpoint = Endpoint::unknown; + HRESULT hr = S_OK; // GetDefaultAudioEndpoint's result when the enumerator was created +}; + +inline DWORD WINAPI probe_thread(void* param) { + auto* out = static_cast(param); + const HRESULT init = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(init)) return 0; + IMMDeviceEnumerator* enumerator = nullptr; + if (SUCCEEDED(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), + reinterpret_cast(&enumerator))) && + enumerator) { + IMMDevice* device = nullptr; + out->hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &device); + out->endpoint = SUCCEEDED(out->hr) && device ? Endpoint::present : Endpoint::missing; + if (device) device->Release(); + enumerator->Release(); + } + CoUninitialize(); + return 0; +} +} // namespace detail + +// Asks the host once; waits at most `timeout_ms` for the answer (an audio service that hangs is reported as unknown). +inline Endpoint default_render_endpoint(HRESULT* hr = nullptr, DWORD timeout_ms = 5000) { + // Heap-held so a probe thread that outlives the wait still writes into live memory; it is freed only after the + // thread has finished, and leaked (a few bytes, once) when it has not. + auto* result = new detail::ProbeResult; + HANDLE thread = CreateThread(nullptr, 0, &detail::probe_thread, result, 0, nullptr); + if (!thread) { + delete result; + return Endpoint::unknown; + } + const bool finished = WaitForSingleObject(thread, timeout_ms) == WAIT_OBJECT_0; + CloseHandle(thread); + if (!finished) return Endpoint::unknown; + const detail::ProbeResult r = *result; + delete result; + if (hr) *hr = r.hr; + return r.endpoint; +} + +} // namespace rt::audio_probe diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index c8545f338e..e729ccd05a 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -176,6 +176,7 @@ void start_title_peek(std::uint8_t* base) { } // namespace +#include "audio_endpoint_probe.h" #include "base_reservation.h" #include "compile_gate_policy.h" #include "code_hooks.h" @@ -559,6 +560,13 @@ int wmain(int argc, wchar_t** argv) { if (!rt::cpu_emulation::install()) std::fprintf(stderr, "[rt] cpu: AddVectoredExceptionHandler failed (error %lu); instructions this CPU lacks " "will stop the game\n", GetLastError()); + // Without a default audio output the title stops after its first-run screens (docs/boot.md, "No audio output + // device"): said here, since nothing later points at it. + if (HRESULT hr = S_OK; rt::audio_probe::default_render_endpoint(&hr) == rt::audio_probe::Endpoint::missing) + std::fprintf(stderr, "[rt] audio: the host has no default audio output (GetDefaultAudioEndpoint 0x%08lX); the game " + "will stop on a loading screen after its first-run screens. Give Wine an output device, " + "a silent one is enough (docs/boot.md, \"No audio output device\")\n", + static_cast(hr)); try { rt::Loader loader(game_dir);