graphics: back the BDA page table with sparse memory #1270
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1270
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1270"
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?
@msfvn on GitHub · 2026-10-09 02:25 UTC · original
msfvn:sparse-bda-pagetable→main· +162 −9 · 6 files · 2 commits · openProblem
The BDA page table has one 8-byte entry per 16 KiB page of the whole guest address space (1 TiB + the 512 GiB extended range):
BDA_PAGETABLE_SIZE= 768 MiB of device-local memory allocated up front. Games map a few tens of GiB of that space (Astro Bot: ~15 GiB), so over 98% of the table is always zero. On a 4-6 GB GPU that is a large share of VRAM.Change
When the device supports
sparseBinding+sparseResidencyBufferwithresidencyNonResidentStrictand the graphics queue family supports sparse binding, the table is created as a sparse buffer:Buffergets aSparseResidencyconstructor andEnsureResident(offset, size), which binds 1 MiB chunks (each covering 2 GiB of guest addresses) on first use.BufferCache::ChangeRegister<true>callsEnsureResidentbefore writing the entries.get_bda_pointeralready treats as a missing page, so the shader side is unchanged.Devices without these features keep the fully resident table.
Testing
Linux, RTX 3050 Laptop 4 GB (NVIDIA 615.71.09), Astro Bot: process VRAM use per
nvidia-smiat the same point of the intro dropped from 2991 MiB to 2413 MiB; rendering unchanged in the intro and cutscenes.Note: NVIDIA's
VK_EXT_memory_budgetlowers the reported heap budget by the sparse buffer's full range even though the memory is not backed, so budget-based numbers understate the saving;nvidia-smishows the real figure.Measurements were taken on a local build that also includes #1102 (so Astro Bot boots without the non-RT patch); regression runs were on
mainwith the community non-RT patch, scripted input through the intro: no new failures (on its own,mainstill stops at the ship scene withfailed to create imageon this 4 GB GPU, see #1271).AI involvement: written with Claude Code (AI assistant) at my request and reviewed by a C++ developer I know; tested on my machine (RTX 3050 Laptop 4 GB, CachyOS) as described above, including playing Astro Bot on this build. Happy to adjust anything you point out.
@coderabbitai[bot] on GitHub · 2026-10-09 02:28 UTC · original · edited 2026-10-11 01:22 UTC
📝 Walkthrough
📝 Walkthrough
Walkthrough
Device creation detects and enables sparse buffer features when the device and graphics queue meet the stated requirements.
Bufferadds sparse chunk allocation, binding, zero-filling, and cleanup.BufferCacheuses sparse residency for the BDA page table when sparse buffers are enabled.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Feature
Merge Risk: 🟡 Moderate · up to
4301dSparse page-table setup may fail on devices with different scratch-buffer memory requirements. Check binding compatibility before merging.
Pre-merge checks |
4 |
1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -107,0 +205,4 @@device.destroyFence(fence.value);for (const auto buffer: scratch) {device.destroyBuffer(buffer);}@coderabbitai[bot] on GitHub · 2026-10-09 02:28 UTC · original · edited 2026-10-11 02:00 UTC
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5184
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42312
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14209
Submit the current command buffer before the sparse bind.
queue.waitIdle()does not submitScheduler().Current(). If that command already contains a shader read, the laterbindSparsecan expose uninitialized memory before the subsequentFillrecords its zeroing operation. A garbage BDA entry can cause an invalid device address and device loss.Call
Scheduler().Finish()beforequeue.waitIdle().Suggested fix
📝 Committable suggestion
✅ Addressed in commit
4301dad@coderabbitai[bot] on GitHub · 2026-10-09 02:28 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
1c017c78-784b-4fd5-943b-e446868c72c7📥 Commits
Reviewing files that changed from the base of the PR and between
7b9997baeaanda042eddb2f.📒 Files selected for processing (6)
src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/streamBuffer.cppsrc/graphics/host_gpu/renderer/cache/streamBuffer.hsrc/graphics/presentation/window/vulkanWindow.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -107,0 +179,4 @@buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst;const auto buffer = device.createBuffer(buffer_info);EXIT_IF(buffer.result != vk::Result::eSuccess);EXIT_IF(vmaBindBufferMemory(m_graphics->allocator, fresh[i], buffer.value) != VK_SUCCESS);@coderabbitai[bot] on GitHub · 2026-10-11 01:18 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 27083
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 28368
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6824
Check the scratch buffer's memory requirements before binding it.
fresh[i]is allocated with requirements derived from the sparse buffer. The scratch buffer is created independently witheTransferDst. ItsmemoryTypeBits,alignment, and required allocation size can differ.vmaBindBufferMemorycan therefore violate the Vulkan binding requirements and fail or produce undefined behavior.Query the scratch requirements once, intersect the memory types, and use compatible size and alignment values.
Suggested fix
@coderabbitai[bot] on GitHub · 2026-10-11 01:18 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
5b33b4af-0668-4ae7-b431-8c5372a316c4📥 Commits
Reviewing files that changed from the base of the PR and between
a042eddb2fand4301dad641.📒 Files selected for processing (1)
src/graphics/host_gpu/renderer/cache/streamBuffer.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -107,0 +205,4 @@device.destroyFence(fence.value);for (const auto buffer: scratch) {device.destroyBuffer(buffer);}@msfvn on GitHub · 2026-10-11 02:00 UTC · original
Right, recorded but unsubmitted work would run after the bind and before the fill. Fixed in
4301dad6without a mid-drawFinish(): each new chunk is now cleared before it is bound, through a temporary buffer bound to the same allocation and a one-off submission, so the table only ever exposes zeros or real entries regardless of what is already recorded. That also removes thewaitIdle.@ -107,0 +205,4 @@device.destroyFence(fence.value);for (const auto buffer: scratch) {device.destroyBuffer(buffer);}@coderabbitai[bot] on GitHub · 2026-10-11 02:01 UTC · original
@msfvnThanks for the explanation and fix. The updated code waits for the temporary-buffer clear to complete beforebindSparse. This prevents recorded but unsubmitted work from reading uninitialized entries, without a mid-drawFinish()orwaitIdle().If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.