D3D12.X: track sampled texture resident and SRV-sampled texels #2730

Open
github-bot wants to merge 2 commits from github-bot/gh-2730 into main AGit
Owner

@⁠O5-7 on GitHub · 2026-11-26 09:06 UTC · original
O5-7:vram/ws5-texel-accounting → main · +445 −3 · 3 files · 2 commits · open

What is in it

  • Workstream 5 of #2688 (per-texel residency vs SRV-sampled accounting, pure measurement with zero behaviour changes).
  • Track TexelMeta (virtual texels, resident texels, and deduplicated per-(slice, mip) coverage across Texture1D/Texture2D/Texture3D/arrays/cubes, resolving res.GetDesc() and MipLevels == 0 full mip chains) on placed sampled textures in crates/xcl/src/hle/d3d12x/vram.rs, updated on placement, map_levels, unmap_superseded, remap_if_unmapped, forget_pages, and SRV creation (dev_create_srv_x in crates/xcl/src/hle/d3d12x/real.rs).
  • Emit a standalone texture residency: N sampled (M with SRV); texels X.XM resident / Y.YM srv-sampled / Z.ZM virtual (P% resident) line in XCL_ACTIVITY=1 right after memory: in crates/xcl/src/host.rs (keeping the memory: line untouched; texels live on their own line next to memory_report::Snapshot::parts as suggested on #2697).

Tested

  • hardware (GPU + driver, CPU), Rust version, release: NVIDIA GeForce RTX 5080 (driver 32.0.15.9579), AMD Ryzen 7 9700X, Windows 11 Pro 10.0.26100, rustc 1.100.0 (0ef1bc386 2026-11-09), release build (cargo build --release -p xcl).
  • cargo test -p xcl --lib vram::tests -- --nocapture on head 2e63cbcf: 24 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing), including 5 texel accounting unit tests (mip_texels_and_range_for_2d_array_3d_and_1d, srv_coverage_respects_most_detailed_mip_levels_min_lod_clamp_and_slices, texel_meta_unions_overlapping_srv_ranges_without_double_counting, texel_meta_tracks_array_slice_coverage_without_overcounting, texel_meta_resolves_implicit_zero_mip_levels_to_full_chain). (cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored on base PR commit 5c09fc39.)

Regression run

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1683 (PresentX 1683)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14252 MB
xcl-smoke v1
commit: 2e63cbcf565d7309e10da2cddbec37c40e0eb990
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1682 (PresentX 1682)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 13644 MB

Not tested

  • No other titles besides title hash 9cc6a39e were run, and #[ignore] hardware/oracle tests were skipped.
  • Non-placed committed textures do not populate TexelStats (by design: this accounts placed sampled textures in vram::PAGES).

AI use

  • Antigravity coding agent helped implement the texel accounting, per-slice / MipLevels=0 fixes, unit tests, and regression runs, reviewed and verified locally.
**@⁠O5-7** on GitHub · 2026-11-26 09:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2730) `O5-7:vram/ws5-texel-accounting` → `main` · +445 −3 · 3 files · 2 commits · open **What is in it** - Workstream 5 of #2688 (per-texel residency vs SRV-sampled accounting, pure measurement with zero behaviour changes). - Track `TexelMeta` (virtual texels, resident texels, and deduplicated per-`(slice, mip)` coverage across `Texture1D`/`Texture2D`/`Texture3D`/arrays/cubes, resolving `res.GetDesc()` and `MipLevels == 0` full mip chains) on placed sampled textures in `crates/xcl/src/hle/d3d12x/vram.rs`, updated on placement, `map_levels`, `unmap_superseded`, `remap_if_unmapped`, `forget_pages`, and SRV creation (`dev_create_srv_x` in `crates/xcl/src/hle/d3d12x/real.rs`). - Emit a standalone `texture residency: N sampled (M with SRV); texels X.XM resident / Y.YM srv-sampled / Z.ZM virtual (P% resident)` line in `XCL_ACTIVITY=1` right after `memory:` in `crates/xcl/src/host.rs` (keeping the `memory:` line untouched; texels live on their own line next to `memory_report::Snapshot::parts` as suggested on #2697). **Tested** - hardware (GPU + driver, CPU), Rust version, release: NVIDIA GeForce RTX 5080 (driver 32.0.15.9579), AMD Ryzen 7 9700X, Windows 11 Pro 10.0.26100, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, release build (`cargo build --release -p xcl`). - `cargo test -p xcl --lib vram::tests -- --nocapture` on head `2e63cbcf`: 24 passed, 0 failed, 1 ignored (`churn_update_tile_mappings_timing`), including 5 texel accounting unit tests (`mip_texels_and_range_for_2d_array_3d_and_1d`, `srv_coverage_respects_most_detailed_mip_levels_min_lod_clamp_and_slices`, `texel_meta_unions_overlapping_srv_ranges_without_double_counting`, `texel_meta_tracks_array_slice_coverage_without_overcounting`, `texel_meta_resolves_implicit_zero_mip_levels_to_full_chain`). (`cargo test --workspace -- --test-threads=4`: 1438 passed, 0 failed, 47 ignored on base PR commit `5c09fc39`.) **Regression run** ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1683 (PresentX 1683) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14252 MB ``` ``` xcl-smoke v1 commit: 2e63cbcf565d7309e10da2cddbec37c40e0eb990 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1682 (PresentX 1682) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 13644 MB ``` **Not tested** - No other titles besides title hash `9cc6a39e` were run, and `#[ignore]` hardware/oracle tests were skipped. - Non-placed committed textures do not populate `TexelStats` (by design: this accounts placed sampled textures in `vram::PAGES`). **AI use** - Antigravity coding agent helped implement the texel accounting, per-slice / `MipLevels=0` fixes, unit tests, and regression runs, reviewed and verified locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:14:11 +00:00
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 09:12 UTC · original · reviewed

On 5c09fc3, srv_mip_range extracts only mip fields from Texture1DArray, Texture2DArray, and TextureCubeArray SRVs. record_srv then deduplicates only by mip bit and mask_texels counts each selected mip using the resource's full DepthOrArraySize. For a 64×64 six-slice 2D array with an explicit mip-0 SRV exposing only slice 0, the new srv-sampled counter adds 24,576 texels rather than the 4,096 the view can sample. A second SRV exposing slice 1 adds zero because mip 0 is already marked. That makes the array/cube-array metric insensitive to slice coverage despite this PR claiming SRV-sampled texels.

Could the coverage union include array slices as well as mip levels, or label the current number as a whole-mip upper bound? A CPU fixture with one-slice, duplicate, and different-slice SRVs could assert increments of 4,096, 0, and 4,096 respectively. This is source review only; I did not run the fixture or a title.

**@⁠luckyteagirl** on GitHub · 2026-11-26 09:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2730#pullrequestreview-6071300926) · **reviewed** On `5c09fc3`, `srv_mip_range` extracts only mip fields from `Texture1DArray`, `Texture2DArray`, and `TextureCubeArray` SRVs. `record_srv` then deduplicates only by mip bit and `mask_texels` counts each selected mip using the resource's full `DepthOrArraySize`. For a 64×64 six-slice 2D array with an explicit mip-0 SRV exposing only slice 0, the new `srv-sampled` counter adds 24,576 texels rather than the 4,096 the view can sample. A second SRV exposing slice 1 adds zero because mip 0 is already marked. That makes the array/cube-array metric insensitive to slice coverage despite this PR claiming SRV-sampled texels. Could the coverage union include array slices as well as mip levels, or label the current number as a whole-mip upper bound? A CPU fixture with one-slice, duplicate, and different-slice SRVs could assert increments of 4,096, 0, and 4,096 respectively. This is source review only; I did not run the fixture or a title.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 10:51 UTC · original · reviewed

On 5c09fc3924200753340b6900e664aea0faf2c48c, could the texel metadata use the created resource's resolved mip count when the input descriptor has MipLevels=0? D3D12 defines zero as requesting the maximum mip chain. place_on_pages creates the reserved resource, but then passes the original descriptor to TexelMeta::from_desc, where desc.MipLevels.max(1) treats zero as one level. For a supported 64×64 non-array sampled texture, a default full-resource SRV should cover seven levels / 5,461 texels; the new counters record only mip 0 / 4,096. This is separate from the array-slice coverage point already posted. Could metadata use res.GetDesc() (or expand the zero sentinel) and include an implicit-full-chain fixture? This is source and D3D12-contract review with arithmetic; I did not run the GPU fixture.

AI use: OpenAI Codex (GPT-6.2 Sol) found the mismatch; a second GPT-6.2 Sol agent and OpenAI Codex (GPT-6.2 Astra) independently checked the creation path and wrote this review.

**@⁠luckyteagirl** on GitHub · 2026-11-26 10:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/2730#pullrequestreview-6072808502) · **reviewed** On `5c09fc3924200753340b6900e664aea0faf2c48c`, could the texel metadata use the created resource's resolved mip count when the input descriptor has `MipLevels=0`? [D3D12 defines zero as requesting the maximum mip chain](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_resource_desc#miplevels). `place_on_pages` creates the reserved resource, but then passes the original descriptor to `TexelMeta::from_desc`, where `desc.MipLevels.max(1)` treats zero as one level. For a supported 64×64 non-array sampled texture, a default full-resource SRV should cover seven levels / 5,461 texels; the new counters record only mip 0 / 4,096. This is separate from the array-slice coverage point already posted. Could metadata use `res.GetDesc()` (or expand the zero sentinel) and include an implicit-full-chain fixture? This is source and D3D12-contract review with arithmetic; I did not run the GPU fixture. AI use: OpenAI Codex (GPT-6.2 Sol) found the mismatch; a second GPT-6.2 Sol agent and OpenAI Codex (GPT-6.2 Astra) independently checked the creation path and wrote this review.
Author
Owner

@⁠O5-7 on GitHub · 2026-11-26 12:04 UTC · original

@⁠luckyteagirl Addressed both review points in 2e63cbcf:

  1. Tracked SRV coverage per (slice, mip) pair (srv_coverage + TexelMeta::srv_extra_slices for slices >= 1), handling Texture1DArray/Texture2DArray (FirstArraySlice + ArraySize) and TextureCubeArray (First2DArrayFace + NumCubes * 6) without overcounting unsampled slices. Added texel_meta_tracks_array_slice_coverage_without_overcounting asserting 4096, 0, 4096 increments on single-slice / duplicate / next-slice SRVs.
  2. Resolved MipLevels == 0 to the full mip chain via both res.GetDesc() in place_on_pages and resolved_mip_levels() in TexelMeta::from_desc. Added texel_meta_resolves_implicit_zero_mip_levels_to_full_chain (64x64 MipLevels: 0 -> 7 levels / 5461 texels).

Re-verified cargo test -p xcl --lib vram::tests (24 passed, 0 failed, 1 ignored) and 60 s smoke.ps1 on 2e63cbcf.

**@⁠O5-7** on GitHub · 2026-11-26 12:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2730#issuecomment-7191524959) @⁠luckyteagirl Addressed both review points in `2e63cbcf`: 1. Tracked SRV coverage per `(slice, mip)` pair (`srv_coverage` + `TexelMeta::srv_extra_slices` for slices `>= 1`), handling `Texture1DArray`/`Texture2DArray` (`FirstArraySlice` + `ArraySize`) and `TextureCubeArray` (`First2DArrayFace` + `NumCubes * 6`) without overcounting unsampled slices. Added `texel_meta_tracks_array_slice_coverage_without_overcounting` asserting `4096`, `0`, `4096` increments on single-slice / duplicate / next-slice SRVs. 2. Resolved `MipLevels == 0` to the full mip chain via both `res.GetDesc()` in `place_on_pages` and `resolved_mip_levels()` in `TexelMeta::from_desc`. Added `texel_meta_resolves_implicit_zero_mip_levels_to_full_chain` (`64x64` `MipLevels: 0` -> `7` levels / `5461` texels). Re-verified `cargo test -p xcl --lib vram::tests` (`24 passed, 0 failed, 1 ignored`) and 60 s `smoke.ps1` on `2e63cbcf`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2730/head:github-bot/gh-2730'
git switch 'github-bot/gh-2730'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2730'
git switch 'github-bot/gh-2730'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2730'
git switch 'github-bot/gh-2730'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2730'
git switch 'main'
git merge --squash 'github-bot/gh-2730'
git switch 'main'
git merge --ff-only 'github-bot/gh-2730'
git switch 'main'
git merge 'github-bot/gh-2730'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.