Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ cargo build --profile diag -p xtp --features diagnostics # target\diag\xtp.exe
| `XTP_SHADER_LOOP_BUDGET=<n>` | (every build) a lane of a translated shader leaves, as at the loop limit, once it has gone back `n` times in all of its loops together instead of 1048576 (2^20; loops inside loops multiply their own limits); `0` turns the budget off (own shader cache entries) |
| `XTP_AUDIO_CAPTURE=<file.wav>` | records what the title plays (our process only) |
| `XTP_XMA_DUMP=<dir>` | saves the first 32 XMA voices' context and input |
| `XTP_DSP_DUMP=<absolute dir>` | captures the first 32 DSP streams per process outside the repository. Each numbered stream directory holds `params.txt`, `ir.f32le` (omitted if unreadable or over 4 MiB), and the first four commands' buffers and gains as raw little-endian floats. On Windows, compare `.output-before.f32le` with `.output.f32le` to see how the command changed its destination. Disconnect waits for pending writes. |
| `XTP_WATCHDOG_HOOK=1` | every build: keeps the title's own watchdog from ending it after about 30 s without progress (slow world frames), and logs a warning (at most every 30 s) when it would have; a real deadlock then hangs for ever, with no `crashes.log` entry; known builds only, otherwise a warning and nothing patched |
| `XTP_TITLE_ASSERTS=continue` | every build: where the title's own assertion would end it because an entry of its archive store could not be made (`int3` at title+0x23d8f03; the entry's header was not read, docs/analysis/archive-null.md), it takes the title's own path for a null object instead, and logs how many times (at once, then at most every 10 s) and a census of that store; hides the failure, it does not fix it; known builds only, otherwise a warning and nothing patched |
| `XTP_XMEM_LEDGER=1` | every build: counts what the title asks of XMem by category (`XMemAlloc` by allocator id and memory type, committed resources included, the share our `XMemAllocDefault` serves, physical pages, virtual reserves, commits and frees, the budget reported) and logs each category that changed every 10 s: calls, failures, frees, live and peak bytes, bytes asked in all |
Expand Down
5 changes: 5 additions & 0 deletions crates/xtp-hle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ license.workspace = true
publish.workspace = true

[dependencies]
xtp-core = { workspace = true, optional = true }
tempfile = { workspace = true, optional = true }
xtp-gpu.workspace = true
xtp-loader.workspace = true
xtp-pe.workspace = true
Expand Down Expand Up @@ -44,12 +46,15 @@ windows = { workspace = true, features = [
windows-core = { workspace = true, optional = true }

[dev-dependencies]
xtp-core.workspace = true
tempfile.workspace = true
xtp-testkit.workspace = true

[features]
# Debugging switches (scripted keys and the like).
diagnostics = [
"dep:xtp-core",
"dep:tempfile",
"xtp-gpu/diagnostics",
"xtp-loader/diagnostics",
"windows/Win32_Media_Audio",
Expand Down
38 changes: 33 additions & 5 deletions crates/xtp-hle/src/modules/dsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ use super::xasync::E_INVALIDARG;
use super::xgameruntime::{HRESULT, S_OK};
use crate::{HleModule, hle_export};

#[cfg(any(test, feature = "diagnostics"))]
mod capture;

const E_POINTER: HRESULT = 0x8000_4003_u32 as i32;
const E_OUTOFMEMORY: HRESULT = 0x8007_000E_u32 as i32;

Expand All @@ -35,6 +38,8 @@ const NOT_FOR_CONVOLUTION: u32 = 4;
pub struct Dsp {
max_streams: u32,
active: Mutex<u32>,
#[cfg(any(test, feature = "diagnostics"))]
capture: Option<capture::Connection>,
}

/// What activation describes.
Expand Down Expand Up @@ -62,6 +67,8 @@ pub struct Stream {
frames: u32,
channels: u32,
status: Box<Status>,
#[cfg(any(test, feature = "diagnostics"))]
capture: Option<capture::Capture>,
}

/// One block of work.
Expand Down Expand Up @@ -102,6 +109,8 @@ pub extern "system" fn XDspConnectWithMaximumStreamLimit(
let dsp = Box::new(Dsp {
max_streams,
active: Mutex::new(0),
#[cfg(any(test, feature = "diagnostics"))]
capture: capture::Connection::open(ir_seconds, max_channels),
});
// SAFETY: checked non-null.
unsafe { out.write(Box::into_raw(dsp)) };
Expand Down Expand Up @@ -155,11 +164,11 @@ pub extern "system" fn XDspActivate(
channels,
"audio DSP stream activated"
);
// SAFETY: a connection from `XDspConnectWithMaximumStreamLimit`.
let connection = unsafe { &*dsp };
{
// SAFETY: a connection from `XDspConnectWithMaximumStreamLimit`.
let dsp = unsafe { &*dsp };
let mut active = dsp.active.lock().unwrap_or_else(|e| e.into_inner());
if *active >= dsp.max_streams {
let mut active = connection.active.lock().unwrap_or_else(|e| e.into_inner());
if *active >= connection.max_streams {
return E_OUTOFMEMORY;
}
*active += 1;
Expand All @@ -168,6 +177,11 @@ pub extern "system" fn XDspActivate(
dsp,
frames: desc.frames,
channels: desc.channels,
#[cfg(any(test, feature = "diagnostics"))]
capture: connection.capture.as_ref().and_then(|capture| {
// SAFETY: the descriptor supplies the IR for the duration of activation.
unsafe { capture.activate(desc) }
}),
status: Box::new(Status {
submitted: 0,
completed: 0,
Expand Down Expand Up @@ -206,11 +220,21 @@ pub extern "system" fn XDspSubmitCommand(
}
// SAFETY: a stream from `XDspActivate`, the title's command.
let (stream, command) = unsafe { (&mut *stream, &*command) };
let samples = (stream.frames * stream.channels) as usize;
#[cfg(any(test, feature = "diagnostics"))]
let mut block = stream.capture.as_mut().and_then(|capture| {
// SAFETY: the caller supplies the input until completion.
unsafe { capture.begin_block(command, samples) }
});
if !command.output.is_null() {
let samples = (stream.frames * stream.channels) as usize;
// SAFETY: the title's output buffer holds one block of the stream.
unsafe { std::ptr::write_bytes(command.output, 0, samples) };
}
#[cfg(any(test, feature = "diagnostics"))]
if let Some(block) = &mut block {
// SAFETY: copy the initialized output before publishing completion.
block.output = unsafe { capture::copy_samples(command.output, samples) };
}
let status = &mut *stream.status;
let next = status.submitted.wrapping_add(1);
// SAFETY: the status block is read by title code on other threads.
Expand All @@ -223,6 +247,10 @@ pub extern "system" fn XDspSubmitCommand(
// SAFETY: optional out parameter.
unsafe { ticket.write(next) };
}
#[cfg(any(test, feature = "diagnostics"))]
if let Some(block) = block {
block.enqueue();
}
S_OK
}

Expand Down
Loading