Skip to content

runtime: count XMA context and XApu command activity in the audio stand-ins - #2107

Merged
R0Y00 merged 11 commits into
R0Y00:mainfrom
JohnConnorNPC:audio/xma-activity
Nov 28, 2026
Merged

R0Y00 merged 11 commits into
R0Y00:mainfrom
JohnConnorNPC:audio/xma-activity

Conversation

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Title (draft): runtime: count XMA context and XApu command activity in the audio stand-ins

Change

Refs #1145. Before any XMA decode work, this adds a way to observe what a caller does with the audio processor through the
desktop stand-ins. With X2W_AUDIO_PERMISSIVE=1 and the new opt-in X2W_AUDIO_ACTIVITY=1:

  • AcpHal.dll keeps a copy of the XMA context array that AcpHalAllocateShapeContexts hands out, compares it about every 10 ms and
    counts contexts filled (all zero to nonzero), changed and cleared, plus HAL slot2 submits by their type argument. No field inside
    a context is read or identified. ApuFree of the array ends the count before the block can be reused.
  • xapu.dll counts every XApuEnqueueCommand call by command class (the first UINT32 of the command), with no cap. Unreadable
    commands and unknown handles are counted separately.
  • Each DLL logs one line per second, only when a count moved. The experimental exports x2w_acphal_xma_activity and
    x2w_xapu_command_counts return the totals.
  • With the variable unset, the code starts no thread, reads no caller memory and logs no line. That gating is in the code and
    is for review to confirm; the fixture cannot observe it directly. What the fixture's off case does check is the observable
    behaviour: the exports return FALSE with zeros, no activity line is logged, and every return value, output, last error and the
    final context bytes match the run with the counter on.

The 64-byte context stride and the command class are stand-in conventions, not console contracts. The counter decodes nothing and
does not establish which counted event starts playback.

The first commit closes a code fence that was already open in docs/experiments.md and is a prerequisite: without it, the new
documentation section, together with the existing "ApuFree in the AcpHal stand-in" section, renders as code and its links are not
checked by tests/docs_links_check.py. It is one line and can be split into its own PR if you prefer.

Verification

Commit under test: 73728f98 (base 5a0b0aad).

cmake --build --preset release --target startup_acphal_xma_activity
ctest --preset release --no-tests=error -R '^startup_acphal_xma_activity$' -V

I have not run this on Windows. The pull-request job (cmake --build --preset pr, ctest --preset pr) does not build the
startup stand-ins or run their fixtures, so a green PR check does not cover this change. That is the same for the existing
startup_acphal_apu_free and startup_xapu_queue fixtures. A Windows result for both configurations comes from
Actions → Windows checks → Run workflow on this branch (workflow_dispatch), or from the main-branch run after merge.

Supporting evidence only (Linux host, clang-cl/xwin cross build, run under Wine):

  • startup_acphal_xma_activity: case on: ok, case none: ok, case off: ok, startup_acphal_xma_activity: ok, exit 0 (4.4 s).
  • Stand-in group, ctest --no-tests=error -R '^startup_(acphal|xapu|stubs$|local_log)' -V:
    • startup_acphal_apu_free and startup_xapu_queue pass.
    • startup_stubs resolves AcpHal.dll 10/10 and xapu.dll 6/6 exports. Under Wine it also fails one unrelated case
      (dstorage page-array control), and it fails that case the same way on the base commit.
    • startup_local_log is run because src/startup_stubs/local_log.h gains one inline helper. Under Wine it exits 5 with two
      FAIL lines (concurrent logf lines are all present and intact, concurrent logging child passes), the same as on the base
      commit; its four _control tests pass.
  • tests/docs_links_check.py: 402 links, none broken. tests/bidi_controls_check.py: clean. Platform-independent Python checks
    (the CI list): 80 of 80 pass.

Not measured: Windows CI, the CMake presets on Windows, the Windows loader, and Windows timer resolution (the 10 ms sample period
depends on it).

Evidence and follow-up

The fixture is source-built and uses only synthetic inputs: one caller script, run in three child processes.

  • on: fills 5 contexts, changes 3 and clears 2. It submits 4 HAL commands (types 1, 1, 3 and 12) and enqueues 6 XApu commands
    (classes 1, 2 and 0x20), plus one null command and one command on an unknown handle. The exports and the summed log lines must give
    exactly these counts. The freed array must come back from ApuAlloc as the same block, and writes to it must not be counted.
  • none (zero-write control): writes only the 64 bytes right after the last context and sends nothing. Every count must be 0 and
    no line may be logged.
  • off: the exports return FALSE with zeros, and no line is logged.
  • Every result, output, last error and the final context bytes must be identical with the counter on and off.

Negative controls: I applied each mutation to the final tree and confirmed the fixture fails, each time on the check it targets:

  • a gate ignored when unset;
  • cleared counted as changed;
  • the class read from the second word;
  • no stop at ApuFree;
  • the last 8 bytes of a context skipped;
  • no log line;
  • one extra context watched, or one extra context scanned with the watched count unchanged (this one fails only the zero-write
    control);
  • the caller's last error clobbered (fails only the on/off comparison);
  • a null output written by an export;
  • ApuFree not returning the block;
  • a broken docs anchor.

Next step for #1145: use these counts to see whether an application writes or enables XMA contexts, and which counted event goes
with it, before any decoder work.

Checklist

  • This pull request covers one reviewable behavior (plus the one-line fence prerequisite described above).
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed (docs/startup-runtime.md, docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opt-in AcpHal sampler runs forever after its first event and closes its thread handle immediately. A regular DLL client can FreeLibrary while that worker is asleep or inside the sampler, leaving it with a return address in the unloaded module. Please tie sampler lifetime to the DLL use (or use synchronous observations), and add a source-built test that loads the DLL, starts activity, then unloads it in a child that stays alive and exits cleanly. Please also run the actual stand-in tests on Windows; the fast PR job does not run them.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 73728f9854c442ec9fbec47baa4521a9ed2682dd (external PR, comment only).

Commands executed

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 2107: Linux Python checks, Windows build and gfx1013 fixtures pass; the /O2 and chart jobs are skipped.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/bidi_controls_check.py: pass.
  • python3 tests/docs_links_check.py: pass (18 files, 402 links).
  • Win2025 (Server 2025 build 26100, MSVC 14.44, WARP), targets startup_acphal_xma_activity, startup_stub_acphal, startup_stub_xapu, ctest -R startup_acphal_xma_activity: Debug 1/1 passed, Release /O2 1/1 passed.
    • The default full-scope run failed on the Windows command-line length limit (PowerShell command over 8191 chars), so I reran with --scope direct and the explicit targets above. This does not run the rest of the suite.

Mutation

  • src/startup_stubs/acphal.cpp:152: swapped the changed and cleared counters (now ? activity.cleared : activity.changed).
  • Win2025 Debug: startup_acphal_xma_activity FAILED (expected xma.changed=3 xma.cleared=2). The mutation is killed. Reverted with git checkout -- ..

Findings

  • P1: none.
  • P2: none.
  • P3 src/startup_stubs/xapu.cpp (activity_thread, summary line): commands= counts classes plus unreadable but not rejected, while rejected= is printed on the same line. A reader may expect commands to be every call. Consider naming it in the doc line or in the log text.
  • P3 src/startup_stubs/acphal.cpp:129-146 (sample_locked): sampling is a 10 ms poll, so a context filled and cleared between two samples is not counted. The comment and docs already say this. Fine as documented.
  • P3 src/startup_stubs/acphal.cpp (watch): if AcpHalAllocateShapeContexts runs again without an ApuFree of the old array, the old shadow is replaced after one last sample. This is handled correctly. A test for this path would be a nice extra.

Checked and fine: the activity code is off unless X2W_AUDIO_ACTIVITY=1. The unwatch call under the lock in ApuFree runs before heap_give, so the sampler thread cannot read a reused block. GetLastError is saved and restored. The unreadable command is guarded by x2w_local::readable.

AI-assisted; commands listed were executed locally.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator Author

Thanks for the reviews. Two new commits on top of 73728f98, then a merge of main: 6f9d0702 (gh #1145 review round 2107-1) and c8067462 (gh #1145 review round 2107-2). The branch merges cleanly with current main. After git fetch origin, main 009153b7 is merged into the branch (f4b2d80b); git merge-tree --write-tree --name-only origin/main HEAD at f4b2d80b against origin/main 009153b7 printed only the tree id 6d0a89a1 and exited 0, with no conflicted files.

Sampler lifetime (R0Y00). Both stand-ins no longer start a thread. AcpHal now compares the XMA context array with its copy only inside the calls that count:

  • the HAL slot2 submit;
  • AcpHalAllocateShapeContexts;
  • every ApuFree once counting has started;
  • x2w_acphal_xma_activity.

It samples at most once per 10 ms, except where a call needs a final sample (re-allocation, ApuFree of the watched array, the export). A counted call made at least a second after the DLL's previous line (or after its first counted call) writes the next line, but only if a count moved. Until then, the counts wait for a later call. As a result, counts from the last second before a caller's final call, and changes made after that call, are never logged, though the exports still return them. xapu does the same from XApuEnqueueCommand and x2w_xapu_command_counts.

I chose synchronous observation over keeping a worker thread, for three reasons:

  • A worker that pins the DLL and exits with FreeLibraryAndExitThread would be safe, but nothing could ask it to stop: DLL_PROCESS_DETACH never arrives while the worker holds its reference. The DLL would then stay loaded after the client's FreeLibrary, so the sampler still would not follow DLL use.
  • Joining an unpinned worker in DLL_PROCESS_DETACH waits for a thread exit, and thread exit needs the loader lock that DllMain already holds.
  • A thread-pool timer with SetThreadpoolCallbackLibrary depends on loader and pool behaviour that I cannot check on both Windows and Wine.

With no thread, no code from either DLL runs except during a call into it. The cost is the logging gap above, and the sampling interval now follows the caller's call rate. The docs state both.

Unload test. startup_acphal_xma_activity has a fourth child case, unload, which runs with permissive and activity on. It:

  • creates the heap and the HAL object and submits once;
  • allocates and writes contexts;
  • enqueues one XApu command;
  • calls FreeLibrary on both DLLs;
  • checks with GetModuleHandleExA(FROM_ADDRESS) that both images are unmapped;
  • sleeps 1.5 s, longer than the old 10 ms and 1 s thread periods, and must exit 0.

The per-case wait is now 12 s, so all four cases fit the 60 s CTest timeout.

tedin7 P3s.

  • commands= vs rejected=: the xapu line now reads ...; rejected=1 (not in commands), and the docs say that commands= is the classes plus the unreadable commands.
  • AcpHalAllocateShapeContexts run again without ApuFree: the unload case covers this. A change to the old array before the second call is counted (by its last sample). A later change to the old array is not counted, and a fill of the new array is. Expected result: watched=4 live=1 filled=2.
  • 10 ms poll: still documented, now as "at most once per 10 ms, inside counted calls".

Results. Linux, clang-cl/xwin cross build, run under Proton Experimental Wine:

At f4b2d80b (clean tree):

  • ctest --test-dir out/build/w1 --no-tests=error -R '^startup_acphal_xma_activity$': Test #127: startup_acphal_xma_activity ... Passed, 1/1, exit 0.
  • Python CI list from windows.yml (92 checks): all 92 checks passed.
  • docs_links_check.py: 18 files, 412 links, pass.
  • bidi_controls_check.py: pass.

At 6f9d0702 (clean tree), ctest ... -R '^startup_(acphal|xapu|stubs$|local_log)':

  • startup_acphal_apu_free, startup_xapu_queue and startup_acphal_xma_activity passed.
  • startup_local_log fails on its concurrent-lines check here. It failed the same way before this PR's review rounds.
  • startup_local_log_reopen_control failed once and passed on re-run, which looks like a flake.
  • startup_stubs fails because its chad consumer scenario times out after 20 s. That scenario is outside this PR: its sources (tests/startup_stub_consumer.cpp, tests/startup_stub_check.py) name neither stand-in. On this same Wine setup it passed (chad: exit=0xe2570200 ok) at 6a0b89aa, 77b30ac1 and main 32595645. It has failed since the base moved to 5a0b0aad, including with this round's acphal.cpp and xapu.cpp reverted to 73728f98. The cause is not established.

Mutations. Each was rebuilt, run, then restored and checked by hash. The first four ran at 6f9d0702; the last at c8067462:

Mutation Result
acphal.cpp as at 73728f98 (thread handle closed, thread never joined) FAIL: case unload exited 0xc0000005
xapu.cpp as at 73728f98 FAIL: case unload exited 0xc0000005
second AcpHalAllocateShapeContexts skips the last sample of the old array FAIL: re-run without ApuFree: ... fields 4 1 1 ...
unload case leaves xapu loaded FAIL: the stand-in is unloaded after FreeLibrary
AcpHal writes its line even when no count moved (c8067462) FAIL: zero-write control logs no activity line

Not measured: any run on Windows. The stand-in tests have not run under the Windows loader or with ctest --preset dev/release, and the PR job does not build these targets. No Windows run of this fix commit has been made yet.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head f4b2d80b2d52b78268b5ce7e485493a59b0bea6d (previous review was on 73728f98; the new commits are the round-1/round-2 fixes plus merges of main).

Scope read: src/startup_stubs/acphal.cpp, xapu.cpp, local_log.h, CMakeLists.txt, docs, tests/startup_acphal_xma_activity.cpp (git diff --stat origin/main...HEAD: 9 files, +869/-1; clean-room, title neutral, mergeable).

Commands executed locally

  • git diff origin/main...HEAD --check -> clean (rc=0)
  • python3 tests/docs_links_check.py -> self-test passed, 18 files / 412 links OK
  • python3 tests/bidi_controls_check.py -> 1480 files, no bidi controls
  • gh pr checks 2107 -> Linux Python checks, gfx1013 fixtures and Windows build+test all pass on this head

What I verified by reading

  • Counter is off by default (X2W_AUDIO_ACTIVITY), no thread, nothing runs outside a call into the DLL, so unload leaves no code running (the new unload case covers it).
  • All shared state (watched, shadow, counts, ticks) is only touched under activity_lock / count_lock; logging happens after the lock is released; GetLastError is preserved on every counted path.
  • ApuFree of the watched array samples first, then drops watched/shadow before the block can be reused, so no read of freed memory; a second AcpHalAllocateShapeContexts samples the old array before swapping.
  • Count structs are all u64 (no padding), so the memcmp "did a count move" test is sound. Snprintf use guards used >= sizeof before the next write; worst-case truncation only shortens the line.
  • Line cadence (>= 1 s, first counted event starts the interval) matches the comments/docs.

Findings

  • P1: none.
  • P2: none.
  • nit (acphal.cpp poll_locked): types[256]/classes[320] can truncate if every bucket has a 20-digit delta; harmless, but the doc could say "line may be shortened".
  • nit (xapu.cpp count_command): the command class is the first UINT32, a stand-in convention; the docs already say so, keep it labelled that way if a real layout is found.

Not done: I could not run the new CTest or a logic mutation locally: the stubs use MSVC __try/__except (local_log.h:75), which the Linux mingw toolchain here cannot build, and I did not queue the Windows VM (not needed: no shader/gfx2hlsl change). The Windows CI result above is my only runtime evidence.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head 5c2715dd23957580648f7d789519588f19adad85 (new since the last reviewed head: one commit, audio: count unreadable XApu commands on the early E_POINTER path, plus a merge of main).

What changed

  • src/startup_stubs/xapu.cpp:266: the early E_POINTER return in XApuEnqueueCommand (null or unreadable 0x60-byte header) now calls count_command(hr_pointer, nullptr) before returning.

Findings

  • P1: none.
  • P2: none.
  • Nit (no change needed): the early refusal checks command_header_size bytes, while count_command only needs 4. A command pointer that is readable for 4 bytes but not for the whole header used to be counted by its class and is now counted as unreadable. That matches the "refused as unreadable" comment and the E_POINTER result, so I think it is the right call. The docs and the comment at the top of the counter already say a command the call cannot read counts as unreadable.
  • Correctness check: count_command calls readable(nullptr, 4), which is false, so the call lands in unreadable and not in by_class[0]. A null command is not confused with class 0. The full-ring E_OUTOFMEMORY path still goes through the normal class count at line 279. GetLastError is saved and restored. With X2W_AUDIO_ACTIVITY off, the call returns before any work.
  • The existing check in tests/startup_acphal_xma_activity.cpp:266 (null command) expects unreadable = 1 at line 286, so it covers the new line. The first-pass finding is therefore addressed.

Commands executed locally (Linux)

  • git diff f4b2d80..5c2715dd for the PR files, and git show 5c2715dd: one line added in xapu.cpp.
  • python3 tests/docs_links_check.py: "Checked 18 Markdown files and 442 links."
  • python3 tests/bidi_controls_check.py: "no bidirectional controls."
  • git diff --check origin/main...HEAD: clean.
  • gh pr view: mergeable. gh pr checks at review time: Linux Python checks pass; the Windows build/test and the gfx1013 fixtures job were still pending.

Not done

  • No mutation run: the test is Windows-only C++ and cannot be built on this Linux host. By reading, removing line 266 makes unreadable 0 and the null-command expectation at line 286 fail. A Windows job should confirm this.
  • No Win2025 run: the PR touches no shader or gfx2hlsl code, so I did not queue the Windows VM. Please wait for the pending Windows CI job before marking Ready.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@JohnConnorNPC could you rebase this branch onto current main and force-push?

GitHub reports head 5c2715dd as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (4aaea119):

  • src/startup_stubs/xapu.cpp

Commands run locally:

git fetch origin main pull/2107/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 2107 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

The cpu_native_acphal_hal example block had no closing fence, so the
ApuFree section after it, and the text up to the next bare fence, rendered
as code and their links were not checked.
…the stand-ins

Opt-in with X2W_AUDIO_ACTIVITY=1. AcpHal watches the XMA context array it
allocates and counts contexts filled, changed and cleared, plus HAL slot2
submits by type; xapu counts XApuEnqueueCommand calls by command class with
no cap. Each DLL logs a line per second when a count moved and has an
experimental export with the totals. Off, nothing runs.
A source-built caller fills, changes and clears XMA contexts, submits HAL
commands and enqueues XApu commands. The on case checks the exact counts
from the exports and the logged lines, and that a freed and reused array
is no longer counted; the none case writes only next to the contexts and
must count 0; the off case reports nothing. Results, outputs, last errors
and context bytes must match with the counter on and off.
Adds the X2W_AUDIO_ACTIVITY switch, an Activity counter section under the
APU heap stand-in with the line formats and limits, and an experiments
entry with the reproduction command for startup_acphal_xma_activity.
… fit CTest timeout

The on and off cases now check that ApuAlloc of the same size returns the
freed context block, so the not-counted-after-reuse check cannot pass on
some other block. expect_on() replaces the repeated on/off expectation
lists without changing them. Each case waits 15 s, so all three fit in
the 60 s CTest timeout.
main's XApuEnqueueCommand now refuses a null or unreadable command header
with E_POINTER before the activity counter runs, so the unreadable count
never moved. Count those calls as unreadable on that path. A call refused
for a full ring (E_OUTOFMEMORY) is still counted by its command class.
… size

XApuConnect now refuses a size of 0 at input +0x0C (R0Y00#2288), so the fixture's
commands all landed on an unknown handle.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed b8cbea6c merged over current main 4b0350ea. The merge is clean and git diff --cached --check is clean.

R0Y00's request on 73728f98 is addressed.

  • No thread: neither stand-in starts one any more. acphal.cpp and xapu.cpp have no CreateThread, _beginthread or std::thread.
  • Sampling is synchronous: AcpHal compares the context array with its copy only inside calls into the DLL: a HAL submit, AcpHalAllocateShapeContexts, ApuFree once counting has started, and the export. It does this at most once per 10 ms. The line is written from a counted call and logged after the lock is released.
  • Freeing the array: ApuFree of the watched array stops the watch before heap_give can decommit or reuse the block.
  • The unload case: this is the child R0Y00 asked for. It loads both DLLs, starts activity in each, calls FreeLibrary on both, checks with GetModuleHandleEx that both images are unmapped, then stays alive 1.5 s and must exit 0.
  • Gating: with X2W_AUDIO_ACTIVITY unset, the export returns FALSE and the counted calls return before reading caller memory.

What I ran. I did a full build in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^(startup_acphal.*|startup_xapu.*|cpu_native_acphal.*|cpu_native_xapu.*)$' -E '(_hardware$|startup_audio_)'

In both presets, 5/5 pass: startup_acphal_xma_activity, startup_acphal_apu_free, startup_xapu_queue, cpu_native_acphal_hal and cpu_native_xapu_queue. I then ran startup_acphal_xma_activity 3 more times in each preset, and every run passed.

Mutants. For each, I rebuilt the two stand-ins and the new test in dev, then ran startup_acphal_xma_activity, startup_acphal_apu_free and startup_xapu_queue:

Mutant Result
AcpHal activity_on() always true killed (the off case: the export returns TRUE)
XApu activity_on() always true killed (the off case logs activity lines)
changed and cleared swapped in sample_locked killed
ApuFree of the watched array keeps watching killed (after free and reuse)
a second AcpHalAllocateShapeContexts skips the final sample of the old array killed (re-run without ApuFree)
AcpHal line written without the "a count moved" check killed (zero-write control)
the E_POINTER refusal not counted as unreadable killed (XApu commands, summed lines)
XApu count_command doesn't restore the caller's last error survives
10 ms sample limit removed survives (cost only, no visible change expected)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking.

  1. Last-error preservation in count_command is unpinned. The sentinel transcript would catch a stand-in that changes the last error, but nothing between GetLastError and SetLastError in count_command changes it in these runs. So dropping the restore goes unnoticed. That's harmless today. It only matters if readable() or logf start touching the last error.
  2. The PR description is stale against the current code.
    • "compares it about every 10 ms" reads like a timer. The code only samples inside calls, at most once per 10 ms.
    • "With the variable unset, the code starts no thread" implies a thread when it's on. No thread is started either way now.
    • The "Not measured: Windows CI, …" paragraph is out of date. Build and test on Windows passes on b8cbea6c, and the runs above are on Windows.
    • The docs in the diff already describe the call-driven sampling correctly.

Verdict: approve on b8cbea6c.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10 (no GPU tests in this set).
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on b8cbea6c.

This reply was AI-assisted.

Conflicts resolved by keeping both sides:
- src/startup_stubs/local_log.h: process_seconds() from this branch,
  then the probe pre-check helpers from main.
- src/startup_stubs/xapu.cpp: main's Opus refusal counters, then this
  branch's count_command() call.
@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I merged current main (b1e92256) into this branch as 0ce61ab3, a plain merge commit with no rebase or force-push. It was approved at b8cbea6c, but it conflicted with main.

Conflicts. Both were additive, and I kept both sides:

  • src/startup_stubs/local_log.h: this branch's process_seconds() comes first, followed by main's probe pre-check helpers (faults_avoided, mapped_prefix, precheck_enabled) from startup: refuse unmapped source ranges before a probe or a copy #2846.
  • src/startup_stubs/xapu.cpp in XApuEnqueueCommand: main's #ifdef X2W_HAVE_OPUS refusal counters come first, followed by this branch's count_command(hr, ...).

One thing for the author. main added a new early return in XApuEnqueueCommand (short decode command -> E_POINTER, inside #ifdef X2W_HAVE_OPUS). It returns before count_command, so with Opus enabled that refused call isn't counted. The E_POINTER return above it does call count_command(hr_pointer, nullptr). I didn't add the call myself, because that path builds only with X2W_WITH_OPUS=ON, and I couldn't build or test it without libopus. If you want every call counted, add count_command(hr_pointer, reinterpret_cast<const void*>(rdx)); before that return.

What I ran on 0ce61ab3:

  • Built dev and release.
  • Release: ctest --test-dir out/build/release --no-tests=error -R '^(startup_acphal.*|startup_xapu.*|startup_stub.*|startup_probe.*|cpu_native_acphal_hal|cpu_native_xapu_queue)$' -E '(_hardware$|startup_audio_)'. All 6 pass, including startup_acphal_xma_activity.
  • Dev: the full non-hardware suite, ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(_hardware$|startup_audio_)'. 1963 of 1975 pass.

A different reviewer will re-review the merged head.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 WARP.

This reply was AI-assisted.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested 0ce61ab3 (the merge of main b1e92256 into b8cbea6c) integrated over current main 86beae95 (tree 4287c49e). The trial merge is clean and git diff --cached --check origin/main is clean.

The merge commit's two resolutions look right to me. git show --remerge-diff 0ce61ab3 shows that only the two conflicted files differ from a plain merge:

  • src/startup_stubs/local_log.h: this branch's process_seconds() is kept whole, with its closing brace. main's probe pre-check helpers follow unchanged. Nothing from either side is dropped.
  • src/startup_stubs/xapu.cpp XApuEnqueueCommand: main's #ifdef X2W_HAVE_OPUS refusal counters run first, after the lock is released. This branch's count_command(hr, rdx) follows, before the first-calls log. So every call that reaches the end of the function is still counted, with the final hr.

What I ran. I did a full build in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_acphal.*|startup_xapu.*|startup_stub.*|startup_probe.*|cpu_native_acphal.*|cpu_native_xapu.*)$' -E '(_hardware$|startup_audio_)'

6 of 6 pass in each preset, with no skips: startup_acphal_apu_free, startup_xapu_queue, startup_acphal_xma_activity, startup_stubs, cpu_native_acphal_hal and cpu_native_xapu_queue.

Mutant on the resolved line: I removed count_command(hr, …) after the Opus block. startup_acphal_xma_activity fails, printing its expected totals (xapu.commands=7, …) against the summed lines. So the counted call is still pinned at its new position. My earlier mutant table on b8cbea6c covers the rest of the branch, which this merge doesn't change.

Non-blocking, same as the merge comment: with X2W_WITH_OPUS=ON, the new short decode command early return (xapu.cpp, inside #ifdef X2W_HAVE_OPUS) returns E_POINTER before count_command, so that refusal isn't counted. I didn't build the Opus configuration (no libopus here).

My two earlier non-blocking notes on b8cbea6c still apply: the last-error restore in count_command is unpinned, and the PR description is stale.

Verdict: approve on 0ce61ab3. R0Y00's changes-requested review on 73728f98 still stands. I addressed its request at b8cbea6c, but only R0Y00 can clear it, so I'm not merging.

Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU tests in this set.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 0ce61ab3.

This reply was AI-assisted.

… before the queue

In an X2W_WITH_OPUS build with typed completions, a type 3 command too short
to decode returned E_POINTER before count_command. Count it by its class, as
the other E_POINTER refusals after the header read are, and pin it in
startup_acphal_xma_activity with a type 3 header that ends where free address
space begins (X2W_PROBE_PRECHECK=1 refuses the tail without a fault).
@JohnConnorNPC

Copy link
Copy Markdown
Collaborator Author

Thank you for merging main and for the approval, @pigalot. I took your count_command suggestion: count_command(hr_pointer, reinterpret_cast<const void*>(rdx)); now sits before the early short-decode-command E_POINTER return, so the call is counted as class 3, like the in-lock E_POINTER refusals. The "Not counted" sentence in the doc is updated and experiments.md lists the new command.

A new case in the xma_activity test pins it: a type 3 command whose 8-byte header ends where unallocated address space begins, expecting class 3 = 1 and commands = 8. Removing the line turns the Opus build red (xapu.commands=7, no xapu.3) and restoring it passes again. The pin needs X2W_WITH_OPUS=ON; the default build stays green either way.

With Wine (Linux), the Opus build has the same 8 failures as main at 0ce61ab and the default build the same 6. xma_activity passes in both. docs_links and bidi pass. I have not run this on native Windows.

@R0Y00, pigalot approved 0ce61ab, the merge this commit builds on; when you have time, could you re-review so CHANGES_REQUESTED can clear?

This comment was AI-assisted.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested cdab51a0, integrated over current main fdba6e15 (tree 1a409785). The trial merge is clean, and git diff --cached --check origin/main is clean.

What changed since my approval of 0ce61ab3: one line in xapu.cpp, plus a test case and doc updates. Inside #ifdef X2W_HAVE_OPUS, the short-decode-command refusal now calls count_command(hr_pointer, rdx) before it returns E_POINTER. This addresses the non-blocking point I made on 0ce61ab3.

I traced it by reading the code. By that point the 8-byte command_header_size read has already passed readable, and count_command reads only the first UINT32 after its own readable check. hr_pointer isn't hr_handle, so the call lands in by_class[3]. That matches how the in-lock E_POINTER refusals are counted, and the line runs after the type3_commands and refused_short_command Opus counters, so it doesn't change them.

I couldn't build or run the Opus configuration. No libopus is installed here, and no CI job or preset sets X2W_WITH_OPUS. So the added line is checked here only by reading the code, plus JohnConnorNPC's Wine run, which shows xapu.commands=7 with the line removed.

What I ran (default build). I did a full build in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_acphal.*|startup_xapu.*|startup_stub.*|startup_probe.*|cpu_native_acphal.*|cpu_native_xapu.*|docs_links.*|startup_docs.*)$' -E '(_hardware$|startup_audio_)'

7 of 7 pass in each preset, with no skips: startup_acphal_apu_free, startup_xapu_queue, startup_acphal_xma_activity, startup_stubs, docs_links, cpu_native_acphal_hal and cpu_native_xapu_queue.

Controls on the new test case (default build):

  • With {"xapu.3", 1} removed from the test's expected totals, startup_acphal_xma_activity fails. So the short command does reach the counter and is classed as 3 without Opus, and the case isn't silently skipped by its free_after check.
  • With the X2W_PROBE_PRECHECK=1 line removed from spawn, the test still passes. As far as I can see, probe_readable already refuses the free tail under __try, so precheck only avoids a first-chance fault. That matches the comment, which says the tail is "refused without a fault".

Non-blocking: the short-command check runs before the handle lookup. So in an Opus build, a short type 3 command on an unknown handle counts as class 3, not as rejected=, while the default build counts it as rejected=. The ordering was already there before this commit; the new line only makes it visible in the counts. If that's intended, a sentence in startup-runtime.md would cover it.

Verdict: approve on cdab51a0. R0Y00's changes-requested review on 73728f98 still stands, and only R0Y00 can clear it, so I'm not merging.

Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU tests in this set.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on cdab51a0.

This reply was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent native Windows review of cdab51a0, integrated with main f41806a9 as tree cd7c4e2a. Release /O2 passed 3/3 with Opus disabled. Using the installed libopus 1.5.2, Debug and Release /O2 passed 3/3 each with X2W_WITH_OPUS=ON. No skips.

cmake --build <build> --target startup_acphal_xma_activity startup_acphal_apu_free startup_xapu_queue_check
ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R '^startup_(acphal_(apu_free|xma_activity)|xapu_queue)$'

Removing just the short type-3 command's counter made the Opus Release fixture fail. After restoring the source and relinking, the same test passed. The existing fixture also covers on/off/zero-write behavior, unchanged return and error values, reallocation and DLL unload. The final source keeps polling inside the opt-in calls, with no worker thread.

Windows 11 26200.9974, MSVC x64 19.51, Windows SDK 10.0.26100.0. No GPU or original executable used. On the current merge base the tested audio source, build and fixture files are unchanged.

@R0Y00
R0Y00 merged commit dbb1c9a into R0Y00:main Nov 28, 2026
5 checks passed
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.

4 participants