Skip to content

hle: capture DSP impulse responses and command blocks - #39

Merged
simnJS merged 2 commits into
MiamiGame:mainfrom
AliceWood:hle/dsp-stream-capture
Nov 24, 2026
Merged

simnJS merged 2 commits into
MiamiGame:mainfrom
AliceWood:hle/dsp-stream-capture

Conversation

@AliceWood

@AliceWood AliceWood commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Setting XTP_DSP_DUMP to an absolute directory outside the repository records data for studying the DSP's impulse-response layout offline. Diagnostics builds capture the first 32 activated streams per process, across connections, and the first four commands per stream. Each numbered directory records the stream descriptor, the connection's IR duration and channel limit, and the impulse response if it is readable and at most 4 MiB.

The DSP copies the buffers while the caller still owns them. Windows captures include the input, destination before and after completion, and both gains. Command submission publishes the completion ticket before queueing the owned snapshots. A single background thread writes the files, and disconnect drains queued work. The diagnostics runtime uses tempfile to give each stream a unique directory and atomically publish complete files.

Fixes #10

Depends on: none

Area

xtp-hle DSP activation and submission, the existing checked Windows memory reader in xtp-loader, and the README and HLE analysis. The diff exceeds 400 changed lines because the writer and its regression tests cover bounded capture, caller-owned buffer lifetimes, and completion while the writer is paused.

Tests

  • cargo xtask pr-check passes on my machine
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot
  • Ran on a title: no. All checks used synthetic data on Windows.

The existing Windows DSP fixture produced zero files on upstream f32d879, six on the initial PR and eight after the review fix, using the same profile and capture setting. The extra files record the command gains and original destination.

Both DSP tests passed on 4202785 with cargo test --locked -p xtp-hle --lib modules::dsp and with --features diagnostics. The test opens 33 connections in one process, checks the 4 MiB boundary and oversized/unreadable responses, and verifies separate and in-place buffers byte for byte. With the writer paused, five commands finish and publish their tickets before any file appears. The loader's existing guard-page and overflow test also passed.

In cargo xtask pr-check --base origin/main, formatting, both Clippy runs, asset policy and conventions passed. The local workspace test step failed on eight GPU tests, all of which also failed on the original upstream baseline f32d879.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

AI assistance: Codex wrote the implementation, review fixes, regression test and docs, and ran the checks. I reviewed the initial commit bfa5c9f. Direct sources were this issue, the PR review, XTP's DSP code and tests, existing capture code, loader memory reader, runtime asset policy and HLE analysis. The issue and HLE analysis supplied the second-hand description of xcl's observations. No xcl or AnyPS5 source was opened or copied.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

@github-actions github-actions Bot added overlap another open PR changes the same files area/hle touches crates/xtp-hle area/docs docs/, Markdown and removed overlap another open PR changes the same files labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.

Pull request Files changed by both
#26 README.md, docs/analysis/hle.md

This comment is kept up to date automatically and removed when the overlap ends.

@github-actions github-actions Bot added area/deps Cargo.lock size/M 100 to 399 changed lines labels Nov 24, 2026

@simnJS simnJS 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.

Thanks @AliceWood, this is a careful first step for #10:

  • it's opt-in and diagnostics-only;
  • it's guarded by ensure_outside_repo;
  • it writes atomically;
  • the child-process test covers the disabled, empty, in-repo and unusable cases with synthetic data.

Two changes before merge:

  1. Bound the disk use. There is a 4-block limit per stream, but no limit on streams per session, and the IR is written at whatever size ir_floats claims (up to 16 GiB). Please add a session counter like XTP_XMA_DUMP's 32, and a ceiling on IR bytes (derived from the connection's ir_seconds, or a flat limit). If it's cheap, also check that the range is readable (VirtualQuery), since this is the first code that dereferences desc.ir and the field hasn't been checked on a title yet.
  2. Keep I/O off the completion path. XDspSubmitCommand creates and renames up to 8 files before it publishes completed, which other title threads poll, and activation writes the whole IR inside the call. Please copy the block (16 KiB at most) and the IR, publish the status first, and hand the writes to a small writer thread.

Optional:

  • Resolve XTP_DSP_DUMP once, or require an absolute path. The title can change the working folder, so a relative path could land in its install folder.
  • The output files are always our own zeros. Capturing the output buffer before we clear it would tell us whether the DSP accumulates.
  • Recording the command gains and the connection's ir_seconds/max_channels in the capture would help Q5.
  • A sequence number in the folder name (stream-000-…) and an info! line with the path would make captures easier to match to a session.
  • One line in the description on why tempfile becomes a diagnostics runtime dependency, and a mention of XTP_DSP_DUMP in docs/analysis/hle.md.

@github-actions github-actions Bot added overlap another open PR changes the same files area/loader touches crates/xtp-loader size/L 400 to 999 changed lines and removed size/M 100 to 399 changed lines labels Nov 24, 2026
@AliceWood
AliceWood requested a review from simnJS November 24, 2026 22:36

@simnJS simnJS 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.

Thanks @AliceWood, both requested changes are in:

  • captures stop at 32 streams per process and at 4 MiB per IR, and the IR is read through the loader's checked reader;
  • the buffers are copied, completed is published, and only then does one writer thread write the files. The paused-writer test shows the order.

The optional items are covered too. Approving: it's opt-in and diagnostics-only, so the points below can come as a follow-up PR:

  1. Connection::drop waits on recv() with no timeout (capture.rs:144). If the writer is stuck on a slow disk, or gone because the process is exiting, XDspDisconnect hangs the title. A recv_timeout of a few seconds with a warning is enough, and you could skip the wait when the connection queued nothing.
  2. block-N.output.f32le is always our own zeros, so the README line about comparing it with .output-before describes XTP's stub, not the DSP. I'd drop that file. It also saves a checked read per command: each one calls VirtualQuery, and on a large committed heap one call can take milliseconds, longer than an audio block. write_bytes already writes that range unchecked, so a plain copy of output-before is no less safe. I'd keep the checked read for the IR.
  3. The stream folder gets its final name before it is filled. If the process ends mid-write, params.txt with no ir.f32le looks the same as an IR left out on purpose. Writing the reason into params.txt (ir=oversized / ir=unreadable) would tell them apart.
  4. 4 MiB is about 22 s of mono at 48 kHz, so a full 24 s IR would be dropped. Since ir_floats is logged, we can raise the limit after a first real run.

Note for later reworks: read_title_memory is now a public API used by xtp-hle, so any change to the loader's memory checks must keep its contract (false for unmapped, reserved, no-access or guard pages).

@simnJS
simnJS merged commit 10d8700 into MiamiGame:main Nov 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Cargo.lock area/docs docs/, Markdown area/hle touches crates/xtp-hle area/loader touches crates/xtp-loader overlap another open PR changes the same files size/L 400 to 999 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture the DSP's impulse responses (first step to reverb)

2 participants