mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:00:52 +01:00
[PR #622] [MERGED] runtime: apply the console value writes after the submission that carried them (RT-LIST-WRITE-VALUE) #663
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#663
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/622
Author: @Mby159
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:fix/rt-list-write-value📝 Commits (6)
de234e1value writes: carry the console's value writes on the GPU label path9b74691docs: the console's value-write slots 71 to 74f3bfc03Merge #1723 (post-story runtime) into #622 (list value writes)924966eAdapt #622 to #1723: its arena and xmem writes become the list values' fallbackf005d7aAdapt #622 to #1723: the slot 71-74 rows say who writes and who waits6aa5f0bMerge main (#1723 merged) into #622 (list value writes)📊 Changes
15 files changed (+564 additions, -6 deletions)
View changed files
📝
docs/d3d12_command_objects.md(+18 -0)📝
docs/d3d12_xs_console_abi.md(+6 -0)📝
runtime/CMakeLists.txt(+9 -0)📝
runtime/README.md(+1 -1)📝
runtime/shims/d3d12_vulkan_device.cpp(+43 -0)📝
runtime/shims/d3d12_xs_device.cpp(+7 -1)📝
runtime/shims/d3d12_xs_device.h(+9 -0)📝
runtime/shims/d3d12_xs_list_values.h(+26 -3)📝
runtime/shims/xmem.cpp(+98 -0)📝
runtime/shims/xmem.h(+14 -0)📝
runtime/src/gpu_label_memory.h(+2 -1)➕
runtime/src/value_write_sink.h(+77 -0)📝
runtime/src/vulkan_backend.h(+10 -0)📝
runtime/src/vulkan_gpu_labels.h(+22 -0)➕
runtime/test/xbox_list_value_fallback_test.cpp(+222 -0)📄 Description
Claimed in the coordination issue as: RT-LIST-WRITE-VALUE
What and why
Console list slots 71 and 72 (
Write32BitValueBottomOfPipeXandWrite64BitValueBottomOfPipeX) were dropped: the list proxy took thekListNotForwardedbranch and returned 0, so the value never reached the title memory and the console counter the title watches never moved.This pull request records the write on the list proxy, collects the records when the queue proxy submits the lists, and applies the value into the title memory after that submission has completed on the GPU, in submission order. The console writes the value at the bottom of the pipe; here the CPU writes it once the queue timeline says the submission is done, so a later submission on the same queue sees it.
Where the bytes land. The console address is resolved in two cases that are genuinely different:
arena.mapped + va, the same bytes the GPU reads. A sparse resource is refused, because the sparse pass binds its memory elsewhere.The write channel that was missing. The console VA being a host address was not enough: xmem commits its physical pages on first touch, and two of the measured windows are
PAGE_NOACCESSfor the CPU. There was no CPU write path into the xmem pages at all (commit_physical_rangeonly commits,host_atin the Vulkan backend is read-only, and itshostpointer is null for DEFAULT/READBACK). The newrt::xmem::write_title_bytescommits the physical range and then writes through the section own host mapping for a physical page (writable even where the title view isPAGE_NOACCESS), or through the window bytes when the range is not one of the xmem pages, after aVirtualQueryprotection check so a GPU-only window is refused instead of faulting.New files:
runtime/src/xs_value_writes.h(the record the layers share and the function that applies a batch),runtime/test/xs_value_writes_test.cpp(a CPU test with a byte-array model, no game data) andruntime/test/xs_value_writes_handover_test.cpp(the hand-over from the queue proxy to the queue that submits, Windows-only).Depends on: none. #577, which shares
runtime/src/vulkan_backend.h, is merged, and this branch is rebased ontomainatd0da7dad.The shape after the review
@V6ser asked for this to be less indirect. It is now:
std::vector<ValueWrite>; there is no log class;runtime/src/vulkan_backend.h; there is no queue helper class;runtime/shims/d3d12_xs_device.cpp; it is no longer in the shared header.runtime/src/xs_value_writes.his the record and the function that applies a batch, and the xmem write the D3D12 layer needs moved toruntime/shims/xmem.h, next to the shim that owns it. The change against the previous headd149020ais 11 files, +247/-295.The hand-over is still per thread, and that is deliberate: the console list proxy is in the Xbox-ABI shim layer and the queue that submits is in the COM layer,
ID3D12CommandQueue::ExecuteCommandListscannot carry the records in its signature, and the proxy cannot call into the COM layer because about twenty test binaries compileruntime/shims/d3d12_xs_device.cppon its own (xs_proxy_mock_test,root_sig_test, thed3d12_*_testtargets).One defect found while reshaping this and fixed: the batches were pushed by the submitting thread and popped by the completion thread with no lock. They are under one now.
The hand-over must not need a TLS guard
The hand-over's buffer is reached through a constant-initialized
thread_localpointer, and the vector behind it ismade on first use. A thread_local that needs a dynamic initializer or a C++ destructor is not usable in this tree:
the runtime runs with "zero
_Init_thread_headerTLS guards or C++ thread_local destructors"(
runtime/shims/com_shim.cpp), and every other thread_local in the tree is a plain POD for that reason - the boolin the xmem shim, the bool in the startup trace, the POD array in the PE loader.
The title's own threads reach the CRT's
_register_thread_local_exe_atexit_callbackon their way out, and with adynamically initialized thread_local in the process that path terminates the process: @DesertGamer measured
0xC0000409at startup on the retail package, with the stackabort <- terminate <- register_thread_local_exe_atexit_callback <- game_thread, and their constant-initializedpointer experiment does not abort. The earlier heads aborted for the same reason: their staged records were a
static thread_localwith astd::vectorinside, one layer down inruntime/src/xs_value_writes.h.What I tested
xs_value_writes_test:the console's value-write slots record and apply their writes, exit 0 (built with the MinGW clang and run here).runtime/src/vulkan_backend.hcompiles on its own (clang++ -fsyntax-only, llvm-mingw 20261117), andruntime/shims/xmem.cppis syntax-clean with the change.runtime/shims/d3d12_xs_device.cpp: syntax-only compile reports two errors, both pre-existing and environmental:ID3D12GraphicsCommandList8is not in this machine's MinGWd3d12.h.python -I scripts/check_no_game_data.pyover all 12 changed files: exit 0, no output.ctest --test-dir runtime/build -C Release: 71 of 72 pass, 2 skipped (shader_library_corpus,vk_sync_validation- they need game data or a GPU). The one failure isvk_queue_query_sync, a known flake: on the pristine upstream tree at the same commit it fails 2 of 5 direct runs, on this tree 3 of 8. It is not caused by this change.Hardware: Windows 11 x64 (10.0.29712), Python 3.13, llvm-mingw 20261117. No game files, no GPU, no network.
Not verified here
runtime/shims/d3d12_com.cppandruntime/shims/d3d12_vulkan_device.cppare not compile-checked as whole files: they need the SDKd3d12.hand the generatedd3d12_stubs.h, and the MinGW header is older and structurally different, so the repository stub generator cannot run on it. The CI build with MSVC and the Windows SDK is still required.xs_proxy_mock_testis Windows-only and was not run. The mock infrastructure is unchanged, but the mock queue and list proxies now carry a plain vector of records.Gaps I would like a ruling on
gpu_timestamp()uses the DEVICE domain ofVK_EXT/KHR_calibrated_timestamps, the same clockGetClockCalibrationanswers with. On a device without it the function returns 0, the write is skipped, and the counter this item is about would still not advance. Flag 2 (system clock, QPC) and flag 0 (the value) work everywhere. This is the largest functional gap.PAGE_NOACCESSGPU window). Such a write is dropped and reported once on stderr.flushargument (the third one) is not interpreted; every write is applied after the submission.Attribution and licensing
The argument shapes are the facts xcl measured; the slot numbers are measured on the retail title and in the shipped BVH builder (section 3.3a of the document); the deferred bottom-of-pipe write model follows VIctory. Both projects are cited for facts and for the model only, no code copied: xcl is GPL-2.0-only and VIctory is GPL-3.0-only, and the attribution is in
runtime/src/xs_value_writes.h, in the new paragraph ofdocs/d3d12_command_objects.mdand in that document section 8.1 licence note.docs/related_projects.mdlists the projects whose licences the repository tracks as a whole. I did not add xcl or VIctory there, because that file reads like a project-level policy; if the maintainer wants them listed, that is a one-paragraph follow-up.Coordination
This is in
runtime/shims/d3d12_xs_device.cpp, the same file as the RT-XS-LIST-X-IID work. @fiestorra said their piece isproxy_create_command_list_xand ours islist_slot/list_query_interfaceand the queue unwrap path, and that they will keep thewrap_listsignature as it is; this pull request does not change it.AI-assisted: yes.
Ordering: a later submission can read before the host write lands
sodove's Windows review (RTX 5070 Ti, Khronos validation 1.4.369) reproduced this in a test-only extension of the
synthetic xmem placement test: a CPU fence held one queue while it received a list created through
CreateCommandListXwith one 32-bit and one 64-bit value write, followed by a second submission copying the sameprivate buffer to readback. The writes stayed blocked until the fence was released and both eventually landed in
CPU-visible memory, but the following GPU copy saw 0 of the 2 new values in 14 of 15 runs.
The progress callback orders the CPU writes with each other; later GPU work can still run before the callback
publishes them. What this pull request gives is therefore:
the GPU, and
It does not give a later submission a guarantee that it observes them. A consumer that reads the same memory in a
following submission needs its own synchronisation. That is stated here rather than left implicit.
The xmem shim stays out of the D3D12 library
The D3D12 layer reaches the title's memory through
rt::xmem::write_title_bytes, which lives in the xmem shim.Calling it directly from
d3d12_vulkan_device.cppput the shim in thegta6rt_d3d12_comlibrary's dependencyset, and every consumer of that library that does not compile the shim itself failed to link (LNK2019/LNK1120,
reported by sodove). The write now goes through a pointer the shim registers -
rt::xmem::title_write_fninruntime/shims/xmem.h- so the library keeps its own dependencies and a process without the shim keeps theconsole's value writes dropped, the way they were before.
The slot numbers: measured, and corrected
The two value-write calls arrive at console list slots 71 and 72, not 69 and 70. Three independent readings agree:
docs/d3d12_command_objects.mdsection 3.3a, which reads the shippedXboxBvhBuilder.dll:+0x238(slot 71) is a 32-bit value write and+0x248(slot 73) is a masked wait. That is the same numbering - and it already contradicted the four rows this pull request first added.1and not an address, as a 64-bit write at address 1 (the sink refuses it unless the arena is mapped at that moment), and slot 69 was never called, so no 32-bit value was ever written.So the two constants in
runtime/src/xs_value_writes.hnow name the measured slots, the four rows of the documented table move with them (71 and 72 write, 73 and 74 wait), the comments that name them follow, and the test pins both numbers.What is still open. Where the numbering starts to differ is not known. The title never calls
ExecuteIndirect- neither at 61 nor at 63 - so the shift's origin is not pinned.ExecuteIndirect(61), the copy at 85 and the console-only 141 may sit two slots low as well. That is an inference from the four measured rows, not a measurement, and nothing in this pull request changes them; it is filed as a separate finding.Not verified locally. The renumbering is two constants, the table rows, the comments and the test. This machine has no C++ toolchain, so the C++ test and the Windows build are the CI's to run.
python -I scripts/check_no_game_data.pyover all 12 changed files: exit 0, no output.Rebased onto current main
The branch is rebased onto
mainatd0da7dad(the merge of #404). One conflict needed a hand:runtime/shims/d3d12_vulkan_device.cpphad main'sstate_.context->mesh_queries = info.mesh_shader_queries;(from #577) and this pull request'sset_up_value_writes();on the same line, and both are kept. The change against thatmainis 12 files, +640/-8.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.