D3D12.X: a view's padding does not make a second texture #2762

Open
github-bot wants to merge 1 commit from github-bot/gh-2762 into main AGit
Owner

@⁠joeypercia on GitHub · 2026-11-26 10:53 UTC · original
joeypercia:d3d12x-view-key-padding → main · +49 −4 · 2 files · 1 commits · open

resource_at makes a placed texture for each new (address, description) of a view the title writes without a resource object (device #70 / #71, CreateShaderResourceViewAtX / CreateUnorderedAccessViewAtX), and keeps it for later views. Its key cleared the padding after the flags (bytes 0x34..0x38) but not the padding after Dimension (bytes 0x04..0x08). The newer retail title leaves that padding set, so the same view made another texture whenever it differed. @⁠GreemSC counted 24,844 such twins among 80,953 textures in a 200 s run (31 %, #2743). This clears both. Part of #2743 and #2688.

There's no eviction here. A version that let earlier textures go when a view covered their memory bounded the count on an RTX 4070 Ti (about 24,000 instead of 62,822 and climbing), but it didn't lower video memory. More than half of what it let go was made again, and its one run ended in the title's own breakpoint. Details are on #2743.

What is in it (one commit, crates/xcl/src/hle/d3d12x/real.rs, crates/xcl/src/host.rs)

  • view_key clears both padding ranges of the 0x38-byte description. resource_at keys its map with it, and passes the cleared description on.
  • The activity line counts the textures kept (views without a resource: N textures kept).
  • Test padding_does_not_make_another_texture: two descriptions that differ only in their padding give one key, and a change of any other byte (dimension, width, format, flags) keeps them apart. It fails without the change (padding at 0x04).

Tested

  • NVIDIA GeForce RTX 4070 Ti (driver 621.40), and the AMD Radeon iGPU of a Ryzen 7 7800X3D (RDNA2) with XCL_ADAPTER=Radeon. Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.8.2502.11. Debug builds for the tests, release for the runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 496ef578:
    • RTX 4070 Ti: 1436 passed, 0 failed, 47 ignored.
    • RDNA2: 1435 passed, 1 failed, 47 ignored. The failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, which fails the same way on main on this iGPU (#2115).
  • In the newer retail title with the same key on nvidia-dev af2cecc4 (1 GiB shader heap, through the world load), the count was 15,773 at 71 s, 42,457 at 121 s and 62,822 at 403 s. I have no count on this card without the change; the 31 % is GreemSC's (AMD / Linux, #2743).

Regression run

RTX 4070 Ti (driver 621.40), release builds, 60 s each, scripts/smoke.ps1 -Game <folder> -Title retail-title on the newer retail title, with the same settings. Both ran with the NVIDIA shader-heap profile (#2590, 1 GiB) installed on this machine. The PR's run shared the GPU with a test suite of mine for part of it. main b49be183 (this PR's base) and this PR's head (no uncommitted changes):

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 58 48
device removals: 0
crashes: 0
peak commit: 15772 MB

PR:

xcl-smoke v1
commit: 496ef5780a4549fc3f15bc65340deb1db4794d6b
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1374 (PresentX 1374)
presents per 2 s (last 3): 51 38 26
device removals: 0
crashes: 0
peak commit: 16909 MB

Not tested

  • How much the twins cost on Windows. Native D3D12 makes an unmapped reserved texture for about 3–9 KB of commit and no video memory (#2743), so on Windows this is mostly fewer objects. Under vkd3d-proton each costs more (GreemSC, #2743).
  • That every title leaves only padding in those bytes: Dimension is a 4-byte enum, followed by the 8-byte Alignment at 0x08, so 0x04..0x08 is padding in D3D12_RESOURCE_DESC.
  • AMD in a title.

AI use

  • Claude Code with Claude Opus 5.5 wrote the code, the test and this description, and ran the tests and the runs on the hardware above. GreemSC found and counted the padding twins (#2743).
**@⁠joeypercia** on GitHub · 2026-11-26 10:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2762) `joeypercia:d3d12x-view-key-padding` → `main` · +49 −4 · 2 files · 1 commits · open `resource_at` makes a placed texture for each new (address, description) of a view the title writes without a resource object (device #70 / #71, `CreateShaderResourceViewAtX` / `CreateUnorderedAccessViewAtX`), and keeps it for later views. Its key cleared the padding after the flags (bytes 0x34..0x38) but not the padding after `Dimension` (bytes 0x04..0x08). The newer retail title leaves that padding set, so the same view made another texture whenever it differed. @⁠GreemSC counted 24,844 such twins among 80,953 textures in a 200 s run (31 %, #2743). This clears both. Part of #2743 and #2688. There's no eviction here. A version that let earlier textures go when a view covered their memory bounded the count on an RTX 4070 Ti (about 24,000 instead of 62,822 and climbing), but it didn't lower video memory. More than half of what it let go was made again, and its one run ended in the title's own breakpoint. Details are on #2743. **What is in it** (one commit, `crates/xcl/src/hle/d3d12x/real.rs`, `crates/xcl/src/host.rs`) - `view_key` clears both padding ranges of the 0x38-byte description. `resource_at` keys its map with it, and passes the cleared description on. - The activity line counts the textures kept (`views without a resource: N textures kept`). - Test `padding_does_not_make_another_texture`: two descriptions that differ only in their padding give one key, and a change of any other byte (dimension, width, format, flags) keeps them apart. It fails without the change (padding at 0x04). **Tested** - NVIDIA GeForce RTX 4070 Ti (driver 621.40), and the AMD Radeon iGPU of a Ryzen 7 7800X3D (RDNA2) with `XCL_ADAPTER=Radeon`. Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.8.2502.11. Debug builds for the tests, release for the runs. - `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4` on `496ef578`: - RTX 4070 Ti: **1436 passed, 0 failed, 47 ignored**. - RDNA2: **1435 passed, 1 failed, 47 ignored**. The failure is `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`, which fails the same way on `main` on this iGPU (#2115). - In the newer retail title with the same key on `nvidia-dev` `af2cecc4` (1 GiB shader heap, through the world load), the count was 15,773 at 71 s, 42,457 at 121 s and 62,822 at 403 s. I have no count on this card without the change; the 31 % is GreemSC's (AMD / Linux, #2743). **Regression run** RTX 4070 Ti (driver 621.40), release builds, 60 s each, `scripts/smoke.ps1 -Game <folder> -Title retail-title` on the newer retail title, with the same settings. Both ran with the NVIDIA shader-heap profile (#2590, 1 GiB) installed on this machine. The PR's run shared the GPU with a test suite of mine for part of it. `main` `b49be183` (this PR's base) and this PR's head (no uncommitted changes): main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 4070 Ti title: retail-title seconds: 60 exit: 0x0 frames shown: 1587 (PresentX 1587) presents per 2 s (last 3): 60 58 48 device removals: 0 crashes: 0 peak commit: 15772 MB ``` PR: ``` xcl-smoke v1 commit: 496ef5780a4549fc3f15bc65340deb1db4794d6b gpu: NVIDIA GeForce RTX 4070 Ti title: retail-title seconds: 60 exit: 0x0 frames shown: 1374 (PresentX 1374) presents per 2 s (last 3): 51 38 26 device removals: 0 crashes: 0 peak commit: 16909 MB ``` **Not tested** - How much the twins cost on Windows. Native D3D12 makes an unmapped reserved texture for about 3–9 KB of commit and no video memory (#2743), so on Windows this is mostly fewer objects. Under vkd3d-proton each costs more (GreemSC, #2743). - That every title leaves only padding in those bytes: `Dimension` is a 4-byte enum, followed by the 8-byte `Alignment` at 0x08, so 0x04..0x08 is padding in `D3D12_RESOURCE_DESC`. - AMD in a title. **AI use** - Claude Code with Claude Opus 5.5 wrote the code, the test and this description, and ran the tests and the runs on the hardware above. GreemSC found and counted the padding twins (#2743).
resource_at makes a placed texture for each new (address, description)
of a view the title writes without a resource object (device #70/#71)
and keeps it. Its key cleared the padding after the flags but not the
padding after Dimension (bytes 4..8). A retail title leaves that set,
so the same view made another texture whenever it differed: 24,844 of
80,953 textures in a 200 s run were such twins (GreemSC, #2743).

The key now leaves out both. The activity line counts the textures
kept.

Part of #2743, #2688.

Assisted-by: Claude Code (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:14:58 +00:00
Author
Owner

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

On 496ef5780a4549fc3f15bc65340deb1db4794d6b, the new VIEW_TEXTURES activity count uses MADE.len(), but resource_at deliberately caches failed creations as a null pointer. A driver-refused descriptor therefore increases views without a resource: N textures kept even though no texture was created; repeated distinct failures can make this diagnostic grow during the OOM investigation that motivated the PR. Could the count include only non-null cached resources, or call it cache entries and report failures separately? A small map fixture with one successful pointer and one null entry could lock the meaning down. This is exact-head source review; I did not induce a D3D12 creation failure.

AI use: OpenAI Codex (GPT-6.2 Sol) found the count mismatch; OpenAI Codex (GPT-6.2 Astra) independently checked the source and wrote this review.

**@⁠luckyteagirl** on GitHub · 2026-11-26 10:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/2762#pullrequestreview-6072874899) · **reviewed** On `496ef5780a4549fc3f15bc65340deb1db4794d6b`, the new `VIEW_TEXTURES` activity count uses `MADE.len()`, but `resource_at` deliberately caches failed creations as a null pointer. A driver-refused descriptor therefore increases `views without a resource: N textures kept` even though no texture was created; repeated distinct failures can make this diagnostic grow during the OOM investigation that motivated the PR. Could the count include only non-null cached resources, or call it cache entries and report failures separately? A small map fixture with one successful pointer and one null entry could lock the meaning down. This is exact-head source review; I did not induce a D3D12 creation failure. AI use: OpenAI Codex (GPT-6.2 Sol) found the count mismatch; OpenAI Codex (GPT-6.2 Astra) independently checked the source and wrote this review.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-26 10:59 UTC · original

Independent Windows/NVIDIA test of PR #2762 head 496ef578, based on main b49be183. The checkout had no source changes.

Tested: RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC, DXC 1.8.2502.11. cargo build --offline --locked --workspace passed. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 passed: 1,436 passed, 0 failed, 47 ignored. There were 25 GPU skip notices: 21 no wave64, 3 refused per-lane cases tracked in #1426, and 1 no heap windows. The PR's padding_does_not_make_another_texture test passed.

Not tested: a title run, matched smoke, or a measured reduction in texture count, memory, or frame time. The new unit test verifies key normalization; this suite does not by itself measure the retained-resource behavior in a retail workload.

AI use: Codex (GPT-6.2 Sol) inspected the diff, ran the commands on the hardware above, and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-26 10:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/2762#issuecomment-7190111354) Independent Windows/NVIDIA test of [PR #2762 head `496ef578`](https://github.com/xcl-dev/xcl/commit/496ef5780a4549fc3f15bc65340deb1db4794d6b), based on [`main` `b49be183`](https://github.com/xcl-dev/xcl/commit/b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). The checkout had no source changes. **Tested:** RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC, DXC 1.8.2502.11. `cargo build --offline --locked --workspace` passed. `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4` passed: **1,436 passed, 0 failed, 47 ignored**. There were **25 GPU skip notices**: 21 no wave64, 3 refused per-lane cases tracked in #1426, and 1 no heap windows. The PR's `padding_does_not_make_another_texture` test passed. **Not tested:** a title run, matched smoke, or a measured reduction in texture count, memory, or frame time. The new unit test verifies key normalization; this suite does not by itself measure the retained-resource behavior in a retail workload. AI use: Codex (GPT-6.2 Sol) inspected the diff, ran the commands on the hardware above, and drafted this report.
Author
Owner

@⁠GreemSC on GitHub · 2026-11-26 11:05 UTC · original

Linux / AMD test of 496ef57: the same ~30 % fewer view-only textures under Wine, the new activity line matches an independent count, no crash.

Tested

  • RX 7900 XT 20 GB, Mesa 26.2.5 RADV, i7-12700K, 24 GB RAM (title capped at 16 GB + 1 GB swap), Linux 7.2, Proton-CachyOS Wine 11, vkd3d-proton with dxil-spirv 53aac41; xcl.exe release, cross-built for x86_64-pc-windows-msvc.
  • main b49be18 + the Wine stack this machine needs (#1732 with #867/#871/#877, #684, #1860, #2097, #2404, #2615, #2598, #751, diagnostics) + local counters, with and without this PR's diff (one conflict, in host.rs's activity block: both kept). Retail title, warm caches, 200 s, XCL_DIRECT_DXIL=1 XCL_DXC_THREADS=4 XCL_TEXTURE_LEVEL_PAGES=1. Without: 2 runs; with: 1 run.
at textures made by resource_at, without (2 runs) with this PR: local count / views without a resource: N textures kept
60 s 16,015 / 16,015 15,773 / 15,773
120 s 59,309 / 59,676 41,930 / 41,930
190 s 79,515 / 80,953 56,778 / 56,778
  • −29 % at 190 s, in line with the 31 % padding twins counted earlier on #2743.
  • The title's anonymous memory at 190 s: 12.76 / 12.47 GB without, 12.59 GB with: no difference measurable in 200 s (each entry is a few KB here).
  • With the PR: last present 198.8 s of 200, 0 crashes, 0 device removals; the intro cutscene's subtitles were on screen (seen by the machine's owner).

Not tested: Windows, NVIDIA, more than one run with the PR, runs past 200 s, a smoke pair on this machine (plain main under Wine stops at ~2.5 s).

AI use: Claude Code (Claude Opus 5.5) merged the trees, ran the runs and wrote this report.

**@⁠GreemSC** on GitHub · 2026-11-26 11:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/2762#issuecomment-7190241683) **Linux / AMD test of `496ef57`: the same ~30 % fewer view-only textures under Wine, the new activity line matches an independent count, no crash.** **Tested** - RX 7900 XT 20 GB, Mesa 26.2.5 RADV, i7-12700K, 24 GB RAM (title capped at 16 GB + 1 GB swap), Linux 7.2, Proton-CachyOS Wine 11, vkd3d-proton with dxil-spirv 53aac41; `xcl.exe` release, cross-built for `x86_64-pc-windows-msvc`. - `main` `b49be18` + the Wine stack this machine needs (#1732 with #867/#871/#877, #684, #1860, #2097, #2404, #2615, #2598, #751, diagnostics) + local counters, with and without this PR's diff (one conflict, in `host.rs`'s activity block: both kept). Retail title, warm caches, 200 s, `XCL_DIRECT_DXIL=1 XCL_DXC_THREADS=4 XCL_TEXTURE_LEVEL_PAGES=1`. Without: 2 runs; with: 1 run. | at | textures made by `resource_at`, without (2 runs) | with this PR: local count / `views without a resource: N textures kept` | |---|---:|---:| | 60 s | 16,015 / 16,015 | 15,773 / 15,773 | | 120 s | 59,309 / 59,676 | 41,930 / 41,930 | | 190 s | 79,515 / 80,953 | **56,778 / 56,778** | - −29 % at 190 s, in line with the 31 % padding twins counted earlier on #2743. - The title's anonymous memory at 190 s: 12.76 / 12.47 GB without, 12.59 GB with: no difference measurable in 200 s (each entry is a few KB here). - With the PR: last present 198.8 s of 200, 0 crashes, 0 device removals; the intro cutscene's subtitles were on screen (seen by the machine's owner). **Not tested:** Windows, NVIDIA, more than one run with the PR, runs past 200 s, a smoke pair on this machine (plain `main` under Wine stops at ~2.5 s). AI use: Claude Code (Claude Opus 5.5) merged the trees, ran the runs and wrote this report.
Author
Owner

@⁠CryingLaughing on GitHub · 2026-11-26 11:26 UTC · original

On native D3D12 with an RTX 4080, changing only padding bytes 0x04..0x08 of one valid placed-texture description created another native resource on main. The same request reused the original resource on this head. The comparison uses the actual resource_at path and retains the resources while checking canonical COM identity.

Revision with the same test-only overlay Leading-padding request reused the original Unique native textures
Parent b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 No 3
Head 496ef5780a4549fc3f15bc65340deb1db4794d6b Yes 2

An exact repeat and the already-normalized trailing-padding control both reused the original on each revision. A second aligned title-memory address remained distinct. All resources were 64×64 RGBA8 shared-page textures.

Tested on RTX 4080 driver 621.01, i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, DXC 1.8.2502.11. XCL_ADAPTER=4080. Overlay patch ID 9f77f5043af453cab2f6057d256816bb1c361004.

cargo test -p xcl --lib --locked -j 4 --no-run --message-format=json, then the test executable with hle::d3d12x::real::resource_at_identity_fixture::resource_at_reuses_texture_across_padding_only_changes --exact --test-threads=1 --nocapture. 1 passed, 0 failed, 0 ignored, 0 capability skips per revision. This measures resource identity. Retail memory use and the workspace suite with the overlay remain untested.

**@⁠CryingLaughing** on GitHub · 2026-11-26 11:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/2762#issuecomment-7190727078) On native D3D12 with an RTX 4080, changing only padding bytes `0x04..0x08` of one valid placed-texture description created another native resource on main. The same request reused the original resource on this head. The comparison uses the actual `resource_at` path and retains the resources while checking canonical COM identity. | Revision with the same test-only overlay | Leading-padding request reused the original | Unique native textures | | --- | --- | ---: | | Parent `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7` | No | 3 | | Head `496ef5780a4549fc3f15bc65340deb1db4794d6b` | Yes | 2 | An exact repeat and the already-normalized trailing-padding control both reused the original on each revision. A second aligned title-memory address remained distinct. All resources were 64×64 RGBA8 shared-page textures. **Tested** on RTX 4080 driver 621.01, i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, DXC 1.8.2502.11. `XCL_ADAPTER=4080`. Overlay patch ID `9f77f5043af453cab2f6057d256816bb1c361004`. `cargo test -p xcl --lib --locked -j 4 --no-run --message-format=json`, then the test executable with `hle::d3d12x::real::resource_at_identity_fixture::resource_at_reuses_texture_across_padding_only_changes --exact --test-threads=1 --nocapture`. **1 passed, 0 failed, 0 ignored, 0 capability skips per revision**. This measures resource identity. Retail memory use and the workspace suite with the overlay remain untested.
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/2762/head:github-bot/gh-2762'
git switch 'github-bot/gh-2762'

Merge

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