d3d12: trace the first declared use of uploaded textures #3492

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u  "codex/texture-first-gpu-use:kaoru-maki-codex/texture-first-gpu-use"
git switch "kaoru-maki-codex/texture-first-gpu-use"
Open
leonida/mandy
kaoru-maki wants to merge 4 commits from kaoru-maki/mandy:codex/texture-first-gpu-use into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
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 'codex/texture-first-gpu-use:kaoru-maki-codex/texture-first-gpu-use'
git switch 'kaoru-maki-codex/texture-first-gpu-use'
Contributor

Claimed in the coordination issue as: D3D12-TEXTURE-FIRST-GPU-USE

What and why

The DirectStorage investigation showed why we need to follow texture data beyond I/O completion. This change adds an opt-in D3D12 diagnostic, LEONIDA_TEXTURE_FIRST_USE=1, that follows a staged upload to the first recorded draw that declares its host texture and can be ordered after the upload. The trace then associates it with the first successful Present whose presentation-copy fence follows the draw. Original finding in #2570

The trace covers graphics preludes and the texture copy worker. For the copy queue it requires an observed completion before the graphics submission. A later graphics fence observation can complete an earlier Present's row. The row establishes declaration and queue order at host-texture granularity. The hardware readbacks below verify sampling at mip 0 after uploads through both queues.

When a recent direct-memory storage write matches the complete staged input by range and bytes, the row can carry its run-local write ID. Rows contain run-local identifiers, relative times, queue, frame and fence values.

Tested

The hardware and CPU checks ran on 6b0498d377. On current main 0036195a72, the production diff and the Rust sources, Cargo inputs, and synthetic hardware fixture used for validation are byte-for-byte identical.

  • Nine native DXGI Present runs passed with generated 8 x 8 textures and a synthetic swap chain. Three runs used synchronous presentation copies, three used presentation copies sent ahead, and three delayed the fence observed by the tracker. All sampled readbacks matched 64 of 64 RGBA pixels.
  • In both presentation-copy modes, the tracker linked graphics draw fence 4 to Present fence 5 and draw fence 7 after a copy-queue upload to Present fence 8. Present calls before those draws and duplicate Presents produced no new trace rows.
  • In the delayed case, DXGI accepted frame 21 with the graphics fence still at 3. After the test gate was released, frame 22 emitted one row with first_frame=21 and present_fence=5.
  • Nine CPU-only synthetic first-use tests passed. The copy-order regression failed in an isolated test variant with the readiness check removed and passed with the check in place. The repository clean-room, diff, and switch-catalog checks passed.
  • Separate hardware checks on the original candidate verified generated texture sampling in three graphics-prelude and three copy-queue runs, with zero-vertex controls preserving the clear color.

GPUs tested: NVIDIA GeForce RTX 5070 Ti Laptop GPU, NVIDIA driver 621.47, Windows 11.

AI-assisted: OpenAI Codex (GPT-6), independently reviewed with GPT-6.2 Sol.

Checklist

  • Based on current main and applies cleanly.
  • One topic.
  • No game data, keys or decryption.
Claimed in the coordination issue as: [D3D12-TEXTURE-FIRST-GPU-USE](https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-26420) ### What and why The DirectStorage investigation showed why we need to follow texture data beyond I/O completion. This change adds an opt-in D3D12 diagnostic, `LEONIDA_TEXTURE_FIRST_USE=1`, that follows a staged upload to the first recorded draw that declares its host texture and can be ordered after the upload. The trace then associates it with the first successful Present whose presentation-copy fence follows the draw. [Original finding in #2570](https://git.leonida.now/leonida/mandy/issues/2570#issuecomment-7646) The trace covers graphics preludes and the texture copy worker. For the copy queue it requires an observed completion before the graphics submission. A later graphics fence observation can complete an earlier Present's row. The row establishes declaration and queue order at host-texture granularity. The hardware readbacks below verify sampling at mip 0 after uploads through both queues. When a recent direct-memory storage write matches the complete staged input by range and bytes, the row can carry its run-local write ID. Rows contain run-local identifiers, relative times, queue, frame and fence values. ### Tested The hardware and CPU checks ran on 6b0498d37714. On current main 0036195a72f8, the production diff and the Rust sources, Cargo inputs, and synthetic hardware fixture used for validation are byte-for-byte identical. - Nine native DXGI Present runs passed with generated 8 x 8 textures and a synthetic swap chain. Three runs used synchronous presentation copies, three used presentation copies sent ahead, and three delayed the fence observed by the tracker. All sampled readbacks matched 64 of 64 RGBA pixels. - In both presentation-copy modes, the tracker linked graphics draw fence 4 to Present fence 5 and draw fence 7 after a copy-queue upload to Present fence 8. Present calls before those draws and duplicate Presents produced no new trace rows. - In the delayed case, DXGI accepted frame 21 with the graphics fence still at 3. After the test gate was released, frame 22 emitted one row with first_frame=21 and present_fence=5. - Nine CPU-only synthetic first-use tests passed. The copy-order regression failed in an isolated test variant with the readiness check removed and passed with the check in place. The repository clean-room, diff, and switch-catalog checks passed. - Separate hardware checks on the original candidate verified generated texture sampling in three graphics-prelude and three copy-queue runs, with zero-vertex controls preserving the clear color. GPUs tested: NVIDIA GeForce RTX 5070 Ti Laptop GPU, NVIDIA driver 621.47, Windows 11. AI-assisted: OpenAI Codex (GPT-6), independently reviewed with GPT-6.2 Sol. ### Checklist - [x] Based on current `main` and applies cleanly. - [x] One topic. - [x] No game data, keys or decryption.
Author
Contributor

Merged upstream main at f4b0404e95. The PR-only diff and the Rust/Cargo hardware-test inputs are byte-for-byte unchanged.

All nine synthetic CPU tests passed again on the updated tree. The previously reported nine native DXGI Present runs used the same Rust sources and test inputs. The clean-room, diff, and switch-catalog checks passed.

AI-assisted update with OpenAI Codex (GPT-6), independently reviewed with GPT-6.2 Sol.

Merged upstream main at f4b0404e95fa. The PR-only diff and the Rust/Cargo hardware-test inputs are byte-for-byte unchanged. All nine synthetic CPU tests passed again on the updated tree. The previously reported nine native DXGI Present runs used the same Rust sources and test inputs. The clean-room, diff, and switch-catalog checks passed. AI-assisted update with OpenAI Codex (GPT-6), independently reviewed with GPT-6.2 Sol.
Author
Contributor

Updated this branch from upstream main at 93b9d90a22c1 with a regular merge. The PR diff is byte-for-byte identical. The new head is 8f1ead9abdfd.

Nine synthetic CPU tests passed again on Windows. The Rust and Cargo inputs with the DXGI fixture match the earlier synthetic hardware-readback build. git diff --check, the switch catalogue check, and check_no_game_data.py passed. Earlier readback report

AI-assisted.

Updated this branch from upstream `main` at `93b9d90a22c1` with a regular merge. The PR diff is byte-for-byte identical. The new head is `8f1ead9abdfd`. Nine synthetic CPU tests passed again on Windows. The Rust and Cargo inputs with the DXGI fixture match the earlier synthetic hardware-readback build. `git diff --check`, the switch catalogue check, and `check_no_game_data.py` passed. [Earlier readback report](https://clearfieldswimming.com/leonida/mandy/pulls/3492#issuecomment-26644) AI-assisted.
First-time contributor

Test report from another machine (I changed no code). Not a review of the code.

  • Head 8f1ead9ab on main 93b9d90a2 (the head already contains it).
  • RTX 3060 Ti 8 GB, driver 610.88, Intel i7-13700KF, Windows 11, 32 GB RAM.
  • cargo test -p leonida-gpu --lib --locked -- --test-threads=1: 790 passed, 0 failed, 60 ignored.
  • cargo test -p leonida-hle --lib --locked -- --test-threads=1: 309 passed, 0 failed, 2 ignored.
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: exit 0.
  • With the feature the new module needs, cargo test -p leonida-gpu --lib --locked --features diagnostics -- --test-threads=1: 889 passed, 0 failed, 60 ignored. All nine texture_first_use::tests passed.
  • Without the feature the nine tests are not built, so the first count equals main's.
  • Not run: other crates, the real-card (--ignored) tests, clippy, the clean-room check, any in-game run.

GPUs tested: RTX 3060 Ti 8 GB, driver 610.88. No game files were used.

AI-assisted: yes (Claude Code, Claude Fable 5.2; verification only).

Test report from another machine (I changed no code). Not a review of the code. - Head `8f1ead9ab` on `main` `93b9d90a2` (the head already contains it). - RTX 3060 Ti 8 GB, driver 610.88, Intel i7-13700KF, Windows 11, 32 GB RAM. - `cargo test -p leonida-gpu --lib --locked -- --test-threads=1`: **790 passed, 0 failed**, 60 ignored. - `cargo test -p leonida-hle --lib --locked -- --test-threads=1`: **309 passed, 0 failed**, 2 ignored. - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`: exit 0. - With the feature the new module needs, `cargo test -p leonida-gpu --lib --locked --features diagnostics -- --test-threads=1`: **889 passed, 0 failed**, 60 ignored. All nine `texture_first_use::tests` passed. - Without the feature the nine tests are not built, so the first count equals `main`'s. - Not run: other crates, the real-card (`--ignored`) tests, clippy, the clean-room check, any in-game run. GPUs tested: RTX 3060 Ti 8 GB, driver 610.88. No game files were used. AI-assisted: yes (Claude Code, Claude Fable 5.2; verification only).
Author
Contributor

Updated this branch from upstream main at e1b0248c12ea with a regular merge. The added and removed lines of the PR are unchanged. Upstream added a separate synthetic test in descriptor/host.rs. The new head is 9bdccb84f004e.

The rebuilt Windows test executable passed all nine synthetic texture_first_use CPU tests. git diff --check and check_no_game_data.py passed. The earlier DXGI copy-queue readback refers to its previously tested hardware build. Earlier update

AI-assisted.

Updated this branch from upstream `main` at `e1b0248c12ea` with a regular merge. The added and removed lines of the PR are unchanged. Upstream added a separate synthetic test in `descriptor/host.rs`. The new head is `9bdccb84f004e`. The rebuilt Windows test executable passed all nine synthetic `texture_first_use` CPU tests. `git diff --check` and `check_no_game_data.py` passed. The earlier DXGI copy-queue readback refers to its previously tested hardware build. [Earlier update](https://clearfieldswimming.com/leonida/mandy/pulls/3492#issuecomment-26797) AI-assisted.
Author
Contributor

I reran the synthetic native DXGI Present fixture against the production tree of 9bdccb84f004e on base e1b0248c12ea. All 18 hardware runs passed across Intel Graphics and NVIDIA GeForce RTX 5070 Ti Laptop GPU, with 84 accepted native Presents in total.

The synchronous and asynchronous cases matched 64 out of 64 generated pixels for uploads on both the graphics and copy queues. The control before any draw emitted zero first-use rows. Later Presents emitted no duplicate rows.

All six delayed-fence runs preserved the first qualifying Present. In the generated sequence, frame 21 presented with fence 5 while the graphics fence had completed through 3 and the draw fence 4 was pending. After completion, the trace emitted one row during frame 22, retaining frame 21 and Present fence 5. The delayed case also matched all 64 generated pixels.

AI-assisted.

I reran the synthetic native DXGI Present fixture against the production tree of `9bdccb84f004e` on base `e1b0248c12ea`. All 18 hardware runs passed across Intel Graphics and NVIDIA GeForce RTX 5070 Ti Laptop GPU, with 84 accepted native Presents in total. The synchronous and asynchronous cases matched 64 out of 64 generated pixels for uploads on both the graphics and copy queues. The control before any draw emitted zero first-use rows. Later Presents emitted no duplicate rows. All six delayed-fence runs preserved the first qualifying Present. In the generated sequence, frame `21` presented with fence `5` while the graphics fence had completed through `3` and the draw fence `4` was pending. After completion, the trace emitted one row during frame `22`, retaining frame `21` and Present fence `5`. The delayed case also matched all 64 generated pixels. AI-assisted.
Sign in to join this conversation.
No description provided.