D3D12.X: drop CreatePlacedResourceX alias table once logged and avoid hot-path formatting #2626

Merged
Decodere merged 1 commit from upstream-pr/2636 into main 2026-11-28 19:48:22 +00:00
Decodere commented 2026-11-26 03:43:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T03:43:22Z.


What is in it

Fixes unbounded growth, hot-path string formatting, and lock-held logging in note_alias (crates/xcl/src/hle/d3d12x/device_x.rs), called on every CreatePlacedResourceX resource placement:

  • Drop alias table once the 16-log cap is reached: Previously note_alias kept inserting (va, String) into a process-global Mutex<Option<HashMap<usize, String>>> forever, even after all 16 diagnostic alias lines had been logged. A lock-free N.load(Ordering::Relaxed) >= MAX_ALIAS_LOGS fast-path now returns immediately once the cap is reached, and record_alias_in clears SEEN to None when the 16th alias is logged so the backing map is freed.
  • Cap tracked VAs before the log cap is reached: If a title places many unique addresses with fewer than 16 aliases, record_alias_in stops inserting new VA entries once MAX_ALIAS_TRACKED (16_384) entries are tracked while still detecting aliases against already-tracked addresses.
  • Avoid heap allocations on every placement and release the mutex before logging: Replaced the per-call format!(...) String value with a Copy PlacedDescSummary struct (preserving the exact "dimension {} {}x{} format {} flags {:#x}" format via Display) and dropped the SEEN mutex guard before calling crate::xlog_info!.

Part of #1773
Part of #1833

Tested

  • Failing-first verification against pre-fix record_alias_in semantics (cargo test --release -p xcl --lib "hle::d3d12x::device_x::tests::note_alias" -- --test-threads=1 --nocapture): all 3 new unit tests failed (0 passed; 3 failed; 0 ignored):
    • note_alias_bounds_tracked_entries_without_aliases failed (left: 13, right: 8, unbounded VA table growth)
    • note_alias_logs_first_16_and_drops_table_after_cap failed (16th alias did not drop the tracking table)
    • note_alias_short_circuits_when_cap_already_reached failed (residual map was not freed once cap was reached)
  • Post-fix targeted tests on WARP (XCL_ADAPTER=warp, XCL_WARP=1, cargo test --release -p xcl --lib "hle::d3d12x::device_x::tests::" -- --test-threads=1 --nocapture): 17 passed; 0 failed; 0 ignored; 0 skipped (0.44s), zero new compiler warnings in device_x.rs.
  • Post-fix targeted tests on RTX 4060 (cargo test --release -p xcl --lib "hle::d3d12x::device_x::tests::" -- --test-threads=1 --nocapture): 17 passed; 0 failed; 0 ignored; 0 skipped (0.40s), zero new compiler warnings in device_x.rs.

Regression run

  • Full release workspace on RTX 4060 (cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture): 37 test binaries, 1438 passed; 0 failed; 47 ignored, 29 pre-existing environment-gated SKIPPED lines:

    • 21 skipped: no wave64 (RTX 4060 is wave32)
    • 3 skipped: wave32 per-lane form: refused by driver (f16 arithmetic, f16 packed, f32 conversions)
    • 3 skipped: no D3D12 debug layer (d3d12SDKLayers.dll unavailable on host: debug-layer dred: false/true and uploads_start_from_each_subresources_state)
    • 1 skipped: pso_measurement_compiles_an_exact_synthetic_record (cannot disable driver cache on Windows)
    • 1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • Paired 60 s RTX 4060 smoke capture (scripts/smoke.ps1):

Base (origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1539 (PresentX 1539)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13973 MB

PR (ce86b00e30e7a4eedfabf215cb3e0a0b2b6b6a89):

xcl-smoke v1
commit: ce86b00e30e7a4eedfabf215cb3e0a0b2b6b6a89
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1556 (PresentX 1556)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13985 MB

Not tested

  • Long-running multi-hour placed-resource workloads beyond the 60 s smoke capture.
  • The 29 host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows).

AI use

Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, and paired 60 s GPU smoke captures were executed directly in this workspace.

<!-- greyfinch-sync:ivall/xcl:issue:5503587062 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2636). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T03:43:22Z. --- **What is in it** Fixes unbounded growth, hot-path string formatting, and lock-held logging in `note_alias` (`crates/xcl/src/hle/d3d12x/device_x.rs`), called on every `CreatePlacedResourceX` resource placement: - **Drop alias table once the 16-log cap is reached:** Previously `note_alias` kept inserting `(va, String)` into a process-global `Mutex<Option<HashMap<usize, String>>>` forever, even after all 16 diagnostic alias lines had been logged. A lock-free `N.load(Ordering::Relaxed) >= MAX_ALIAS_LOGS` fast-path now returns immediately once the cap is reached, and `record_alias_in` clears `SEEN` to `None` when the 16th alias is logged so the backing map is freed. - **Cap tracked VAs before the log cap is reached:** If a title places many unique addresses with fewer than 16 aliases, `record_alias_in` stops inserting new VA entries once `MAX_ALIAS_TRACKED` (`16_384`) entries are tracked while still detecting aliases against already-tracked addresses. - **Avoid heap allocations on every placement and release the mutex before logging:** Replaced the per-call `format!(...)` `String` value with a `Copy` `PlacedDescSummary` struct (preserving the exact `"dimension {} {}x{} format {} flags {:#x}"` format via `Display`) and dropped the `SEEN` mutex guard before calling `crate::xlog_info!`. Part of #1773 Part of #1833 **Tested** - **Failing-first verification** against pre-fix `record_alias_in` semantics (`cargo test --release -p xcl --lib "hle::d3d12x::device_x::tests::note_alias" -- --test-threads=1 --nocapture`): all 3 new unit tests failed (`0 passed; 3 failed; 0 ignored`): - `note_alias_bounds_tracked_entries_without_aliases` failed (`left: 13, right: 8`, unbounded VA table growth) - `note_alias_logs_first_16_and_drops_table_after_cap` failed (16th alias did not drop the tracking table) - `note_alias_short_circuits_when_cap_already_reached` failed (residual map was not freed once cap was reached) - **Post-fix targeted tests on WARP** (`XCL_ADAPTER=warp`, `XCL_WARP=1`, `cargo test --release -p xcl --lib "hle::d3d12x::device_x::tests::" -- --test-threads=1 --nocapture`): `17 passed; 0 failed; 0 ignored; 0 skipped` (`0.44s`), zero new compiler warnings in `device_x.rs`. - **Post-fix targeted tests on RTX 4060** (`cargo test --release -p xcl --lib "hle::d3d12x::device_x::tests::" -- --test-threads=1 --nocapture`): `17 passed; 0 failed; 0 ignored; 0 skipped` (`0.40s`), zero new compiler warnings in `device_x.rs`. **Regression run** - **Full release workspace on RTX 4060** (`cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture`): `37` test binaries, `1438 passed; 0 failed; 47 ignored`, `29` pre-existing environment-gated `SKIPPED` lines: - `21` skipped: `no wave64` (RTX 4060 is wave32) - `3` skipped: wave32 `per-lane form: refused` by driver (`f16 arithmetic`, `f16 packed`, `f32 conversions`) - `3` skipped: no D3D12 debug layer (`d3d12SDKLayers.dll` unavailable on host: debug-layer `dred: false`/`true` and `uploads_start_from_each_subresources_state`) - `1` skipped: `pso_measurement_compiles_an_exact_synthetic_record` (cannot disable driver cache on Windows) - `1` skipped: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - **Paired 60 s RTX 4060 smoke capture (`scripts/smoke.ps1`):** Base (`origin/main` `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1539 (PresentX 1539) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13973 MB ``` PR (`ce86b00e30e7a4eedfabf215cb3e0a0b2b6b6a89`): ``` xcl-smoke v1 commit: ce86b00e30e7a4eedfabf215cb3e0a0b2b6b6a89 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1556 (PresentX 1556) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13985 MB ``` **Not tested** - Long-running multi-hour placed-resource workloads beyond the 60 s smoke capture. - The `29` host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows). **AI use** Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, and paired 60 s GPU smoke captures were executed directly in this workspace.
sage-sage commented 2026-11-26 06:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sage-sage on 2026-11-26T05:18:04Z.


Test report: passes on NVIDIA. Exact head ce86b00e (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the three new note_alias_* tests pass
  • SKIPPED (29 lines, the same as on main on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dll not installed), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off)

Not tested

  • No game, so not a title that places resources at many addresses.

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7183362801 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2636#issuecomment-7183362801). Originally posted by [sage-sage](https://github.com/sage-sage) on 2026-11-26T05:18:04Z. --- **Test report: passes on NVIDIA.** Exact head `ce86b00e` (its base is current `main` `b49be18`, so head = merged). **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build - `cargo test --workspace -- --test-threads=4`: 1438 passed, 0 failed, 47 ignored; the three new `note_alias_*` tests pass - SKIPPED (29 lines, the same as on `main` on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (`d3d12SDKLayers.dll` not installed), 1 `no heap windows`, 1 `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off) **Not tested** - No game, so not a title that places resources at many addresses. Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
rgroenewoudt commented 2026-11-26 16:50:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by rgroenewoudt on 2026-11-26T16:50:10Z.


Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head ce86b00: no new failures.

Tested

  • AMD Radeon RX 9070, driver 32.0.32029.2010; AMD Ryzen 9 5950X; Windows 11 Pro build 26300; Rust 1.100.0 MSVC; DXC 1.9.2602.17; debug build- cargo test --workspace --no-fail-fast -- --test-threads=4: 1436 passed, 2 failed, 47 ignored. The 2 failures are fuzz_validate_and_gpu_1 (seed 722) and _3 (seed 1599), the AMD ones from #2115, not touched here.
  • SKIPPED (7): 6 × f16 / f32 per-lane forms refused (#1426); heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Not tested

  • No regression run on a real title (no game data here); this covers only the test suite on AMD

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs.
<!-- greyfinch-sync:ivall/xcl:comment:7198156475 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2636#issuecomment-7198156475). Originally posted by [rgroenewoudt](https://github.com/rgroenewoudt) on 2026-11-26T16:50:10Z. --- **Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head `ce86b00`**: no new failures. **Tested** - AMD Radeon RX 9070, driver 32.0.32029.2010; AMD Ryzen 9 5950X; Windows 11 Pro build 26300; Rust 1.100.0 MSVC; DXC 1.9.2602.17; debug build- `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1436 passed, 2 failed, 47 ignored. The 2 failures are `fuzz_validate_and_gpu_1` (seed 722) and `_3` (seed 1599), the AMD ones from #2115, not touched here. - SKIPPED (7): 6 × f16 / f32 per-lane forms refused (#1426); `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) **Not tested** - No regression run on a real title (no game data here); this covers only the test suite on AMD **AI use** - Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2626
No description provided.