D3D12.X: reuse allocator, fence and staging buffer in title texture uploads #465
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!465
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/465/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@kxiserino on GitHub · 2026-11-24 00:38 UTC · original
kxiserino:perf/title-textures-batch-uploader→main· +353 −1 · 2 files · 2 commits · closed without mergingWhat is in it
gpu::texture::BatchUploaderincrates/xcl/src/gpu/texture.rsto reuse a per-deviceID3D12CommandAllocator,ID3D12GraphicsCommandList,ID3D12Fence, waitHANDLE, and a persistently-mapped upload staging buffer (capped at 64 MiB; larger one-off batches fall back to a temporary staging buffer).fence::waittimeouts so a laterupload_batchcall cannot overwrite staging or reset the command allocator while an earlier copy is still in flight; clear pending state and mark the uploader unusable on device removal.row_bytes == RowPitch, falling back to row-by-row copies otherwise.hle::d3d12x::title_textures::upload_allto keep oneBatchUploaderper device inUPLOADERSinstead of creating and destroying an allocator, command list, fence, event, and one upload buffer per texture on everyExecuteCommandListsrefresh.gpu_batch_uploader_reuses_staging_and_reports_partial_failuresandgpu_batch_uploader_retains_pending_batch_and_blocks_reuse_until_completionincrates/xcl/src/gpu/texture.rs.Tested
32.0.16.1714, wave32-only), DXC1.9.2609.5.cargo test -p xcl --lib gpu::texture -- --nocapture: 13 passed, 0 failed (includinggpu_batch_uploader_reuses_staging_and_reports_partial_failures,gpu_batch_uploader_retains_pending_batch_and_blocks_reuse_until_completion, andgpu_console_textures_upload_every_mip_and_sliceon the RTX 3090).cargo test -p xcl --lib title_textures -- --nocapture: 7 passed, 0 failed (includinggpu_mirror_upload_follows_cpu_writes_and_later_mapping_changesandplaced_title_textures_share_vram_and_preserve_pixelson the RTX 3090).cargo test --workspace -- --test-threads=4(lib, on base1152852): 636 passed, 1 failed (hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, pre-existing failure in this environment; confirmed passing on RDNA3 by reviewer), 21 ignored; 2 GPU tests reportedSKIPPED:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64andgpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.cargo test --workspace --test "*" -- --test-threads=4: 40 passed, 0 failed across all 12 integration test binaries.Regression run
Not tested
gpu_batch_uploader_retains_pending_batch_and_blocks_reuse_until_completion).hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memoryfailed in this environment (unrelated to this PR).AI use
@TheHoracio on GitHub · 2026-11-24 00:46 UTC · original
Test report on AMD RDNA3: RX 7800 XT (16 GB, wave32 and wave64), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used. The PR's own runs are all on NVIDIA, so this adds an AMD GPU with 64-lane waves.
Tested: the PR head
1152852as it is (on its base2997c9a).cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored, no SKIPPED tests (the twono wave64tests run here).gpu_batch_uploader_reuses_staging_and_reports_partial_failurespasses. So do the GPU tests named in the description (gpu_console_textures_upload_every_mip_and_slice,gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes,placed_title_textures_share_vram_and_preserve_pixels).xmem_virtual_query_marks_cpu_readable_memory, which failed in your environment, passes here.Not tested: a regression run on a title, a release build, the head merged onto current
main.AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.
@thehollowedone on GitHub · 2026-11-24 00:46 UTC · original
One upload-lifetime issue in 1152852. The fence helper can return a timeout with the submitted copy still pending. The caller logs the error and keeps the uploader cached. A later upload can then overwrite the staging buffer or reset the allocator before the previous copy has finished. Staging and allocator reuse · D3D12 allocator reset requirements
Could the uploader retain the submitted batch and gate reuse on confirmed fence completion, with device removal handled separately? A focused test could check that a timed-out batch keeps its staging allocation and blocks reuse until completion. I verified this path by reading the source and D3D12 contract. I did not induce a GPU timeout.
AI use
Codex with GPT-6.2 Sol traced the error path and drafted this review.
@kxiserino on GitHub · 2026-11-24 00:59 UTC · original
Good catch @thehollowedone! Fixed in
13aa0ac: BatchUploader now keeps a PendingBatch (fence target + any temporary staging buffer) across timeouts and checks inish_pending before touching staging or resetting the command allocator, while handling FenceError::Removed separately by releasing pending staging and marking the uploader removed. Added gpu_batch_uploader_retains_pending_batch_and_blocks_reuse_until_completion covering pending-batch retention across timeout and recovery once the fence completes, plus a fresh 30s smoke run.@grahamster2 on GitHub · 2026-11-24 01:10 UTC · original
Tested on an RTX 3080 against
mainand the two other PRs for the same fix (#451, #455). #465 doesn't change the intro video here: it plays at ~4.5 fps, the same asmain, and world streaming starts at 136–138 s instead of 140 s. There were no device removals.Setup: RTX 3080 10 GB, driver 610.88, 32 GB RAM with ~15–17 GB used by other programs. Release builds of
main2997c9a(code-identical toa6f5f7a) and of #4512cefc88, #455 07e6199 and #4651152852. Each PR was tested on its own. The retail title ran 180 s per run withXCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PRESS_A_AT=14,17,21on a warm cache. Numbers are from theactivity (2 s)lines; the earlier patch test ondb1ddb2is here.0x887a0006(DEVICE_HUNG), at 13.5 s and 11.0 s, before the intro video. The log line isD3D12 device removed: 0x887a0006 … – the title is stopped, and then the process ends with status 0x887a0006.mainand the other PRs had no removals in their runs.smoke.ps1, 60 s: it presses nothing, so every build stays on the menu, and all four look the same there.2997c9a2cefc881152852All smoke runs reported
exit: 0x0andgpu: NVIDIA GeForce RTX 3080. I left the title line out of the table.Not tested:
The same numbers are posted on the other PRs: #451, #455.
Test runs and this report: Claude Code (Claude Opus 5.5).
@kxiserino on GitHub · 2026-11-24 02:49 UTC · original
Closing as superseded by merged #451 and #602, which already reuse upload memory and detile/hash in place.
@fladit123 on GitHub · 2026-11-25 18:04 UTC · original
I noticed that #465 included a contiguous staging copy for tightly packed texture subresources, but this specific optimization does not appear to be present in current main.
Would you be open to revisiting that isolated change, with credit to the original implementation?
I would benchmark actual D3D12 upload memory on an RTX 4060, use WARP as an additional correctness control, and proceed only if the improvement is repeatable, with byte-exact GPU readback and no regression for padded layouts.
No runtime changes have been made yet.
Pull request closed