gpu: initialize BDA page table before first use #1065
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!1065
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1065/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?
@MehmetCambaz on GitHub · 2026-10-05 10:03 UTC · original
MehmetCambaz:fix/bda-page-table-init→main· +132 −1 · 4 files · 1 commits · closed without mergingUpdate (review follow-up)
GetBdaPageTableBufferis no longernoexcept. It isn't a plain getter anymore: the first call clears the table throughBuffer::Fill, which isn'tnoexcept.EXITdoesn't throw, so nothing changes at runtime.m_bda_pagetable_initializedis a plainboolon purpose. It's only touched on the GPU thread, like the rest ofBufferCache. Other threads (fault handler, unmap) go throughSendCommandSync.memset), andFillneeds an active command buffer.Summary
BufferCacheallocates the BDA page table in device-local memory, but its untouched entries were never initialized before the table could be populated or bound for shader use.A zero entry is the BDA unresolved sentinel. If a newly allocated table contains stale non-zero data, a shader can treat an untouched guest page as already resolved to a device address and skip the normal fault path.
This initializes the table once before its first registration write or descriptor consumer.
What is covered
The initialization is reached through both production first-use paths:
BufferCache::ChangeRegisterclears the full table before publishing mapped-page device addresses.BufferCache::GetBdaPageTableBufferclears it before the descriptor path can expose it to shaders.The clear uses the existing
Buffer::Fillpath. Its transfer barriers order the clear before subsequent page-table writes and shader reads.Why this test matters
Fresh Vulkan device-local allocations are not guaranteed to contain zeroes. A normal test could therefore pass accidentally when the allocator happens to provide cleared memory.
The new GPU-backed regression first fills the real production BDA table with
0xdeadbeefdeadbeef, verifies that the poison is observable, then checks that never-owned entries return to the required zero/unresolved value.It covers both:
The checked entries span low memory, extended memory, and an unrelated page-table location.
Regression proof
With only the one-time table initialization disabled, the focused regression fails deterministically in 2/2 runs:
With the fix, it passes in 2/2 runs (
registration ok,consumer ok).Testing
Windows 11, RTX 4070, Release:
bda_page_table_initializationpasses, and the same check passes inside the fullshader_recompiler_computerun.shader_recompiler_compute(later, afterPackedUscaledVertexColor) andbuffer_cache_dirty_gcsegfault on my machine with and without this PR, at the same spot on base72e4989b, so they are unrelated to this change.AI usage
AI assistance was used for investigation, implementation, and testing. I reviewed the final diff and the validation results before updating this PR.
@coderabbitai[bot] on GitHub · 2026-10-05 10:12 UTC · original · edited 2026-10-06 00:28 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
268af8ce-a4e7-4f2c-8aa9-6c156dd5f10b📥 Commits
Reviewing files that changed from the base of the PR and between
72e4989b1eand180e65adec.📒 Files selected for processing (4)
CMakeLists.txtsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
BufferCache now zero-fills the BDA page table on first registration change or first access. The compute tests check unowned entries after initialization and verify device addresses for registered buffers. The initialization check runs in the full test sequence and through a dedicated CTest entry.
Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
180e6The page table is cleared before registration or first consumption, and the new tests check unowned entries and registered addresses. No merge-blocking issue is established.
Security Architecture Review
Security architecture risk: ⚪ Minimal · up to
180e6The change prevents uninitialized entries from being treated as valid addresses before first use. The reviewed paths preserve existing access boundaries, and no introduced security architecture concern was identified.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (2 skipped: 1 unsupported, 1 too large.)
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.@overlordxrz-source on GitHub · 2026-10-06 00:10 UTC · original
Validated locally (read the diff, built on x86_64 macOS no-Qt Release):
shader_recompiler_compute_testsbinary builds clean (compile coverage for the new GPU test);resource_trackingpasses. The new poison-then-verify regression itself needs a real Vulkan device so I couldn't execute it here (no loader in this environment — pre-existing limitation, same as clean main).Fill(0)through the existingBuffer::Fillpath (so transfer barriers order the clear before page-table writes/shader reads), reached from both first-use paths (ChangeRegisterandGetBdaPageTableBuffer). Uninitialized device-local memory being misread as resolved translations is exactly the kind of silent corruption that wastes days downstream, and the poison-with-0xdeadbeefregression design (defeats accidentally-zeroed allocators) is the right way to test it.GetBdaPageTableBufferlostnoexcept— I assume becauseFillcanEXIT; worth a brief note in the PR. Also, ism_bda_pagetable_initializedonly ever touched on the GPU thread (like the rest ofBufferCachemutation)? If so no race; if any first-use path can run elsewhere it wants an atomic.Looks good to me pending those two answers.
@MehmetCambaz on GitHub · 2026-10-06 00:23 UTC · original
Thanks for testing it
noexcept: it's not really aboutEXIT, since that just ends the process and doesn't throw. The getter now does real work the first time it's called (it clears the table throughBuffer::Fill), and that isn'tnoexcept, so I didn't want the signature to promise more than it does. Nothing changes at runtime. Happy to put it back if you prefer.Threading: yes, it's only touched on the GPU thread, same as the rest of
BufferCache. Other threads, like the fault handler and unmap, go through 'SendCommandSync' and never touch it directly, so a plain bool is fine. An atomic wouldn't help anyway, because theFillit guards has to be recorded on the GPU thread.I'll add a short note about both to the PR description.
Pull request closed