Skip to content

Memory: serialize sparse commits and decommits with uploads - #236

Open
utkarshxdev wants to merge 1 commit into
xcl-dev:mainfrom
utkarshxdev:intro-render-fixes-latest
Open

utkarshxdev wants to merge 1 commit into
xcl-dev:mainfrom
utkarshxdev:intro-render-fixes-latest

Conversation

@utkarshxdev

@utkarshxdev utkarshxdev commented Nov 23, 2026 •

Copy link
Copy Markdown

Serialize sparse CPU page updates with the upload scan. Previously, the scan could read a page while Windows was decommitting it, or a delayed commit record could mark a decommitted page live again.

What is in it

  • Sparse host commits, decommits, and GPU bookkeeping share STATE. A sparse release returns the reservation to the allocator after successful decommit.
  • Fixed-address VirtualAlloc in sparse windows requires MEM_COMMIT and a range within one live reservation. Non-commit calls, including MEM_RESET and MEM_RESET_UNDO, return null and ERROR_INVALID_ADDRESS. This changes the previous host passthrough.
  • CPU-only Windows regression tests cover reset rejection and upload/decommit ordering. The race test checks page accessibility with VirtualQuery before attempting a read.

Tested

  • macOS arm64 cross-check at the revised head: cargo check --locked --target x86_64-pc-windows-msvc --offline --all-targets passed, with one existing deprecation warning.
  • The extracted race test passed on macOS with Win32 memory calls modeled. Moving the host decommit before the lock produced the expected assertion failure.
  • Historical Windows GPU suite on the earlier revision 03d4a86 merged into 0e946cf: Ryzen 5 5600G, RX 7800 XT driver 32.0.32029.2010, Windows 11 26300, Rust 1.100.0 MSVC. cargo test --workspace -- --test-threads=4 reported 655 passed, 0 failed, 40 ignored, and no skips.
  • Windows CI for the revised head requires upstream workflow approval. No test jobs have run.

Regression run

Historical A/B runs from the earlier revision. The display adapter is named in the output. XCL ran on the RX 7800 XT.

Main baseline

xcl-smoke v1
commit: 0e946cfc68244edee1fba6e0425371f687a05ccd
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 1216 (PresentX 1216)
presents per 2 s (last 3): 26 25 26
device removals: 0
crashes: 0
peak commit: 17191 MB

Earlier PR revision merged locally

xcl-smoke v1
commit: 81d72e456615e6d5c98bd433caf8f343d0d1d40e
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 1194 (PresentX 1194)
presents per 2 s (last 3): 18 19 18
device removals: 0
crashes: 0
peak commit: 17173 MB

Not tested

  • The revised head still needs the full suite on a Windows GPU and a fresh xcl-smoke pair. The historical retail run did not exercise the sparse VirtualAlloc commit path.

AI use

  • OpenAI Codex, GPT-6 (exact runtime variant unavailable), implemented the review changes and tests, ran verification, and updated this description.

@srcamarda

Copy link
Copy Markdown
Contributor

AMD run of 03d4a86 merged onto main 0e946cf (clean merge), with a retail title, plus a few points from reading the diff.

Tested

  • RX 7800 XT (RDNA3, driver 32.0.32029.2010), Ryzen 5 5600G, 32 GB, Windows 11 26300, Rust 1.100.0 MSVC
  • The PR's tests pass (command_list_slots_include_131_and_132, intro_sparse_reservation_matches_the_observed_request, sparse_commit_rejects_invalid_ranges, the early-commit ones)
  • cargo test --workspace -- --test-threads=4: 655 passed, 0 failed, 40 ignored, no SKIPPED
  • scripts/smoke.ps1, 90 s, six runs of each binary (two batches of three, each starting with a cold translation cache): main 738 / 1 100 / 892 / 1 035 / 1 216 / 1 134 frames, this PR 1 052 / 1 026 / 947 / 948 / 1 194 / 976. Mean ~1 020 for both; no crash or device removal; the same peak commit (~17.2 GB).

What the title does with it

  • #131 and Add synthetic Cargo benchmark suite #132 are called once each early in loading. The PR's log lines:
    D3D12.X: ID3D12GraphicsCommandList #132 (0x75d42a70, 0x700000, 0x0, 0x0)
    D3D12.X: ID3D12GraphicsCommandList #131 (0x75d42a70, 0xc3c0, 0x80020000, 0x0)
    
    On main the same calls already reach the guard's stub (ID3D12GraphicsCommandList10::#131 (not on PC), 4 + 3 calls; Add synthetic Cargo benchmark suite #132 4 + 1), which returns 0 as well. So on this title the new handlers change nothing but the log, and main does not crash there. Which title or build showed the null-vtable crash?
  • The intro pool reservation never fires here. With XCL_TRACE_MEM, the title's reservations in 90 s are these, and none is 0x1_3800_0000 with plain MEM_RESERVE / PAGE_NOACCESS; every one carries extra flag bits:
    VirtualAlloc(0x0, 0x600000000, flags 0x20402000, protect 0x4)
    VirtualAlloc(0x0, 0x600000000, flags 0x20402000, protect 0x801)
    VirtualAlloc(0x0, 0x49400000, flags 0x20003000, protect 0x22004)
    VirtualAlloc(0x0, 0x89700000, flags 0x20003000, protect 0x2404)
    VirtualAlloc(0x0, 0x23300000, flags 0x20003000, protect 0x22004)
    VirtualAlloc(0x0, 0x25400000, flags 0x20003000, protect 0x22004)
    VirtualAlloc(0x0, 0x185c00000, flags 0x20402000, protect 0x2004)
    
    (plus three 64K-page / coherent-window ones and the placeholders). No VirtualAlloc (sparse commit) line either, so the reworked commit path is not reached by this title. A different build of the game?

Points from reading the diff

  1. An unannounced behaviour change in VirtualAlloc: on main a call on an address in a sparse window without MEM_COMMIT (e.g. MEM_RESET / MEM_RESET_UNDO) goes on to the normal path. With this PR it now fails with ERROR_INVALID_ADDRESS. Intended? It isn't in the description and has no test.
  2. Scope: three unrelated changes (list slots, sparse commit locking, the intro pool). CONTRIBUTING asks for one per PR, and the description needs Tested with the suite counts and the two xcl-smoke blocks for PR checks.

Regression run (gpu: names a virtual display adapter here, but XCL ran on the RX 7800 XT). The second run of the second batch for each:

main:

xcl-smoke v1
commit: 0e946cfc68244edee1fba6e0425371f687a05ccd
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 1216 (PresentX 1216)
presents per 2 s (last 3): 26 25 26
device removals: 0
crashes: 0
peak commit: 17191 MB

this PR merged onto main (local merge commit):

xcl-smoke v1
commit: 22db4c62b726dee1fb28a1ddba55d3a3b67378ec
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 1194 (PresentX 1194)
presents per 2 s (last 3): 18 19 18
device removals: 0
crashes: 0
peak commit: 17173 MB

Not tested

  • The intro pool path and the new sparse commit path (this title reaches neither), whether it hits the new ERROR_INVALID_ADDRESS path, the PR on its own, NVIDIA.

AI use

  • Claude Code with Claude Opus 5.5: ran the tests and the smoke runs, read the logs, the memory trace and the diff, wrote this report.

@ryosen0

ryosen0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Test report on our machine with this PR's head (03d4a86) stacked on current main (db1ddb2) + #300 + #294 + #273 + #304: Ryzen 7 9800X3D, RTX 3060 Ti 8 GB (wave32), driver 32.0.16.1742, Windows 11.

XCL_NETWORK=0 XCL_RUN_SECONDS=240 XCL_ACTIVITY=1 xcl run <retail folder>: clean exit at the timer, 3987 frames shown, no crash, no device removal. Intro stretch ~t=60-165 s at 4.9-6.4 fps, then a steady 30.0 fps to the end; the character loading screen is reached. BCPack refusals in the same run: BC5 44, BC7 20 requests (BC1 unpacked). The 41 console-MS-in-AS-slot refusals are unchanged.

The same run without this PR (main + #300 + #294 + #273 + #304, 180 s): the same shape - dip 4.4-8.6 fps at t=44-166 s, 29.9 fps after. So on this hardware the PR neither helped nor hurt the intro pace measurably; the slow stretch looks bounded by something else (we see 6.5 GB local + 4.6 GB non-local video memory on the 8 GB card during it).

Not tested: the command-list slots 131/132 paths in isolation; no unit-test run for this report (run-only data point).

AI use: GPT-6.2 Astra (API model selector) ran the builds and runs and wrote this report; the human contributor watched the screen and reviewed it.

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and thanks @srcamarda and @ryosen0 for the runs. Not merged yet - what would get it in, in this PR:

  1. Drop the intro pool reservation. It is keyed to the title's executable name, and fixes here have to model the console for any title, not one game (the repository also does not name the game). srcamarda's memory trace shows the title never makes a plain MEM_RESERVE / PAGE_NOACCESS reservation of 0x1_3800_0000, so the path never runs; if a real reservation needs to be in the sparse windows, the rule should come from what the reservation is (its flags / protection), not who makes it.
  2. The command-list slots #131 / Add synthetic Cargo benchmark suite #132: on main these calls already reach the guard's stub, which returns 0 too, so the new handlers only change the log, and no run showed the null-vtable crash they are meant to prevent. Either drop them, or say which title/build crashed there and with what log.
  3. The sparse commit / decommit under STATE.lock() is the part worth having. Two things for it: say in the description (and cover with a test) the behaviour change srcamarda found - VirtualAlloc without MEM_COMMIT (MEM_RESET / MEM_RESET_UNDO) on an address in a sparse window now fails with ERROR_INVALID_ADDRESS instead of taking the normal path; and add a test that shows the race it closes (the upload scan reading a page mid-decommit), failing without the change.

The two A/B runs above found no difference on a retail title either way, so with 1 and 2 gone and 3 tested this is a small, safe change. Please keep Tested (suite counts) and the xcl-smoke pair in the description.

Keep host page transitions and sparse tile state under the same lock. Cover fixed-address bounds, reset rejection, and the upload/decommit ordering regression.

Assisted-by: OpenAI Codex (GPT-6)
@utkarshxdev
utkarshxdev force-pushed the intro-render-fixes-latest branch from 81d72e4 to 4913af0 Compare November 24, 2026 16:09
@utkarshxdev

Copy link
Copy Markdown
Author

Hey @ivall, thanks for the guidance!

I've rebased on latest main and addressed all three review items:

  1. Dropped the intro pool reservation entirely.
  2. Dropped command-list slots #131 / Add synthetic Cargo benchmark suite #132 to keep this PR strictly focused on memory serialization.
  3. Documented and tested VirtualAlloc non-commit rejection (ERROR_INVALID_ADDRESS), and added the regression test for the upload scan / decommit ordering race.

Branch is clean and rebased with zero conflicts. Ready for workflow approval and review whenever you're free!

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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.

6 participants