WIP: d3d12,xmem: sync TitleTexture readability against title_memory_map between passes (RT-TITLE-TEXTURE-MAP-GEN) #2240
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2240
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/title-texture-map-generation"
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 successfully merged and closed
Claimed in the coordination issue as:
RT-TITLE-TEXTURE-MAP-GEN(https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7188273837)What and why
Device::title_texture_readable(runtime/shims/d3d12_vulkan_device.cpp) cached positive readability (generation = 0,cache_success = true) and relied solely onrefresh_title_textures()(throttled toLEONIDA_TITLE_TEXTURE_PERIOD_MS = 16ms ahead ofExecuteCommandLists) to drainleonida::title_memory_map::changes_sinceand callt.memory.retry().When
CopyPageMappingsBatchXorXMemMapPhysicalPagesunmaps or maps 64 KiB tiles (title_memory_map::changed) and a title thread calls synchronous Slot-70write_placed_texture_view(or the async fill worker runs) before the next 16 ms pass (!title_pass_):title_texture_readablereturned staletruewithout probingVirtualQuery, faulting insidehash_bytes(:239) while holdingtitle_texture_mutex.pending()(cache_failure = true) returned stalefalsewithout re-probing until the next pass, delaying bindless publication of newly mapped tiles.xmem::physical_page_fault(runtime/shims/xmem.cpp:1675) recorded read faults (access == 0) over unmapped window pages asFaultExit::left_to_titlewithout checkingtitle_code(pc), andmix_words/hash_byteslackedLEONIDA_GUARDED_NO_BUILTIN(and calledstd::memcpyinside a__trycallee).Changes:
map_generation_inTextureReadability::sync_map(pass_generation, cpu, size)(runtime/src/title_texture_memory.h), called fromtitle_texture_readablewhen!title_pass_ && guard && !mapped. Unchanged generations cost oneO(1)atomic load; non-overlapping map changes advancemap_generation_with0extraVirtualQueryprobes; overlapping unmaps defer immediately (0first-chance AVs) and overlapping maps wake pending textures immediately.LEONIDA_GUARDED_NO_BUILTINand a packedUnalignedWord64load tomix_words/hash_bytes.from_title(title_code(pc)) onaccess == 0inxmem::physical_page_faultso host guarded reads exit viaFaultExit::passed_guardedwithout falseleft_to_titlecounts, while title-code reads and all write faults retainleft_to_title.Tested
ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure:title_memory_map: verifiessync_map(0probes on non-overlapping change, immediate defer on overlapping unmap, immediate wake on overlapping map).d3d12_existing_heap,d3d12_existing_heap_no_write_watch,d3d12_existing_heap_write_watch: newcheck_placed_view_map_changescase on bothVK_EXT_host_image_copyand staged devices verifies0first-chance AVs viaAddVectoredExceptionHandlerafter interiorMEM_DECOMMIT+title_memory_map::changedon a512 KiB(> 256 KiBsampled-hash) placed texture, and immediate bindless publication afterMEM_COMMIT+title_memory_map::changedwithoutExecuteCommandLists.xmem,xmem_pool_zero_read,xmem_no_write_watch,xmem_write_watch: new non-title executable-stub read test verifiesFaultExit::passed_guardedincrements with0left_to_titleincrements while title-image reads still incrementleft_to_title.460 / 463runnable tests pass (0regressions vsmain).python -I tests/test_text_write_line_endings.py&python -I scripts/check_no_game_data.pyacross all 7 touched files (exit 0).GPUs tested: NVIDIA GeForce RTX 3090, driver 610.88 (Vulkan 1.4.341), Windows 11 x64
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Overlap note: #2267 (RT-TITLE-TEXTURE-SHOW-AFTER-UPLOAD) also touches the TitleTexture path. The logic is separate (it changes
Resource::create_textureand the fill worker, nottitle_texture_readable), but both PRs add a case toruntime/test/d3d12_existing_heap_test.cppand itsmain(), so whichever lands second may need a small merge there. AI-assisted (Claude Code).Independent verification of head
d088ea79b8394c04a46ec19efb2922a7cd3faae3, with currentmain(a73a57e13) merged in, no conflicts.Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.
d3d12_existing_heap,d3d12_existing_heap_no_write_watch,d3d12_existing_heap_write_watch,title_memory_map,xmem, plus neighboursxmem_pool_zero_read,xmem_wine_commit,xmem_no_write_watch,xmem_write_watch: 9/9 pass.main's runtime: the threed3d12_existing_heap*tests fail atslot-70 view map changes line 1437: g_view_avs.load(std::memory_order_relaxed) == 0, so the new case catches the bug. The newxmemcase passes onmaintoo, andtitle_memory_map_testdoes not compile there (it calls the newsync_map).mainon this machine (xbox_presentandd3d12_set_descriptor_heapsfail onmaintoo).Diff read, one question: in
physical_page_fault, a read fault on a title page that isnot_oursand not from title code now exits aspassed_guarded, which is not noted. That is right for the D3D12 layer's guarded reads, but a host read of an unmapped title page outside any guard now also leaves no note. If that is intended, a line in theFaultExitcomment saying so would help.No game files used. AI-assisted (Claude Code).
Thank you, @zmasi. This went into
mainthrough #2350 (RT-LINUX-AMD-WORLD), merged at your headd088ea79bwith your commits and authorship kept, although it was still marked draft. It was part of the build that first drew the world on Linux with an AMD GPU. GitHub shows this PR as merged for that reason, so nothing needs closing.AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)