d3d12_xs: CreateSamplerX writes through; mapped descriptor ranges are left to the submission-time pull (RT-XS-DESCRIPTOR-MIRROR-GAPS) #2498
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2498"
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?
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T19:38:38Z.
Claimed in the coordination issue as: RT-XS-DESCRIPTOR-MIRROR-GAPS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226662844)
What and why
Item 2 of @kevincommits' finding in #1608 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226076494). Thanks for the audit.
Both gaps are in
runtime/shims/d3d12_xs_device.cpp, where title-backed descriptor heaps are kept in step with the real heap:proxy_create_sampler_x, CreateSamplerX) created the sampler in the real heap only. Every other descriptor creator and copier callslocal_write_throughto store the result at the title's address as well: slots 17-22, 23/24, and the placed view. A title that copies slot-61 samplers out of its own heap memory into a shader-visible heap therefore copied zeros or stale bytes. Slot 61 now writes through, as slot 22 does.local_mirror_tableruns when a descriptor table is bound (list slots 35/36) and copied the title's raw slots into the real range. For a mapped range (DescriptorRange::mapped, the Vulkan device's live arena) that copy could overwrite a slot the queue had translated in place for a submission still running (timbot103's review). Main did this on Windows; on WineVirtualQueryhid the range. The queue already pulls the title's slots for every bound table at submission (pull_title_descriptors), so a mapped range is now left to it, on Windows and Wine alike.No overlap with #2484 or the other open PRs on
d3d12_xs_device.cpp:git merge-treefinds no conflict with #2484.Tested
Windows 11, MSVC (VS 18), RelWithDebInfo, on
main43a9d562d. CPU only.xs_proxy_mock_testgainscheck_descriptor_mirror. The mock's real heap reports a CPU start in test memory (g_mock_heap_cpu_start; other checks keep the old fake address), and the XMem hook hands out a title buffer.main's slot 61 this fails.title_va_aliases().pull_descriptors) then copies the title's slot. The first version of this PR fails the first check.ctest -R "^(xs_proxy_mock.*|device_proxy)$": 10/10 pass.scripts/check_no_game_data.py: clean.GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU tests only)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T21:36:44Z.
Review: APPROVED
Reviewed the diff and tested locally on Windows 11 (MSVC 19.44, Ninja Release).
proxy_create_sampler_x()now callslocal_write_through(self, dest, 1)afterCreateSampler, matching device slot 22 so title-backed heaps hold the sampler bytes instead of zeros.local_mirror_table()now bypasses thelocal_accessible()check whenrange.mappedis set, consistent withlocal_write_throughfor livevkMapMemoryspans on Wine.xs_proxy_mock_testand ranctest --output-on-failure -V -R xs_proxy_mock: 9/9 tests passed (includingcheck_descriptor_mirror).AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:02:04Z.
Reviewed at head
a23273b5con Windows 11 (MSVC 202219.44).Verification
xs_proxy_mock_test.xs_proxy_mock_test: passed.Finding (Request changes)
local_mirror_table()copy can overwrite an in-flight submission's rebased descriptor in place (d3d12_xs_device.cpp:345-393,3639-3644;d3d12_vulkan_device.cpp:4025-4066,4185-4193,8349-8371):Bypassing
local_accessible()viaif (!range.mapped && ...)enableslocal_mirror_table()to raw-memcpytitle descriptors directly intorange.real_start + offsetduring command-list recording (SetGraphicsRootDescriptorTable/SetComputeRootDescriptorTable), without synchronizing against GPU completion. On the Vulkan backend, submission pulls title descriptors and rebases title buffer addresses in place in the shared arena. If list A is submitted with a rebased buffer descriptor and list B records a bind to the same table before A finishes on the GPU (even if B is never submitted),local_mirror_table()overwrites A's translated GPU descriptor in the live arena with the raw title bytes while A's shaders are still reading it. Keeping mapped-arena synchronization strictly on the submission-time refresh path (or using submission-lifetime storage) avoids corrupting in-flight descriptors.The
CreateSamplerXslot-61 write-through (d3d12_xs_device.cpp:4865-4868,5028-5042) looks clean.AI-assisted review + local MSVC verification.
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T02:11:43Z.
@timbot103 thanks, you're right. Fixed in
59feb165b.A mapped real range is the Vulkan device's live arena.
scan_title_tablepulls the title's slots there and rebases their buffer addresses in place at submission, while lists submitted earlier may still be reading them. A raw copy at recording time could therefore replace a translated slot under a running submission.Two notes on scope:
local_mirror_tableonly checkslocal_accessible, andVirtualQueryreports the arena as committed read-write there. So main did the same recording-time copy into mapped ranges. The first commit of this PR extended it to Wine.pull_title_descriptorsthroughtitle_va_aliases().pull_descriptors), and that path does not askVirtualQueryabout the arena. So Wine gets the title's descriptors without it.So
local_mirror_tablenow returns for a mapped range, with a comment saying why. Unmapped ranges keep the recording-time copy as before. The slot-61CreateSamplerXwrite-through is unchanged.Test,
xs_proxy_mock_testcheck_descriptor_mirrorcase 2:title_va_aliases().pull_descriptors(...), the queue's submission path, then copies the title's slot.With the previous commit the "left as it was" check fails (line 3500).
ctest -R "^(xs_proxy_mock.*|device_proxy)$": 10/10 pass. Windows 11, MSVC (VS 18), RelWithDebInfo.AI-assisted (Claude Code)
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T08:21:44Z.
Review: APPROVED
Re-reviewed head
59feb165band re-tested locally on Windows 11 (MSVC 19.44, Ninja Release).local_mirror_table()whenrange.mappedis set cleanly fixes the recording-time race flagged by@timbot103(avoiding raw copies over translated descriptors in the live Vulkan arena while leaving submission-time pulls topull_title_descriptors).proxy_create_sampler_x()write-through to title-backed heaps remains intact, andcheck_descriptor_mirror()now asserts both that the mapped real slot stays untouched during list recording and thattitle_va_aliases().pull_descriptors()updates it at submission.xs_proxy_mock_testand ranctest --output-on-failure -R xs_proxy_mock: 9/9 passed (2.72 s).AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T21:24:28Z.
Independent Verification Report —
59feb165bd+origin/main(aa918e5d9f)Environment: Windows 11 (
26200), AMD Ryzen 9 5950X + NVIDIA RTX 3090, MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8, Debug/Od /MDd& Release/O2 /MD).Verdict: PASS (Ready to merge) — clean merge with
origin/main(008b3158cb85) and combined Batch 9 set (a422ed80f598).1. Red -> Green Verification
origin/maind3d12_xs_device.cpp+#2498xs_proxy_mock_test.cpp):xs_proxy_mock_testfails (rc = 1) incheck_descriptor_mirror, reproducing both gaps onorigin/main:CreateSamplerX) did not calllocal_write_through(self, dest, 1), leaving title-backed sampler heap slots zeroed.local_mirror_tablecopied raw title bytes intorange.mappedlive Vulkan descriptor arena ranges at command-list recording time (slots 35/36), overwriting in-place translated descriptors of in-flight submissions.59feb165bd+origin/main):xs_proxy_mock_test(all 9/9 CTest modes in Release + default in Debug): PASS (default,--fail-virtualalloc,--fail-virtualprotect,--fail-veh,--env-slots,--env-slots-invalid,--env-slots-70,--env-slots-74,--slot133-layout), confirmingCreateSamplerXwrites through to title-backed heaps whilelocal_mirror_tableleavesrange.mappeduntouched until submission-timetitle_va_aliases().pull_descriptors(...).device_proxy_test(2/2 CTest modes against Windows 11 WARPd3d12.dll/dxgi.dll— default and--trace-d3d12): PASS.#2498.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:03:14Z.
Verified by OreoFR
Run 1 (lot 4)
09c153948+ PR head59feb165b; integration package 2 of 6 (4 PRs, merged without conflict)Run 2 (lot 4 bis)
33db04a70+ PR head59feb165b; integration package of 15 PRsAll runs
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:46:15Z.
Run on PR head
59feb165b(base43a9d562d, 2 commits), checked against main1bc055e6c(and origin/mainc7753ed98):git merge-tree --write-treefinds no conflict with either.Environment: NVIDIA GeForce RTX 3090 (24 GB), driver 621.40, Windows 11 Pro (build 26300), MSVC 14.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, SDL3 3.4.20 static installed. CPU tests only.
Configure (as scripts/build_runtime.ps1 does, own build folder):
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON. Only the test targets were built, not the whole runtime:cmake --build runtime/build -j 8 --target xs_proxy_mock_test device_proxy_test.Green (PR head):
ctest -R "^(xs_proxy_mock.*|device_proxy)$" --output-on-failure-> 10/10 passed (xs_proxy_mock2.65 s).Red (behavioural, the new test kept; the header-missing kind does not apply, no new header):
runtime/shims/d3d12_xs_device.cppput back to base43a9d562d, rebuiltxs_proxy_mock_test,ctest -R "^xs_proxy_mock$"-> failed at the slot 61 write-through check:line 3471: std::memcmp(title + off3, real_heap + off3, kMockDescriptorInc) == 0.a23273b5c: slot 61 fix kept, mapped-range handling as in the first commit), same target and test -> failed at the mapped-range check:line 3500: std::memcmp(real_heap + off2, in_flight, kMockDescriptorInc) == 0. So both checks bite, each for its own fix.Link check: merged into main
1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:04:26Z.
Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and
gta6rt.exestill links) and a re-check here: no conflict withmain4cf39d157, same head as run,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.