From 1c8fae9ec040e9e8824bdaf44e99b336dff7b9f8 Mon Sep 17 00:00:00 2001 From: ivall Date: Sat, 21 Nov 2026 17:06:15 +0100 Subject: [PATCH] Tests: no process-wide switch in a parallel test, registry cleanup and advapi32 routing checked - The structured / block-chain HLSL comparison set XCL_RECOMP_NO_STRUCTURED for the whole process while other recompiler tests ran in parallel: now Options::structured. - gpu_pso_e2e: releasing the mesh stand-in removes exactly one TWO_PASS entry (the tests there run one at a time). - resolver: advapi32!RegOpenKeyW resolves to kernelx, RegSetValueExW to the real advapi32. - scripts/test.ps1 lists the sample-data variables not set (their tests pass without running); README says so. --- README.md | 5 +++-- crates/xcl/src/gpu/recomp/mod.rs | 7 +++++-- crates/xcl/src/gpu/recomp/tests.rs | 5 ++--- crates/xcl/src/resolver.rs | 16 ++++++++++++++++ crates/xcl/tests/gpu_pso_e2e.rs | 3 +++ scripts/test.ps1 | 3 +++ 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6643b5e..4a97939 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,9 @@ Unit tests, an end-to-end test with our own "console title" (`tests/testtitle`) (D3D12, SM 6.6; skipped without a GPU / DXC). Tests on real game data are opt-in through environment variables pointing at your own files – `XCL_SAMPLE_RPF` (shader pack), `XCL_SAMPLE_DLLS` (the game's console DLLs), `XCL_SAMPLE_TTPF` (texture archive), -`XCL_SAMPLE_BK2` (a movie), `XCL_SAMPLE_BVH4` – described in `HANDOFF.md`. No game data is part -of the repository. +`XCL_SAMPLE_BK2` (a movie), `XCL_SAMPLE_BVH4` – described in `HANDOFF.md`; without them those +tests pass without running anything (`scripts/test.ps1` lists the ones not set). No game data is +part of the repository. ## Licenses diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index 2cd8768..4919d0a 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -313,11 +313,14 @@ pub struct Options { /// then exactly the single-window form); 2..4 add `mem1`.. (u3..) and pick the window of /// every access from the high address bits pub mem_windows: u32, + /// structured control flow when the program allows it (false, or `XCL_RECOMP_NO_STRUCTURED`: + /// always the guarded block chain) + pub structured: bool, } impl Default for Options { fn default() -> Self { - Options { mode: Mode::Kernel, wave64: true, hw_wave: 0, static_sampler_base: 0, mem_windows: 1 } + Options { mode: Mode::Kernel, wave64: true, hw_wave: 0, static_sampler_base: 0, mem_windows: 1, structured: true } } } @@ -1076,7 +1079,7 @@ pub fn translate(code: &[u8], opt: &Options) -> Result { let ctx = Ctx { insts: &insts, starts: &starts, leaders: &leaders, loops: &loops, edges: &edges, memo: Default::default() }; let mut flags = BTreeSet::new(); let mut code = String::new(); - if gs_jump.is_none() && std::env::var_os("XCL_RECOMP_NO_STRUCTURED").is_none() && structurable(&ctx, 0, u64::MAX).is_some() { + if gs_jump.is_none() && opt.structured && std::env::var_os("XCL_RECOMP_NO_STRUCTURED").is_none() && structurable(&ctx, 0, u64::MAX).is_some() { // structured control flow: plain if / loops, no block dispatch on `pc` (much // smaller for DXC and the driver on big programs) emit_structured(&ctx, &mut em, &mut code, 0, u64::MAX, None, 0, None, &BTreeSet::new(), 1, &mut blocks, &mut flags); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 8cc5dd4..c9e94e1 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -46,9 +46,8 @@ fn hlsl_is_generated_for_straight_line_and_branches() { // forward branches only: a plain `if`, no loop and no block dispatch on pc assert!(t.hlsl.contains("if (!(") && !t.hlsl.contains("pc ==") && !t.hlsl.contains("for (;;)") && t.hlsl.contains("[WaveSize(64)]"), "{}", t.hlsl); // the guarded block chain (fallback form) for the same program - unsafe { std::env::set_var("XCL_RECOMP_NO_STRUCTURED", "1") }; - let g = translate(&code, &Options::default()).unwrap(); - unsafe { std::env::remove_var("XCL_RECOMP_NO_STRUCTURED") }; + // (an option, not the environment variable: other tests translate at the same time) + let g = translate(&code, &Options { structured: false, ..Options::default() }).unwrap(); assert!(g.hlsl.contains("if (pc == 0u)") && !g.hlsl.contains("while"), "{}", g.hlsl); // a backward branch: only its range becomes a loop let code = prog(&[ diff --git a/crates/xcl/src/resolver.rs b/crates/xcl/src/resolver.rs index d898db5..f7d3aab 100644 --- a/crates/xcl/src/resolver.rs +++ b/crates/xcl/src/resolver.rs @@ -351,3 +351,19 @@ pub fn get_proc_address(h: usize, what: &ImportName) -> Option { } system_proc_in(h, what) } + +#[cfg(test)] +mod tests { + use super::*; + + /// advapi32 imports go to kernelx: the registry functions the GDK thunks use for the device + /// type are XCL's, everything else is the real advapi32. + #[test] + fn advapi32_imports_route_through_kernelx() { + let name = |s: &str| ImportName::Name { hint: 0, name: s.into() }; + let (a, s) = resolve_inner("advapi32.dll", &name("RegOpenKeyW"), 0); + assert!(a != 0 && matches!(s, Source::Hle(ref m) if m == crate::hle::KERNELX), "{s:?}"); + let (a, s) = resolve_inner("advapi32.dll", &name("RegSetValueExW"), 0); + assert!(a != 0 && matches!(s, Source::System(ref d) if d == "advapi32.dll"), "{s:?}"); + } +} diff --git a/crates/xcl/tests/gpu_pso_e2e.rs b/crates/xcl/tests/gpu_pso_e2e.rs index 4e29578..a2e8cf2 100644 --- a/crates/xcl/tests/gpu_pso_e2e.rs +++ b/crates/xcl/tests/gpu_pso_e2e.rs @@ -287,7 +287,10 @@ fn retail_pipelines_built_in_the_background_behind_a_stand_in() { assert!(real::two_pass_of(raw).is_some(), "the two-pass parts through the stand-in"); println!("mesh: the call returned after {call:?}, the real pipeline was ready after {:?}", t0.elapsed()); // the title releases the stand-in: its real pipeline goes with it, the address is forgotten + // (the tests here run one at a time: the count is this test's) + let two_pass = real::two_pass_count(); drop(mesh); + assert_eq!(real::two_pass_count(), two_pass - 1, "the released pipeline's compute pass is gone"); assert_eq!(pso_async::resolve(raw), raw); assert!(real::two_pass_of(raw).is_none()); } diff --git a/scripts/test.ps1 b/scripts/test.ps1 index 8e78464..5c43195 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -1,6 +1,9 @@ # Build everything (the e2e test needs the test title + DLL) and run all tests. $ErrorActionPreference = 'Stop' Set-Location (Join-Path $PSScriptRoot '..') +# tests on game data pass without running anything when their variable is not set +$missing = 'XCL_SAMPLE_RPF', 'XCL_SAMPLE_DLLS', 'XCL_SAMPLE_TTPF', 'XCL_SAMPLE_BK2', 'XCL_SAMPLE_BVH4' | Where-Object { -not (Test-Path "env:$_") } +if ($missing) { Write-Host "not set, their tests are skipped: $($missing -join ', ')" } cargo build --workspace if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } cargo test --workspace -- --test-threads=4