[pr-performance][rendering][memory] Refresh only written mips of tracked BC textures #50

Open
holoslicer wants to merge 1 commit from holoslicer/Darner:perf-streamed-texture-mips into main
Contributor

Contributor role (optional)

What it changes

Streaming a single mip could make Darner read, detile and upload an entire block-compressed texture. For a fully staged, single-slice 2D BC texture in verified write-watched memory, this change maps written pages to mip levels. It refreshes those levels on the CPU and accumulates them for the GPU upload at submission.

Initial uploads, remaps and writes into a packed mip tail use a full refresh. If two live staging buffers can overwrite the same GPU texture, each submits its full staged image.

How it was tested

Windows x64, Rust 1.98.1. Published commit 0973b6e4aa has the same Git tree as tested commit bc4e62f540. Both have upstream parent 4a92569fb8.

  • In a synthetic 2048 × 2048 BC7 texture, changing the 256 × 256 mip reduced source reads from 5,636,096 to 65,536 bytes and selected one of 12 mips for upload. Every row in all 12 GPU mips matched an independent full refresh. The regression also writes a marker to an unchanged staging mip to catch an accidental CPU refresh or GPU copy.
  • Both focused mip tests passed, including the page-boundary and packed-tail cases. The workspace GPU test suite passed 1,707 tests with 79 ignored. Both workspace Clippy configurations passed with warnings denied, and the asset policy passed across 544 files.
  • The full workspace run (cargo --config 'profile.test.package.darner-shader.opt-level=3' test --workspace --locked --offline --no-fail-fast -- --test-threads=1) finished with 3,234 passed, two failed and 117 ignored. Both failures also reproduced on unmodified upstream: DXIL depth-output validation and the expected 32-lane wave size. In-game frame times and texture pop-in still need a matched route.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • This change has no PR dependencies.

Checked for overlap

  • Searched the new forge's issues and PRs and checked the changed files in its open PRs. No competing partial-mip upload was found. PR #8 controls sampler LOD bias and #11 controls streaming-heap size. The following PRs also touch host.rs for other changes: #25, #31, #32, #33, #34, #35, #38, #39, #40, #41 and #43.
## Contributor role (optional) <!-- Fluxer ID omitted. --> ## What it changes Streaming a single mip could make Darner read, detile and upload an entire block-compressed texture. For a fully staged, single-slice 2D BC texture in verified write-watched memory, this change maps written pages to mip levels. It refreshes those levels on the CPU and accumulates them for the GPU upload at submission. Initial uploads, remaps and writes into a packed mip tail use a full refresh. If two live staging buffers can overwrite the same GPU texture, each submits its full staged image. ## How it was tested Windows x64, Rust 1.98.1. Published commit `0973b6e4aa` has the same Git tree as tested commit `bc4e62f540`. Both have upstream parent `4a92569fb8`. - In a synthetic 2048 × 2048 BC7 texture, changing the 256 × 256 mip reduced source reads from 5,636,096 to 65,536 bytes and selected one of 12 mips for upload. Every row in all 12 GPU mips matched an independent full refresh. The regression also writes a marker to an unchanged staging mip to catch an accidental CPU refresh or GPU copy. - Both focused mip tests passed, including the page-boundary and packed-tail cases. The workspace GPU test suite passed 1,707 tests with 79 ignored. Both workspace Clippy configurations passed with warnings denied, and the asset policy passed across 544 files. - The full workspace run (`cargo --config 'profile.test.package.darner-shader.opt-level=3' test --workspace --locked --offline --no-fail-fast -- --test-threads=1`) finished with 3,234 passed, two failed and 117 ignored. Both failures also reproduced on unmodified upstream: DXIL depth-output validation and the expected 32-lane wave size. In-game frame times and texture pop-in still need a matched route. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] This change has no PR dependencies. ## Checked for overlap - [x] Searched the new forge's issues and PRs and checked the changed files in its open PRs. No competing partial-mip upload was found. PR #8 controls sampler LOD bias and #11 controls streaming-heap size. The following PRs also touch `host.rs` for other changes: #25, #31, #32, #33, #34, #35, #38, #39, #40, #41 and #43.
Contributor

Independent Windows D3D12 check on an RTX 4060 8 GB (driver 621.40, Windows 11 build 26300, Rust 1.98.1).

At 0973b6e4aa, cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib texture::mip_upload_tests:: -- --test-threads=1 --nocapture passed 2/2. I also applied this PR to 1a5286a78daa and extended the BC7 test to dirty mip 3, refresh, dirty mip 2, refresh, then submit once. The D3D12 device LUID matched the RTX 4060. The two refreshes read 65,536 and 262,144 bytes from a 5,636,096-byte source. The submission selected both mips, every row in all 12 mips matched a full CPU detile, and the marker in the untouched staging mip stayed out of the GPU readback.

This synthetic run covers pending mip accumulation and copies. Gameplay, frame times, and issue #68's black blocks are outside its scope.

Independent Windows D3D12 check on an RTX 4060 8 GB (driver 621.40, Windows 11 build 26300, Rust 1.98.1). At `0973b6e4aa`, `cargo --config 'profile.test.debug=0' test --locked -p darner-gpu --lib texture::mip_upload_tests:: -- --test-threads=1 --nocapture` passed 2/2. I also applied this PR to `1a5286a78daa` and extended the BC7 test to dirty mip 3, refresh, dirty mip 2, refresh, then submit once. The D3D12 device LUID matched the RTX 4060. The two refreshes read 65,536 and 262,144 bytes from a 5,636,096-byte source. The submission selected both mips, every row in all 12 mips matched a full CPU detile, and the marker in the untouched staging mip stayed out of the GPU readback. This synthetic run covers pending mip accumulation and copies. Gameplay, frame times, and issue #68's black blocks are outside its scope.
Contributor

Follow-up on a stale mip after a late upload-ahead completion. I reproduced it at 0973b6e4aa on an RTX 4060 8 GB (Windows 11 build 26300, driver 621.40, Rust 1.98.1).

With DARNER_UPLOAD_AHEAD=1 and DARNER_PRELUDE_UPLOADS=1, the test sends a synthetic 2048×2048 BC7 chain through the real COPY worker and waits for its D3D12 fence. It delays only the CPU call to ahead::finish. An ordinary upload_from times out in listed after ~1.05 s and its prelude uploads the chain. The test then changes mip 3, refreshes staging, and releases ahead::finish before the next prelude claims that update.

  • On the PR, uploads.copied() clears the pending mip 3. A subsequent write to mip 2 submits only mip 2. GPU readback still has 0x1b in mip 3 (expected 0xb7).
  • At current main (1a5286a78daa), the same sequence also loses the first update. The later write triggers a full upload and restores mip 3 to 0xb7.
  • On current main with this PR and a local guard, both uploads are recorded (masks 0x8 and 0x4). GPU readback gets 0xb7 for mip 3 and 0x4d for mip 2. The guard checks staging.once while holding staging.last and only clears pending uploads and records the held hash while the staging buffer still belongs to the one-shot upload. An ordinary list sets once=false before its refresh, which uses that same lock.

The test forces the CPU completion order after the COPY fence has signaled. Concurrent GPU writes across the COPY and DIRECT queues, in-game frequency, and a gameplay symptom are outside the scope of this reproduction.

Follow-up on a stale mip after a late upload-ahead completion. I reproduced it at `0973b6e4aa` on an RTX 4060 8 GB (Windows 11 build 26300, driver 621.40, Rust 1.98.1). With `DARNER_UPLOAD_AHEAD=1` and `DARNER_PRELUDE_UPLOADS=1`, the test sends a synthetic 2048×2048 BC7 chain through the real COPY worker and waits for its D3D12 fence. It delays only the CPU call to `ahead::finish`. An ordinary `upload_from` times out in `listed` after ~1.05 s and its prelude uploads the chain. The test then changes mip 3, refreshes staging, and releases `ahead::finish` before the next prelude claims that update. - On the PR, `uploads.copied()` clears the pending mip 3. A subsequent write to mip 2 submits only mip 2. GPU readback still has `0x1b` in mip 3 (expected `0xb7`). - At current `main` (`1a5286a78daa`), the same sequence also loses the first update. The later write triggers a full upload and restores mip 3 to `0xb7`. - On current `main` with this PR and a local guard, both uploads are recorded (masks `0x8` and `0x4`). GPU readback gets `0xb7` for mip 3 and `0x4d` for mip 2. The guard checks `staging.once` while holding `staging.last` and only clears pending uploads and records the held hash while the staging buffer still belongs to the one-shot upload. An ordinary list sets `once=false` before its refresh, which uses that same lock. The test forces the CPU completion order after the COPY fence has signaled. Concurrent GPU writes across the COPY and DIRECT queues, in-game frequency, and a gameplay symptom are outside the scope of this reproduction.
This pull request can be merged automatically.
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 'perf-streamed-texture-mips:holoslicer-perf-streamed-texture-mips'
git switch 'holoslicer-perf-streamed-texture-mips'

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 'holoslicer-perf-streamed-texture-mips'
git switch 'holoslicer-perf-streamed-texture-mips'
git rebase 'main'
git switch 'main'
git merge --ff-only 'holoslicer-perf-streamed-texture-mips'
git switch 'holoslicer-perf-streamed-texture-mips'
git rebase 'main'
git switch 'main'
git merge --no-ff 'holoslicer-perf-streamed-texture-mips'
git switch 'main'
git merge --squash 'holoslicer-perf-streamed-texture-mips'
git switch 'main'
git merge --ff-only 'holoslicer-perf-streamed-texture-mips'
git switch 'main'
git merge 'holoslicer-perf-streamed-texture-mips'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!50
No description provided.