Skip to content

Memory: new sparse tiles are mapped together before the next submit - #1517

Draft
oishigeso wants to merge 1 commit into
xcl-dev:mainfrom
oishigeso:sparse-batch
Draft

oishigeso wants to merge 1 commit into
xcl-dev:mainfrom
oishigeso:sparse-batch

Conversation

@oishigeso

Copy link
Copy Markdown

Follows 7f94c6f (#532), which parks decommitted tiles; this does the same for new ones. A title starting on a Series S profile maps 4.3 GB of physical pages in small pieces (MapTitlePhysicalPages → sparse::committed), and each new tile cost one UpdateTileMappings plus a signal (~0.4 ms on this PC). Its loading thread was held ~25 s with nothing presented, and its stall watchdog ended it. Related: #1268 (the first UpdateTileMappings calls holding the render thread).

New tiles now get their pool tile in mapped at once, and their mapping call is queued (pending). flush_pending sends them, one call per window, before the title's next submit, before XCL's own copies and readbacks on the windows, or past 4,096 tiles. A tile decommitted before the flush is skipped. One decommitted and parked before its mapping was sent stays pending, because taking it back from parked sends no mapping.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: pending, flush_pending, called from before_execute, the upload and readback paths, and commit_range past PENDING_MAX; the existing parking test extended to commit, decommit, flush and commit again

Tested

  • AMD Radeon RX 6700 XT (driver 32.0.21030.2001), Ryzen 5 3600, Windows 10 Pro 19045, rustc 1.100.0, release
  • cargo test -p xcl --lib sparse -- --test-threads=1: 16 passed, 0 failed, 1 ignored
  • Written and run before Memory: decommitted sparse tiles stay mapped until the next submit #532 merged in about 10 runs of a retail title on the Series S profile; the ~25 s hold at start was gone. Rebased onto 7f94c6f since; the combination was reviewed against the parking, which found the parked-before-flush case above (now in the test).
  • The regression runs below are on the Series S profile: 1,319 frames in 60 s against 373 on main, presenting every 2 s window at the end.

Regression run

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: AMD Radeon RX 6700 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 373 (PresentX 374)
presents per 2 s (last 3): 0 28 60
device removals: 0
crashes: 0
peak commit: 19259 MB

PR (this PR's head commit; the title is run through a folder named RetailTitle):

xcl-smoke v1
commit: b52f7cb67236473c8a4d9a07eabaf01694d72de0
gpu: AMD Radeon RX 6700 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1319 (PresentX 1320)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19347 MB

Not tested

  • NVIDIA, Intel; Linux / Wine

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, its test and this description, and ran the tests and runs above on my PC at my direction.

🤖 Generated with Claude Code

A title starting on a Series S profile maps 4.3 GB of physical pages in
small pieces (MapTitlePhysicalPages -> sparse::committed), and each new
tile cost one UpdateTileMappings + signal (~0.4 ms). Its loading thread
was held ~25 s with nothing presented and its stall watchdog ended it.

New tiles now get their pool tile in `mapped` at once and their mapping
call is queued (`pending`); `flush_pending` sends them, one call per
window, before the title's next submit, before XCL's own copies and
readbacks on the windows, or past 4,096 tiles. A tile decommitted
before the flush is skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@fladit123 fladit123 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent validation on RTX 4060 confirms the substantial potential of batching, but I found a threshold-related performance regression that should be addressed before merging.

Results

Tested against base 930e8b4 and PR HEAD b52f7cb67236473c8a4d9a07eabaf01694d72de0.

Synthetic workload Baseline PR
4,096 individual commits: UpdateTileMappings calls 4,096 4
Median elapsed time through mapping fence 750.89 ms 1.24 ms
Parked-address stress case 3.47 ms 4.26 ms

Finding

commit_range triggers flush_pending() when pending.len() >= PENDING_MAX.

However, flush_pending() retains parked addresses whose mappings have not yet been submitted. These entries continue contributing to the threshold even though they are not ready to be mapped.

With 4,095 such parked addresses, the next 32 commits triggered 32 early flushes, examining 135,167 entries including the final flush.

This effectively defeats batching in that workload and increased median elapsed time by approximately 22.8%.

I recommend tracking only unique, currently eligible mappings toward the flush threshold while preserving the necessary pending state for parked addresses that are subsequently recommitted.

A regression test covering this parked-address workload would be valuable.

Rebase considerations

Current main also has fence-based tile quarantine and per-title-queue synchronization. Please preserve these guarantees when resolving the conflicts in sparse.rs.

Correctness validation

  • 14 targeted tests passed on each revision, with one ignored per revision.
  • Additional integrity fixture verified nine sentinels, remapping to a different slot, and reading from a second queue.
  • No D3D12 validation errors or warnings, and no device removal in the additional fixture.
  • Final measurements used separate build targets and verified executable hashes.

The measurements cover synthetic mapping through fence completion, not game FPS or frame times. Integration with current main has not been validated.

The batching approach looks promising. My

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants