d3d12: coherent page-tracked backing for non-aliased placed buffer SR… #3776
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3776"
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 R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-12-01T18:54:05Z.
Closes #3640
Summary
Supplies coherent, incrementally refreshed desktop buffer backing for non-aliased (
!placed.alias) placed buffer SRVs inindirect_table_buffer(src/startup_stubs/d3d12_draw.inl), including large buffers exceeding the 16 MiBtitle_input_snapshotlimit (such as the 174 MiB0xae00000buffer).src/startup_stubs/coherent_placed_buffer.inl): Tracks 64 KiB page hashes intitle_memory, coalesces contiguous dirty pages into minimalCopyBufferRegionuploads from a staging upload buffer withCOMMON -> COPY_DEST -> COMMONtransitions, and cleans up tracker state on resource retirement.src/startup_stubs/d3d12_draw.inl): Marks buffers written on the GPU (gpu_written/mark_gpu_written) so subsequent CPU-backed refreshes do not clobber GPU outputs, returning explicit named refusals ("an input is in a placed buffer with mixed GPU and CPU writes","an input range is outside its placed buffer","an input range in title memory is not readable"). Preserves existingindirect_table_copied_gpu_rangeandcommitted_root_srv(#3718) paths.tests/startup_coherent_placed_srv.cpp,tests/cmake/coherent_placed_srv.cmake,tests/standin_exports_check.py): Addsstartup_coherent_placed_srv_<backend>and updatesd3d12_xsexport expectations (79 -> 80).Fixture Coverage (
startup_coherent_placed_srv)0x11223344and0x55667788) afterCopyBufferRegionqueue_a->Signal->queue_bWait)queue_bobserves updated data after fence"an input is in a placed buffer with mixed GPU and CPU writes"indirect_table_bufferx2w_coherent_placed::refresh_rangetests/standin_exports_check.pyx2w_coherent_placed_refreshexport (80entries)471cases,6/6mutations killed)Verification
ctest --preset release --no-tests=error -R "^startup_coherent_placed_srv_(warp|hardware)$" -V— 2/2 passed (WARP0.06s, AMD Radeon hardware0.14s, 0 debug layer errors)python -B tests/standin_exports_check.py— passed (471cases,6/6mutations killed)python -B tests/docs_links_check.py&python -B tests/bidi_controls_check.py— passed-Console s -Gpu amd, 90s): compute dispatches went from1 translated / 4645 refusedto1453 translated / 0 refusedwith zeroplaced bufferrefusals.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-12-01T21:43:00Z.
Addressed the gpu_written provenance case (commit
c7a96c0d):Verified on release:
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T01:50:09Z.
Blocking coherence issues in the current
refresh_range: (1)page_validandpage_hashesare updated before allocation, Map, or submission, so a failed upload can make the retry report clean without uploading anything. Likewise, recording list A then recording list B can make B skip a copy even if A is reset or never submitted. Please separate pending uploads from backing known visible to the consuming list/queue, with failed-allocation retry and unsubmitted/reset-list controls. (2)list_already_refreshedcomputess.offset + s.bytes - offsetwithout first boundingoffsetby the span end. For[0, 64 KiB)followed by[128 KiB, 128 KiB + 4), unsigned subtraction wraps and accepts a disjoint page. Please add that same-list control.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-12-02T06:59:17Z.
Addressed both blocking review items from @R0Y00 (commit
778caf75):Separated per-list pending state from committed
BackingStateand added failure rollback (src/startup_stubs/coherent_placed_buffer.inl,src/startup_stubs/d3d12_xs_device.cpp):refresh_rangereads committedBackingStateand the calling list'sListPendinghashes without mutating either untilCreateCommittedResource,Map,memcpy, barriers, andCopyBufferRegionsucceed. On allocation orMapfailure, it returnsfalsewith*out_copied_bytes == 0and leaves page state untouched so retries upload the dirty pages.ID3D12CommandList*inListPending(deduplicating within the same list without hiding dirty pages from other command lists) and transferred intoBackingState(withlast_submit_queue,last_submit_fence, andlast_submit_fence_value) only inqueue_executeviacommit_listsafterExecuteCommandLists(with cross-queuebefore_submitfence wait when another queue relies on committed state).list_reset, failedlist_close, and listreleasecallx2w_coherent_placed::discard_listto drop unsubmitted pending state;drain_retired_resourcescallsx2w_coherent_placed::erase.Fixed unsigned underflow in
list_already_refreshed(src/startup_stubs/coherent_placed_buffer.inl):offsetagainst the span end (s.offset <= offset,rel = offset - s.offset,rel < s.bytes && bytes <= s.bytes - rel) so disjoint ranges like[0, 64 KiB)followed by[128 KiB, 128 KiB + 4)no longer wrap.Added the 3 requested controls in
tests/startup_coherent_placed_srv.cpp:[0, 64 KiB)then[128 KiB, 128 KiB + 4)(plus a duplicate[128 KiB, 128 KiB + 4)check) on the same list and verifies GPU readback on both pages.Mapretry control: exercises simulatedCreateCommittedResourceandMapfailures (UploadFaultMode::create/UploadFaultMode::map), verifiesfalsereturn and unchangedcopied_bytes/committed_page_valid, then retries and verifies GPU readback.list_a->Reset()without submit andlist_aleft unsubmitted beforelist_brecords and submits, verifyinglist_bstill uploads the page and GPU readback sees the expected bytes.Verified on
release(commit778caf75):.\tools\dev.ps1; cmake --build --preset release --target d3d12_xs_shim startup_coherent_placed_srv: exit 0ctest --preset release --no-tests=error -R "^startup_coherent_placed_srv_(warp|hardware)$" -V:2/2passed (startup_coherent_placed_srv_warp,startup_coherent_placed_srv_hardware).\out\pe-env\Scripts\python.exe -B tests\standin_exports_check.py:470 cases, 6/6 mutations killed PASS.\out\pe-env\Scripts\python.exe -B tests\startup_triage_run_check.py:0 failed.\out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py:Self-test passedImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T11:39:56Z.
Review: CHANGES_REQUESTED
On
a9344430,ctest --preset dev --no-tests=error -j 1 -V -R '^startup_coherent_placed_srv_(warp|hardware)$'passed 2/2 on Windows 11 26300.9974. The fixture selected WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, debug layer off. The disjoint-page, allocation/Map retry and discarded-list cases now pass.One cross-queue lifetime gap remains.
before_submit()waits on the last recorded upload fence. A submitted list that only references already committed pages adds no staged updates or uploads, socommit_lists()returns without recording its completion. A later refresh on a different queue can therefore insert a copy into the backing while the clean consumer is still reading it. The fixture's cross-queue case uses a manual queue wait and does not exercise that dependency. Please add a source-built control with a gated clean consumer on one queue, then a dirty refresh on another, and track the consumer's completion before overwriting its pages.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-12-02T12:08:27Z.
Addressed the remaining cross-queue lifetime gap (commit
19d2bb33):refresh_range()records the pages a list reads in per-listListPending.read_pages, on both the dirty and the already-clean path (copied_bytes == 0).commit_lists()now publishes per-page, per-queue reader fences (last_reader_queue/fence/valueinBackingState::page_readers) even when the list staged no uploads or updates; a later submit on the same queue supersedes that queue's reader entry, readers on other queues stay.before_submit()waits the submitting queue on every other queue's reader fence for the pages its dirty copies are about to overwrite (completed fences are skipped, duplicate fences merge by max value).discard_list()/erase()drop unsavedread_pages.Fixture: new section 6 is the requested source-built control with no manual cross-queue
Waitbetween the reader and the writer: a gated clean consumer on queue_a (queue_a->Wait(gate,1), clean refresh + copy into out_a), then a dirty refresh of the same page on queue_b (title value 0x11223344 -> 0x99AABBCC, copy into out_b), then the gate is signaled. Readback checks out_a == 0x11223344 and out_b == 0x99AABBCC.Evidence on
19d2bb33, Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, debug layer off:ctest --preset release --no-tests=error -R '^startup_coherent_placed_srv_(warp|hardware)$'passed 2/2..inlchange reverted (fixture kept), the new case fails withgated: dirty refresh overwrote the backing before the clean reader finished, so the case exercises exactly the dependency described.standin_exports_check.py(470 cases, 6/6 mutations killed),startup_triage_run_check.pyandbidi_controls_check.pypass.Full-game execution remains unverified; this covers the fixture-level cross-queue ordering.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T12:28:18Z.
Review: APPROVED
The clean-reader lifetime finding is addressed on
19d2bb33. The clean path now publishes its reader fence, and a dirty submission checks it before executing. The source-built fixture passes 2/2 withctest --preset dev --no-tests=error -j 1 -V -R '^startup_coherent_placed_srv_(warp|hardware)$'on Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop driver 32.0.16.1656, debug layer off. Changingif (dit != dirty_pages.end())toif (false && dit != dirty_pages.end())fails on each backend withdirty refresh overwrote the backing before the clean reader finished. The source was restored. Required Windows CI still fails innative_direct_meshat+0x34: unmapped graphics export, covered by #3851. Please sync and rerun after that fixture fix lands.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-12-02T15:54:44Z.
@R0Y00 All CI green
Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-12-02T20:51:37Z.
@Holastor since this merged, eight startup compute tests fail on
main. They pass with only this PR reverted.main46d465d9main46d465d9with0e29ac07revertedstartup_compute_dispatch_input_{warp,hardware}startup_compute_input_view_token_{warp,hardware}startup_compute_root_srv_dispatch_{warp,hardware}startup_compute_snapshot_order_{warp,hardware}They are not in the
prpreset, which is probably why CI stayed green. The first assertions are controls that expect a refusal for an input in a placed buffer that does not alias title memory, for exampledispatch-input-copied: a refused Dispatch wrote the output,dispatch-input-token-copied wrote the output,dispatch-root-srv-copied. With the newrefresh_rangepath those inputs are refreshed from title memory and the dispatch runs.snapshot_ordernow stops onan output buffer descriptor has zero recordsinstead of its expected reason. I haven't traced that one.If the refresh is the intended behaviour, these controls need new expectations. A refused control could then use a case the refresh still refuses: a GPU-written backing, a non-default heap or an unreadable range. Local, RTX 3080, dev preset:
ctest -R 'startup_compute_(dispatch_input|input_view_token|root_srv_dispatch|root_uav_native|snapshot_order)'. The ninth failure,root_uav_native_warp(WARP wave size 4), is unrelated to this PR.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-03T07:54:26Z.
@Holastor thanks for this work. One observation from full-length application runs: since this merged, every full run stalls when it reaches a later, heavier scene (the presenter's fence wait exceeds 2 s and the process is ended about 30 s later). Bisection shows the stall needs the refreshed bytes themselves: copying the same ranges to a scratch buffer, or writing zeros, does not stall, so the refresh code itself is probably not at fault. #3914 makes the refresh opt-in with
X2W_COHERENT_PLACED_REFRESH=1as a temporary gate that leaves your code unchanged (the 8 compute tests @JB2WIN reported pass again with the switch unset), and we are still working on the root cause, most likely a translated shader doing unbounded work once it reads real constants.