D3D12.X: count CPU-backed title textures as they come and go #3576

Open
raylitebull wants to merge 1 commit from upstream-pr/3576 into main
raylitebull commented 2026-12-01 14:44:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-12-01T14:44:27Z.


update_lengths runs under the TEXTURES lock on every placement, release, retirement and uncover, and counted the CPU-backed entries by walking all of by_res. A retail title keeps tens of thousands of entries there (55k+ on amd-dev). Now Table keeps the count up to date wherever by_res changes.

What is in it

  • title_textures.rs: Table::cpu_backed_count, maintained by insert_active / remove_active (all by_res inserts and removals in Table go through them); update_lengths stores it.
  • In debug builds, update_lengths checks the count against a full count, so a later by_res change that bypasses the helpers fails in tests instead of dropping uploads.
  • Test: the_cpu_backed_count_follows_the_active_textures.

Tested

  • No Windows machine or GPU here: a Linux x86_64 cloud machine (Ubuntu 24.04), rustc 1.99.0, debug build.
  • cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: no errors, no new warnings.
  • The lib unit tests of the touched modules, built for x86_64-pc-windows-gnu and run under Wine 9.0 (no GPU) with --test-threads=4, next to the same filters on main b2b1f109:
    • hle::d3d12x::title_textures: 65 passed, 1 failed, 1 ignored (main: 64 / 1 / 1)
      The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks.

Regression run
Not run yet: there was no Windows machine or title here. scripts/smoke.ps1 still has to run on a title, built from main and from this head, so PR checks fails until those two blocks are added.

Not tested

  • The Windows (MSVC) build and the whole suite (cargo test --workspace -- --test-threads=4) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run.
  • Any title on main, and any performance on main: the numbers above are from amd-dev.
  • This part was not measured on its own: on amd-dev it is part of 4d6d4a77, whose numbers cover all of its lock changes together.

AI use

  • Capy with Claude Opus 5.5 ported raylitebull's amd-dev commit 4d6d4a77 to main, split it into this PR and five others, and wrote the test, the commit message and this description. The amd-dev measurements are raylitebull's own runs.

Open in Capy

<!-- greyfinch-sync:ivall/xcl:issue:5588048604 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3576). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-12-01T14:44:27Z. --- `update_lengths` runs under the `TEXTURES` lock on every placement, release, retirement and uncover, and counted the CPU-backed entries by walking all of `by_res`. A retail title keeps tens of thousands of entries there (55k+ on `amd-dev`). Now `Table` keeps the count up to date wherever `by_res` changes. **What is in it** - `title_textures.rs`: `Table::cpu_backed_count`, maintained by `insert_active` / `remove_active` (all `by_res` inserts and removals in `Table` go through them); `update_lengths` stores it. - In debug builds, `update_lengths` checks the count against a full count, so a later `by_res` change that bypasses the helpers fails in tests instead of dropping uploads. - Test: `the_cpu_backed_count_follows_the_active_textures`. **Tested** - No Windows machine or GPU here: a Linux x86_64 cloud machine (Ubuntu 24.04), rustc 1.99.0, debug build. - `cargo check --workspace --all-targets --target x86_64-pc-windows-gnu`: no errors, no new warnings. - The lib unit tests of the touched modules, built for `x86_64-pc-windows-gnu` and run under Wine 9.0 (no GPU) with `--test-threads=4`, next to the same filters on `main` `b2b1f109`: - `hle::d3d12x::title_textures`: 65 passed, 1 failed, 1 ignored (main: 64 / 1 / 1) The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks. **Regression run** Not run yet: there was no Windows machine or title here. `scripts/smoke.ps1` still has to run on a title, built from `main` and from this head, so `PR checks` fails until those two blocks are added. **Not tested** - The Windows (MSVC) build and the whole suite (`cargo test --workspace -- --test-threads=4`) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run. - Any title on `main`, and any performance on `main`: the numbers above are from `amd-dev`. - This part was not measured on its own: on `amd-dev` it is part of `4d6d4a77`, whose numbers cover all of its lock changes together. **AI use** - Capy with Claude Opus 5.5 ported raylitebull's `amd-dev` commit `4d6d4a77` to `main`, split it into this PR and five others, and wrote the test, the commit message and this description. The `amd-dev` measurements are raylitebull's own runs. <!-- capy-badge:start --> <a href="https://capy.ai/thread/jam_01M8RYX4CVNT8FXPPZSVVY1EFJ"><picture><source media="(prefers-color-scheme: dark)" srcset="https://capy.ai/badge/accent-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://capy.ai/badge/accent-light.svg"><img alt="Open in Capy" src="https://capy.ai/badge/accent-light.svg"></picture></a> <!-- capy-badge:end -->
Foniass commented 2026-12-01 14:50:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T14:50:08Z.


Review (head 013d8e3d, diff read, not a merge-check; draft):

  • The count is right today, but nothing keeps it right. cpu_backed is set only when an Entry is created (title_textures.rs ~589, ~674, ~4835, ~4960), and every non-test by_res insert and remove goes through insert_active / remove_active under TEXTURES, so it can't drift or underflow now. Its one reader, refresh_parts (~1952), skips uploads when the count is 0 and the device has no sparse support. A future insert that bypasses the helpers would make it read 0 and drop uploads silently. A debug_assert_eq! against a full count in update_lengths (~539) would catch that in tests.
  • The gain isn't measured on main. The only numbers are from amd-dev 4d6d4a77, which bundles six lock changes; a measurement of this change alone (placements / releases per second, or frame time on a title that streams textures) would show what it buys.
  • The new test can't fail on main (the field doesn't exist there), which is fine for a speed change.

Fine: shadowing and uncovering keep the count (an entry is in by_res or shadowed, never both), and the default path only loses a full scan per placement and release. #3426 edits Table::remove and will conflict textually.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7314904884 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3576#issuecomment-7314904884). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T14:50:08Z. --- Review (head 013d8e3d, diff read, not a merge-check; draft): - **The count is right today, but nothing keeps it right.** `cpu_backed` is set only when an `Entry` is created (`title_textures.rs` ~589, ~674, ~4835, ~4960), and every non-test `by_res` insert and remove goes through `insert_active` / `remove_active` under `TEXTURES`, so it can't drift or underflow now. Its one reader, `refresh_parts` (~1952), skips uploads when the count is 0 and the device has no sparse support. A future insert that bypasses the helpers would make it read 0 and drop uploads silently. A `debug_assert_eq!` against a full count in `update_lengths` (~539) would catch that in tests. - **The gain isn't measured on main.** The only numbers are from `amd-dev` 4d6d4a77, which bundles six lock changes; a measurement of this change alone (placements / releases per second, or frame time on a title that streams textures) would show what it buys. - The new test can't fail on main (the field doesn't exist there), which is fine for a speed change. Fine: shadowing and uncovering keep the count (an entry is in `by_res` or `shadowed`, never both), and the default path only loses a full scan per placement and release. #3426 edits `Table::remove` and will conflict textually. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 14:59:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T14:59:01Z.


Follow-up (head d2752076; the one-line diff from 013d8e3d read). The debug_assert_eq! against a full count of CPU-backed textures is in update_lengths, so a future by_res change that bypasses insert_active / remove_active fails in debug builds and tests instead of silently dropping uploads. That was my only code point; the gain on main is still unmeasured.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7315145925 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3576#issuecomment-7315145925). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T14:59:01Z. --- Follow-up (head d2752076; the one-line diff from 013d8e3d read). The `debug_assert_eq!` against a full count of CPU-backed textures is in `update_lengths`, so a future `by_res` change that bypasses `insert_active` / `remove_active` fails in debug builds and tests instead of silently dropping uploads. That was my only code point; the gain on main is still unmeasured. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
capy-ai[bot] commented 2026-12-01 15:06:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-01T15:06:16Z.


@Foniass thanks, the debug check is in (d2752076), as you confirmed. A measurement on main will come with the smoke runs.

AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.

<!-- greyfinch-sync:ivall/xcl:comment:7315350672 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3576#issuecomment-7315350672). Originally posted by [capy-ai[bot]](https://github.com/apps/capy-ai) on 2026-12-01T15:06:16Z. --- @Foniass thanks, the debug check is in (d2752076), as you confirmed. A measurement on `main` will come with the smoke runs. AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.
Foniass commented 2026-12-01 15:23:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:23:44Z.


Test report (not a merge-check: draft, PR description red)
base: b2b1f109d2
head: d275207689
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3576#issuecomment-7315145925, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run. A bookkeeping change whose cost a 60 s run capped at 60 presents per second can't show.
assessment: merges, builds and passes the whole suite on current main, including the new count check in the debug-build tests; still open: a measurement of the gain on main
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7315837222 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3576#issuecomment-7315837222). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T15:23:44Z. --- Test report (not a merge-check: draft, `PR description` red) base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: d275207689bbd16f76edc4f6e907064581073f4d merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3576#issuecomment-7315145925, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main. performance: no smoke run. A bookkeeping change whose cost a 60 s run capped at 60 presents per second can't show. assessment: merges, builds and passes the whole suite on current main, including the new count check in the debug-build tests; still open: a measurement of the gain on main hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3576:upstream-pr/3576'
git switch 'upstream-pr/3576'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3576'
git switch 'upstream-pr/3576'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3576'
git switch 'upstream-pr/3576'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3576'
git switch 'main'
git merge --squash 'upstream-pr/3576'
git switch 'main'
git merge --ff-only 'upstream-pr/3576'
git switch 'main'
git merge 'upstream-pr/3576'
git push origin 'main'
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!3576
No description provided.