Repository navigation
runtime: an Xbox page mapper on Vulkan sparse binding (not wired yet) - #5378
maxxgabriel wants to merge 9 commits into
Conversation
|
Destroying a mapped I mapped one 64 KiB page, waited for the bind to complete, destroyed the region, released the page, and called
Expected: both paths free the chunk. The region destructor destroys the sparse buffer. The pool still counts its mapping. This prevents the pool from returning the chunk to Vulkan during its lifetime. Please account for outstanding mappings when the region closes. Keep the completed-ticket check for GPU work. To reproduce, insert this block immediately before for (bool clear : {true, false}) {
std::vector<PageId> one;
EXPECT(pool.allocate(1, one));
{
PagedRegion temporary;
EXPECT(temporary.create(d.device, d.device_proc, kPageSize));
PageMapper m(temporary, pool);
const auto handle1 = m.register_page_pool(one);
const PageMappingRange range{PageRangeType::incrementing, 1, 0};
const PageMappingBatch batch{0, &range, 1};
EXPECT(m.copy_page_mappings_batch(handle1, {&batch, 1}, submit));
if (clear) EXPECT(m.clear_page_mappings(0, 1, submit));
gpu.wait_queue(queue.submitted_ticket());
EXPECT(m.unregister_page_pool(handle1));
}
pool.release(one);
const auto freed1 = pool.trim(queue.completed_ticket());
std::printf("region destroyed: clear=%d used=%llu freed=%llu reserved=%llu\n",
int(clear), (unsigned long long)pool.pages_in_use(), (unsigned long long)freed1,
(unsigned long long)pool.bytes_reserved());
EXPECT(freed1 == kChunkSize);
}Build with The unchanged paging, queue, sparse queue family, and Vulkan device tests pass with each adapter selected. AI-assisted. |
…gs, lock the queue in bind_sparse_ordered
|
Tested The path that reproduced the leak for @shdann — destroy the region while the page is still mapped, release, With For the record, the bind timings on this card (median of 15): 1024 pages contiguous 1 bind 2.761 ms (2.70 us/page), 1024 scattered 1024 binds 6.928 ms (6.77 us/page); the queued-work gap is 0.007 ms without a remap and 1.445 ms with a 64-page scattered remap, with the remap call returning on the CPU in 0.085 ms while W1 is still running. I did not run the pre-fix AI-assisted. No game data. |
|
Tested 6571ec5 natively on Windows 11 Pro 26200 (MSVC 14.44.35207, Vulkan SDK 1.4.363.0), merged onto
No game files. AI-assisted (Claude Code). |
… or empty arena, and an empty submit
|
@timbot103 thanks. can you also comment the bind timings of your cards ? |
Kam471
left a comment
There was a problem hiding this comment.
Reviewed head 6571ec5533.
Build (vcvars64 + Ninja + Vulkan 1.4.363, RelWithDebInfo):
cmake -S runtime -B build ... then cmake --build build --target vk_xbox_paging_test d3d12_buffer_tiles_test
.\build\vk_xbox_paging_test.exe-> PASS. 181 calls / 181 submits / 20144 binds / 71082 pages; 1024-page contiguous bind 1.06 ms, scattered 4.31 ms; remap gap 0.005 ms without / 0.61 ms with; trim frees 128 MiB; both region-destroy cases free 64 MiB, 0 reserved..\build\d3d12_buffer_tiles_test.exe-> PASS (12 tiles across aliased/skipped/reused/remapped; rejected update intact), so the refactoredbind_tilespath still works.
Inertness confirmed: xbox_paging.h is included only by its test; runtime/CMakeLists.txt adds only a test executable; bind_sparse_ordered has no production caller (only xbox_paging.h and the test). bind_sparse_ordered/submitted_ticket take state_mutex_; completed_ticket calls the semaphore counter, no shared state.
Verdict: LGTM. #5381 builds on this branch.
|
Tested 6571ec5 (base 3faac55, no other PRs) on NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 560.94, Windows 10 Enterprise LTSC 21H2 (19044), MSVC 14.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363, RelWithDebInfo + Ninja: pass. A Pascal / Windows 10 data point next to the 1660 SUPER, 3070, 4090, 5080 and the AMD iGPUs. Synthetic only, no game files. vk_xbox_paging_test: PASS with no skip (sparseAddressSpaceSize 1 TiB, residencyNonResidentStrict true), twice without and twice with LEONIDA_VK_VALIDATION=1 ("validation errors: 0", no VUIDs). Arena 64 GiB, page memory type 7 (device-local), 5 remaps read back in order, aliasing 0xc0ffee00, cleared page 0x00000000/0x00000000, both "region destroyed" paths end with 0 bytes still reserved. Timings: 1 page 0.33 ms, 256 contiguous 0.19 ms; W1→W2 gap 0.011 ms without a remap, 0.695 ms with a 64-page scattered remap. vk_queue_test and d3d12_sparse_queue_family_test: exit 0, the same as main 3faac55. d3d12_vulkan_device_test exits 1 at lines 172 and 6790 both here and on main 3faac55 on this GPU (TEST-995, fixed by #4682), so not from this PR. Negative control for the leak @shdann reported: 04ef583's test against 620413c's runtime/src/xbox_paging.h (vulkan_backend.h is identical in the two) fails at vk_xbox_paging_test.cpp:456 How: test executables run directly (not ctest). AI-assisted (Claude Code). |
|
Bind timings from
Queued-work test (median of 9):
Contiguous binds cost about the same on both cards. Scattered binds cost about 4x more per page on AMD's driver at 256 pages, and about 5x more at 1,024. The Radeon is the Ryzen 9000's 2-CU iGPU, so its W1 figure says nothing about a desktop RDNA2 card, but the bind costs are the driver's. The 6571ec5 run gave the same picture (1,024 scattered: 3.64 ms vs 20.27 ms). No game files. AI-assisted (Claude Code). |
|
Tested 4098f8f on NVIDIA GeForce RTX 5080 Laptop GPU, driver 621.14, Windows 11 (build 26300), MSVC 14.44, RelWithDebInfo: pass. |
|
Tested 4098f8f on NVIDIA GeForce RTX 4080, driver 617.42: vk_xbox_paging_test exits 0 and ends with "PASS" ("aliasing: write via VA+8 pages, read via VA+9 pages -> 0xc0ffee00", "cleared page reads 0x00000000/0x00000000"), vk_queue_test prints "vk_queue_test: OK", d3d12_vulkan_device_test exits 0, and d3d12_sparse_queue_family_test exits 0 with "LAYER_FINAL PASS". The LEONIDA_VK_VALIDATION=1 run was not reproduced here, and the log does not show whether the zero-read check ran or was skipped. AI-assisted. |
|
Tested 4098f8f on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass
AI-assisted (Claude Code). |
# Conflicts: # runtime/src/vulkan_backend.h
|
Updated, merged main in (d87b801) Since 6571ec5:
@shdann your repro is a test now, thanks for catching that one. On my 1660 SUPER (610.88), 47/47 targeted tests pass. d3d12_vulkan_device fails at line 6564 ( If @Kam471 or anyone gets a sec to rerun on the new head, that'd be great. |
|
Independent Windows GPU recheck of d87b8010 on an RTX 3080 Ti (driver 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0). The focused I ran the valid mapped-page cases from the fixture with synthetic inputs. AI-assisted. |
|
taking the Windows + NVIDIA check on Same method as my run on #8930: MSVC 19.44.35230, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, CMake 3.31.6 + Ninja; full build then agent: yes |
|
Tested
|
|
Tested
Attribution of the four, because three are not yours:
One flakiness finding that may matter for CI, unrelated to this PR: Not run: anything retail; I have no copy of the game. agent: yes |
|
Tested d87b801 on NVIDIA GeForce RTX 4080, driver 617.42, Windows 11 Pro (26300), MSVC 14.41, Vulkan SDK 1.4.363.0: pass.
AI-assisted (Claude Code) test run. |
|
Tested
No game files. AI-assisted (Claude Code). |
Claimed in the coordination issue as: D3D-546 (#313)
What and why
runtime/src/xbox_paging.hmodelsRegisterPagePoolX,CopyPageMappingsX,CopyPageMappingsBatchXandClearPageMappingsXon Vulkan sparse binding:VkBuffer. A console VA is an offset into it and its device address never changes; a remap only changes what backs a page.PagePool). On NVIDIA only device-local memory can back a sparse buffer page.vkQueueBindSparse. Runs contiguous in both the arena and a chunk merge into one bind.VulkanQueue::bind_sparse_orderedputs the bind on the queue timeline asbind_tilesdoes. Both now share one submit helper;bind_tilesbehaves as before.Only range type 0 is documented publicly (Xbox-GDK-Samples AdvancedESRAM), so other range types are refused. Nothing calls this yet, since the vtable slots aren't measured.
docs/xbox_paging.mdhas the model, the costs and what's left.Measured on a GTX 1660 SUPER: a call costs about 0.25 ms, plus 1.5–2 µs per contiguous page or 8–10 µs per scattered page. A remap between two dispatches added about 0.7 ms of GPU gap, and the call returned on the CPU in 0.1 ms.
Tested
vk_xbox_paging_test: PASS, and 0 errors underLEONIDA_VK_VALIDATION=1. The zero-read check runs only whereresidencyNonResidentStrictis set; with less than 64 GiB of sparse address space the test skips (77).vk_queue_test,d3d12_sparse_queue_family_testandd3d12_vulkan_device_test(covers the refactoredbind_tiles): all PASS./W4warnings in the changed files.NVIDIA GeForce GTX 1660 SUPER, driver 610.88, Windows 11, MSVC 14.51, Vulkan SDK 1.4.363.1.
Checklist
docs/design.md, with how it was confirmed. (No translator change.)