Skip to content

perf(gpu): detile and upload only touched rows on tracked texture writes - #416

Open
gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-dirty-row-texture-upload
Open

gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-dirty-row-texture-upload

Conversation

@gdemontalivet

Copy link
Copy Markdown
Contributor

Summary

  • Extends victory-formats tiled row walking (including paired-row walk_runs odd-start handling) to detile only the row range touched by dirty 64 KiB pages of a tracked texture mip.
  • Uploads only the touched block-row aligned D3D12_BOX bands via CopyTextureRegion (VICTORY_DIRTY_ROWS=1 default, 0 opts out for A/B testing).
  • Excludes subresources overlapping untracked pages so mixed tracked+untracked mips cannot leave stale rows, and requeues taken pages via Tracked::retry on failed staging allocation/detile.

Measured M5 Max (CrossOver / D3DMetal) Impact

  • Synthetic 4K BC7 single-page detile benchmark: 945.1 µs → 47.2 µs (20.0× faster, 16× less tiled memory read).
  • Matched frozen-cache M5 Max warm A/B (sync path): median frame time 844.2 ms → 664.5 ms (-21.3%), CPU prep 370.9 ms → 244.1 ms (-34.2%), submit-thread textures 48.0 ms → 29.1 ms (-39.4%), GPU time 107.5 ms → 95.8 ms (-10.9%).

Verification

  • cargo xtask policy: pass
  • cargo test -p victory-formats: 55 passed
  • Wine + D3DMetal (texture::, tracked_rows::, single-page upload): 17/17 passed
  • cargo clippy --target x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings (default & --features diagnostics): 0 warnings

Port dirty-row partial texture detiling and upload so a tracked write
into a subresource that owns a changed page reads, detiles, and copies
only the affected element-row band through a block-aligned D3D12_BOX
instead of re-reading and detiling the entire mip:

- victory-formats: add Layout::touched_rows and Layout::detile_rows,
  extending the paired-row walk_runs loop to support arbitrary
  (including odd-starting) row ranges without breaking row-pair
  alignment.
- victory-gpu (watch): add Tracked::retry to requeue taken pages when
  staging allocation or detiling fails so dirty updates are never
  dropped.
- victory-gpu (texture): plan per-subresource row bands on tracked
  writes (with VICTORY_DIRTY_ROWS=0 opt-out for A/B testing), exclude
  subresources overlapping untracked memory from partial-row skipping so
  ordinary-memory rows never go stale, scale block-compressed D3D12_BOX
  row bounds by block size, and requeue failed uploads via Tracked::retry.
- Add format parity/timing tests and D3D12/D3DMetal GPU tests covering
  partial RGBA8 and BC1/BC7 row uploads, mixed tracked+untracked mips,
  and deferred staging retry.
@evan-kolberg

Copy link
Copy Markdown
Contributor

An M4 Pro follow-up to the single-page result. I used gdemontalivet’s exact #416 revision to compare the current single row band with a prototype that plans each contiguous dirty range and merges touching row bands. Two native release runs, 24 samples per mode, with byte-exact output against a full detile in every sample.

  • 4K BC7, four clustered pages: the current one-band path read 1 MiB in 48–51 µs (median range across runs).
  • Same BC7, four scattered pages: one band read 16 MiB in 833–977 µs. Separate bands read 4 MiB in 195–208 µs. 2K RGBA8 showed the same 16→4 MiB change.
  • Sixteen scattered pages: both plans read the full 16 MiB, and the per-range planning was slower.

This measures resident-memory copying, planning and the real detile function. GPU upload cost and gameplay pacing are separate measurements.

Prepared and tested with Codex.

@earpjonathan

earpjonathan commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Correction: this PR is not the cause. More runs show the dark first indoor area and grey, ashen skin come and go with the host pipeline library. The dark runs, with or without this PR, each had 35 to 42 frames that dropped work while about 2,000 pipelines were still being made after the library was replaced. The lit runs had 1 to 3. Switching between builds is what emptied the library in my comparison, so the earlier result here was an artifact of how I tested, and I'm sorry for the noise.

The likely mechanism: one-time setup work at the start of the scene, probably the lighting, gets dropped because its pipeline isn't ready yet, and the scene stays wrong afterwards. I'll test this PR again with a warm library.

Prepared with Claude Code.


Original comment, kept for the record:

In-game check on an M5 Pro (macOS 27.0.1, CrossOver 26.3 Wine with the repo's current patches, D3DMetal 4.0 beta 3, Series X). Runs with the same opening and scripted input, on main at bf99e72 plus #401, #435, #433, #439 and #419, with and without this PR.

Happy to run a debug switch or extra logging if that helps narrow it down.

Prepared with Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants