runtime: mark UAV writes before refreshing coherent placed buffers #3892
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3892
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3890"
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?
@Leyukaka on GitHub · 2026-12-02 21:00 UTC · original
Leyukaka:fix-3776-uav-refresh→main· +826 −66 · 11 files · 12 commits · openFixes the main regression from #3778. This is a follow-up to that work: it keeps the coherent refresh as merged and adds the write sources that the refresh did not know about yet. Thanks to @Holastor for the refresh and its provenance marker, which this change reuses unchanged.
Problem
Since #3778,
indirect_table_bufferand the compute root SRV path refresh a non-aliased placed buffer from guest memory unless the resource is marked GPU-written. Only copies set that mark (mark_gpu_writteninlist_copy.inl). A write made by a guest shader through a UAV did not, so a buffer written that way could be overwritten with the stale guest bytes before the draw read it.Five tests fail on current
main, confirmed on unmodifiedmainon Windows:startup_indirect_translated_draw_warpstartup_indirect_translated_draw_hardwarestartup_indirect_translated_refusal_census_warpstartup_indirect_translated_refusal_census_hardwarestartup_indirect_translated_refusal_census_control_warpThe refusal census tests report:
Change
Resources written through a guest UAV are now marked with the same marker as copies:
ExecuteIndirect, which go throughdraw_translatedClearUnorderedAccessViewUintandClearUnorderedAccessViewFloat)ResolveQueryDatadestinationsA buffer the GPU never wrote keeps the refresh from #3778.
The mark is per resource and is set when the command is recorded, as for copies. It has the same limitation as copies: a list recorded before the write and executed after it can still upload guest bytes.
The
ResolveQueryDatamark changes no result today. That slot only accepts a readback buffer without guest memory, which the refresh never handles. It is marked so that every GPU write follows the same rule.Tests in
tests/startup_indirect_draw_indexed.cpp:Validation
On Windows (MSVC), WARP and hardware: 19/19 passed on base
0d00d996f, including the five tests that fail on unmodifiedmainthere. The branch was then rebased onto25f8ebec5without conflicts; I will rerun the same set on the new base and post the result here.Not covered
@R0Y00 on GitHub · 2026-12-02 21:12 UTC · original · requested changes
Independent MSVC Debug on
0cce5d07passed the full 19-case WARP/RTX 4060 Laptop matrix. Removing only the mark inlist_clear_uavreproduced all five translated-draw/census failures. There is also a newly exposed lifetime regression: I used the newrefreshed_buffercase, recorded the same slot-53 clear against it on a second wrapped DIRECT list, closed and released that list without submitting it, and then submitted the ordinary translated read from the original list. On both adapters, head returned 0/8 red pixels (0xff000000, expected0xff0000ff). Removing just the record-time mark made that read pass 8/8 on both; the later submitted-clear case then failed as expected. The global mark prevents the guest-backed read even though no GPU write ran. Please retain a list-local mark for same-list reads after a write, commit it only when the write is submitted, and discard pending marks when the list is reset or released. Keep both the submitted-clear and abandoned-list cases.c3a8543333' into HEAD fe0933d01e@R0Y00 on GitHub · 2026-12-02 21:29 UTC · original · reviewed
I pushed
73f3f639for re-review. New UAV and query writes are visible to reads in the same recording. Submission commits the mark, and Reset/release drops a pending mark. The legacy copy paths keep their existing behavior. On Windows 11 build 26300, MSVC Debug passed all 19 targeted cases on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The submitted-clear and abandoned-list readback cases both pass. In the standalone coherence test, removing only submission promotion fails both adapters withsubmit did not commit the pending GPU write; restoring it gives 2/2. The indirect-draw fixture runs with the debug layer enabled. Please independently review the new recording/submit transition before landing.@Leyukaka on GitHub · 2026-12-02 21:56 UTC · original
Thanks for
73f3f639. I reviewed the recording/submit transition at that commit. This was checked by reading the diff and the surrounding code, not built or run here.Checked, looks right
record_gpu_write/is_gpu_written(resource, list)key the pending mark on the native list, the same keyrefresh_rangeandcommit_listsuse, and on the whole buffer (coherent_placed_buffer.inl:164-181). Whole-resource tracking matches the old global mark and is the conservative choice for a UAV.d3d12_draw.inl:3092), the compute root SRV path (d3d12_compute_dispatch.inl:1004), andrefresh_rangeitself (coherent_placed_buffer.inl:307).commit_listsruns inside thesubmitlambda after the nativeExecuteCommandLists(d3d12_xs_device.cpp:5981), so it covers the plain batch, the per-list split path and the draw-dump / red-producer wrappers. A refused submission (linear_refreshfailure) returns before it, and lists skipped for a failed Close or recycled chunks are not in the committed set.d3d12_xs_device.cpp:2500), failed Close (:2555) and final release (:1536) all calldiscard_list, which erases the list entry, so a reused list address cannot inherit stale marks.erase(resource)also clearsgpu_writes(coherent_placed_buffer.inl:256).is_gpu_written(resource, list)releaseslist_cache_lockbefore the registry lookup, andcommit_listsreleases it beforemark_gpu_writtentakesregistry_lock. No new nesting.One remaining gap: a write still pending on another list
The refresh decision is made when the reader is recorded, but the mark only becomes global at submission:
is_gpu_written(X, B)is false, sorefresh_rangerecords a copy of the guest bytes into B.ExecuteCommandLists(2, {A, B}), or A then B in two calls.At
0cce5d07, step 2 was refused because the mark was already global. This is not a regression againstmain, which does not mark the clear at all, but it reopens part of what the previous commit closed, for lists recorded in sequence or on worker threads and submitted together.One option that keeps your abandoned-list case passing: in
is_gpu_written(resource, list), also return true when any other live entry inlist_cache()holds the resource ingpu_writes. Released, Reset and failed-Close lists drop their entries, so an abandoned writer stops blocking as soon as it is released or Reset. The cost is a conservative refusal while an unsubmitted writer list is still alive, which is the previous behavior limited to that window.Tests
copied_buffer(clear and read in the same recording),discarded_clear_buffer(abandoned list), andstartup_coherent_placed_srv.cpp(mark visible only to the recording list, dropped on Reset, committed only by submission).Minor, and older than this change: the non-render
ExecuteCommandListspath (d3d12_xs_device.cpp:6027) does not callcommit_lists. Harmless as long as nothing records these marks outside render mode.@R0Y00 on GitHub · 2026-12-02 22:55 UTC · original · reviewed
I independently reproduced @Leyukaka’s cross-list case on
73f3f639. The unmodifiedstartup_coherent_placed_srv_(warp|hardware)selection passes 2/2. In a local source-built extension, list A copies0xcafebabeto a default-heap backing and registers its pending GPU write. List B records the normal guest refresh and a readback before either list is submitted. Both lists are submitted in order in one batch. After the fence, WARP and RTX 4060 Laptop both read0x77777777from the guest shadow, and B had staged 65,536 bytes. Omitting only B's refresh for this control gives0xcafebabeon both adapters. Please cover the ordered two-list case along with the existing abandoned-list case. We should also exercise recording B first and then submitting A before B, because a recording-time lookup of pending writers would not cover that order.@R0Y00 on GitHub · 2026-12-02 23:10 UTC · original
I also ran the other recording order on
73f3f639: record B's guest refresh and readback first, then record A's GPU write, then submit A before B in the same batch. WARP and RTX 4060 Laptop both read the stale0x77777777after the fence. With only B's refresh omitted, both read A's0xcafebabe. A check for existing pending writers at B's record time cannot catch this order, so please include it when choosing where to guard the refresh.@R0Y00 on GitHub · 2026-12-03 08:06 UTC · original
Related verification on #3916 (
9af44a3f): all 13 affected startup cases passed with refresh disabled. With the same binaries andX2W_COHERENT_PLACED_REFRESH=1, both WARP and RTX reproduced the key3 refusal-census mismatch at pixel(0,0)(0xff00ff00vs0xff000000). Once #3916 lands, please set that switch explicitly in the cross-list fixture and rerun both record/submit orders so the default-off path cannot mask the issue under review here.@R0Y00 on GitHub · 2026-12-03 08:13 UTC · original
On
maind2e6a4ed, the rebase conflicts are limited to the two refresh callers. Keep #3916’s default-off guard in both, then use this PR’sis_gpu_written(native, cmd_list)on the enabled path. I found no reader of the new pending write marks outside the two refresh callers andrefresh_range, so the newly addedrecord_gpu_writecan also return early when refresh is disabled. The existing copy tracking should keep its current behavior. Please check the default-off regression suite alongside the opt-in cross-list cases.@Leyukaka on GitHub · 2026-12-03 09:35 UTC · original
Rebased on
main(d2e6a4ed), new headebb5df0b. I will force-push the branch: the history is rebased, your commita0460f13is kept with its authorship, and the merge commit is gone.Conflicts. Only the two refresh callers, as you found. Both keep the #3916 guard first (
refresh_enabled()incompute_root_srv_buffer, the&& refresh_enabled()branch condition inindirect_table_buffer), then callis_gpu_written(native, cmd_list)on the enabled path.Added on top
record_gpu_writereturns before taking the list lock when the refresh is off, so no list entry is created andcommit_listscommits nothing. The linear-buffer copy tracking is unchanged.is_gpu_written(resource, list)now also checks the pending marks of every other live list. This covers the order where list A records the clear and list B, recorded later, would refresh. Reset, failed Close and release still drop A's mark.startup_coherent_placed_srvchecks thatlist_bis refused whilelist_aholds the mark and refreshes afterlist_ais reset.startup_indirect_translated_coherent_{warp,hardware}run the translated mode withX2W_COHERENT_PLACED_REFRESH=1set by the test, and fail if the switch is not on, so the default-off path cannot mask the cases under review.Known limitation: your second order. B records its refresh before A records the write, and A is submitted first. This branch does not handle that case. The check runs when B records, before A's write exists. When A is submitted, B's copy is already in its closed list. Handling this would need a conditional or indirect copy, which is out of scope here. The
X2W_COHERENT_PLACED_REFRESHrow indocs/startup-runtime.mdnow describes the case. There is no fixture for it, because it would fail against the current code. With the switch off (the default) the case cannot happen, because nothing is refreshed.Tests
Windows, MSVC, WARP and a hardware adapter: 32/32 passed in this set.
startup_indirect_translated_draw_{warp,hardware},startup_indirect_translated_refusal_census_{warp,hardware,control_warp}, the eightstartup_compute_*cases,startup_coherent_placed_srv_switch_off,startup_indirect_copy_provenance*,startup_clear_uav_*,startup_mesh86_material_backing*.X2W_COHERENT_PLACED_REFRESH=1):startup_coherent_placed_srv_{warp,hardware},startup_indirect_translated_coherent_{warp,hardware}.A full-length application run with the switch unset also completed its 360 s window without a stall.
73f3f639ddtoebb5df0b7e@R0Y00 on GitHub · 2026-12-03 10:52 UTC · original
Independent MSVC Debug run at
ebb5df0bon Windows build 26300, inbox WARP and RTX 4060 Laptop 32.0.16.1656. The 10 focused CTests passed without skips: startup_coherent_placed_srv (both adapters and switch-off), translated draw and refusal census (both adapters), explicit coherent-refresh (both adapters), and the WARP refusal-census mutation control.The new tests cover a writer that is already recorded when the second list checks refresh, and a pending mark discarded by Reset. The remaining order in the review is still open on this head: record the refresh list first, record the writer second, then submit writer before refresh. The documentation now names that limitation. Please keep the default-off guard and leave the review open while the opt-in path can still overwrite a submitted GPU write in that order.
@Leyukaka on GitHub · 2026-12-03 11:33 UTC · original
Thank you for the independent run at
ebb5df0band for keeping the review open on the second order. That order (refresh list recorded first, writer recorded second, writer submitted first) is now decided at submission, on the opt-in path only. New head7580ef80: two commits on top ofebb5df0b(8046aa33runtime and docs,7580ef80tests). I will push the branch;ebb5df0band the commits below it are unchanged.Change
refresh_rangeno longer records its copy into the guest list. It keeps a request on the list: the resource, the copy ranges, and the upload filled with the guest bytes when the list records. The record-time refusals are unchanged (a write pending on any live list, a committed write, Reset, failed Close and release).queue_executecallsx2w_coherent_placed::prepare_refreshesfor each submission, afterbefore_submit. In submission order, each list's requests run from an internal list created on the same queue and executed just before that list, in the sameExecuteCommandLists. The internal list carries the COMMON to COPY_DEST barriers the guest list used to carry.x2w-coherent-refresh skipped, first 8) and counted (x2w_d3d12_coherent_refresh_skips), and its page hashes are not committed. No guest list is dropped. A list submitted before the writer keeps its copy, so the write lands last.CopyBufferRegion,CopyResource) now also record a pending write mark, so a submitted copy counts as an earlier write. Their record-time mark and the copy provenance tracking are unchanged.Known difference. If one list refreshes the same buffer twice with different guest bytes in between, both copies now run before that list, so its earlier reads also see the later bytes.
Cost, with the switch on. Each submitted list that has refresh copies to run gets a new allocator and command list, created at that submission and released after its fence. There is no pooling yet.
Unchanged with the switch off (#3916 guard). No list carries a request,
prepare_refreshesreturns before taking a lock, and lists are submitted as before.Docs. The
X2W_COHERENT_PLACED_REFRESHrow indocs/startup-runtime.mdno longer lists this order as a known gap. It describes the submission-time copies, the skip and the known difference above.Tests
startup_coherent_placed_srv_{warp,hardware}(switch on): the existing sections submit through the same preparation as the runtime. New section 7: one list records a refresh and a consumer copy, then another list records a GPU write to the same buffer. (a) Writer first in the same call: the copy is skipped, the refreshing list still runs, its consumer reads the written word, and the page hash is not committed. A resubmission skips it again. (b) Writer in an earlier call: same result. (c) Control, refreshing list first: its copy runs from the internal list placed just before it, the consumer reads the guest word, and the written word lands last.startup_indirect_translated_coherent_{warp,hardware}(switch on): the refreshing cases submit through a guest queue. Two new cases record a UAV clear on another guest list after the draw and submit it first, in the same call or an earlier one. The draw's copy is skipped (one skip each), the draw shows the cleared value, and the table buffer keeps the clear.startup_indirect_translated_draw_{warp,hardware}(switch unset): the same two cases refuse the draw at record time, skip nothing at submission, and keep the clear.Validation
Windows, MSVC, WARP and a hardware adapter: 32/32 passed in the same focused set as before.
startup_indirect_translated_draw_{warp,hardware},startup_indirect_translated_refusal_census_{warp,hardware,control_warp}, the eightstartup_compute_*cases,startup_coherent_placed_srv_switch_off,startup_indirect_copy_provenance*,startup_clear_uav_*,startup_mesh86_material_backing*.X2W_COHERENT_PLACED_REFRESH=1):startup_coherent_placed_srv_{warp,hardware}including the new section 7, andstartup_indirect_translated_coherent_{warp,hardware}.A full-length application run with the switch unset also completed its 360 s window without a stall.
@R0Y00 on GitHub · 2026-12-03 11:59 UTC · original
I independently rebuilt
7580ef80in MSVC Debug on Windows build 26300. The 10 targeted tests all passed on inbox WARP and RTX 4060 Laptop, including reversed recording/submission order, default-off, and the refusal-census control. There were no skips.I also reproduced the disclosed same-list limitation with the source-built startup_coherent_placed_srv fixture. In one list, refresh [0,4) on a fresh page containing 0x12345678 and copy the first word to readback. Change the guest word to 0x89abcdef, refresh [4,8) so the updated 64 KiB page is staged again, then copy the first word to a separate readback offset. After the fence, both adapters returned 0x89abcdef for both reads. The first should still observe 0x12345678. Please keep the cross-list fix and preserve the refresh point inside the guest list, or explicitly refuse a conflicting second snapshot before it can silently change the first read. The current docs and tests make clear that the default-off path stays covered.
@Leyukaka on GitHub · 2026-12-03 13:19 UTC · original
Thank you for the reproduction. A conflicting second snapshot in one list is now refused when it is recorded, so it can no longer change the first read. New head
ea0d9b05: two commits on top of7580ef80(1abb4c8bruntime and docs,ea0d9b05test). The cross-list fix and the order-2 handling at submission are unchanged.Change
All of a list's refresh copies run before that list, so a list holds one snapshot of each 64 KiB page.
refresh_rangenow refuses a later consumer in the same list (RefreshRefusal::conflicting_snapshot, counted) when a page changed in guest memory since the list copied or read it:The first snapshot is kept, so the earlier read keeps its bytes. Identical bytes share the snapshot and add no copy. The draw input and compute root SRV callers refuse with a specific reason:
... changed in guest memory after its list refreshed it for an earlier read. Nothing changes with the switch off.Docs. The
X2W_COHERENT_PLACED_REFRESHrow indocs/startup-runtime.mdreplaces the known difference with this rule.Test
startup_coherent_placed_srv_{warp,hardware}(switch on), new section 8, follows your scenario:[0, 4)of a fresh page holding0x12345678and copies the first word to readback.0x89abcdefand the list refreshes[4, 8)for a second consumer. That refresh is refused as a conflicting snapshot and counted.[8, 12)shares the staged page without a copy.0x12345678.Validation
Windows, MSVC, WARP and a hardware adapter: 32/32 passed in the same focused set as before, including section 8 of
startup_coherent_placed_srvon both adapters andstartup_coherent_placed_srv_switch_off.@R0Y00 on GitHub · 2026-12-03 13:42 UTC · original
I independently rebuilt
ea0d9b05with Windows MSVC Debug and ranctest --preset dev --no-tests=error -j 1 -V -R '^startup_coherent_placed_srv_(warp|hardware)$'. Both WARP and RTX passed, including the conflicting snapshot refusal and preservation of the first read. I also independently reproduced the two remaining CI regressions on this head:Please register both reasons and reconcile the export inventory with current main. The GPU fixture result is good, and the two CI checks still need to pass on the revised head.
ea0d9b050fto57d2968a61@Leyukaka on GitHub · 2026-12-03 14:18 UTC · original
Both CI regressions are fixed in
57d2968a. The branch was rebased onto currentmain(7b3212a9) without conflicts, so it is force-pushed.COMPUTE_DISPATCH_REASONS(tools/startup/triage_run.py) now lists the two refusal reasons for a page that changed after its list refreshed it:a compute root SRV changed in guest memory after its list refreshed it for an earlier read(compute) andan input changed in guest memory after its list refreshed it for an earlier read(draw).x2w_d3d12_coherent_refresh_skips. Withmain's Mesh86 upload export,d3d12_xsnow has 87 entries, 52 of them unmeasured.standin_exports_check.pypins the new entry's source to itsdllexportline, as #3887 did for the Mesh86 export.Validation
Windows, MSVC, WARP and a hardware adapter: 35/35 passed in the focused set.
standin_exports_check,startup_triage_run,startup_triage_run_cli_check.X2W_COHERENT_PLACED_REFRESH=1):startup_coherent_placed_srv_{warp,hardware}.@R0Y00 on GitHub · 2026-12-03 14:43 UTC · original
Windows and Linux CI are green at
57d2968a. A trial merge against mainadfc0d94conflicts in tests/startup_indirect_draw_indexed.cpp after #3937. Please preserve the snapshot_stale corruption before Submit and snapshot_index in the translated-indexed selector alongside the coherent refresh controls. The runtime source merges cleanly. Rerun both the coherent placed SRV and translated indexed snapshot checks on the refreshed head.57d2968a61toed89d267c1@Leyukaka on GitHub · 2026-12-03 15:17 UTC · original
Rebased on
main(adfc0d94), new headed89d267. The history is rebased again, so I will force-push. Your commit is kept with its authorship. The runtime source merged without conflicts.Conflicts. Both were in
tests/startup_indirect_draw_indexed.cpp. Each side's lines are kept as they are:translated_indexedkeepssnapshot_indexfrom #3937. Thetranslated-coherentmode and theX2W_COHERENT_PLACED_REFRESHcheck follow it unchanged.run(): thesnapshot_stalecorruption (0x4d) runs first. The UAV clear recorded on another list after the draw (writer_recorded_after_draw) comes after it. Both still run before any list is closed or submitted.Validation
On Windows (MSVC), WARP and a hardware adapter, on the rebased head: 37/37 passed in the focused set, including startup_indirect_translated_indexed_snapshot_{warp,hardware} from #3937, startup_coherent_placed_srv_{warp,hardware,switch_off}, startup_indirect_translated_coherent_{warp,hardware}, the default-off indirect and compute regression tests, startup_triage_run and standin_exports_check.
startup_indirect_translated_indexed_snapshot_{warp,hardware}.startup_coherent_placed_srv_{warp,hardware}(switch on) andstartup_coherent_placed_srv_switch_off.startup_indirect_translated_coherent_{warp,hardware}.startup_indirect_translated_draw_{warp,hardware},startup_indirect_translated_refusal_census_{warp,hardware,control_warp},startup_compute_{dispatch_input,input_view_token,root_srv_dispatch,snapshot_order}_{warp,hardware}.startup_triage_run,runtime_startup_triage_run_cli_check,standin_exports_check.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.