gpu: compare one linear buffer through sharing, copying and refused sharing #1935
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1942"
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 MasterDomino on 2026-11-24T21:57:55Z.
What
This PR adds
tests/unified_buffer_paths_check.cpp, a source-built, test-only fixture. It is registered asunified_buffer_paths_{warp,hardware}(SKIP_RETURN_CODE 77) next to the #874 VM tests, with threeWILL_FAILcontrols on WARP. It runs one ordinary linear buffer that the CPU writes and the GPU reads through four paths with the same cases.docs/experiments.mdgains a section next to the #874 VM sections. No production code changes, and no stand-in's default behaviour changes.Why
In #1914, the decision was a hybrid model whose first slice is one linear CPU-written, GPU-read buffer. It asked for that buffer to be run through real sharing, forced copying and forced sharing failure, with the source-built heap and cross-queue controls from #874. The cases are: bind A and write B before submission; a GPU write seen by the CPU alias after the fence; a submission held in flight whose backing is not reused; and missing refresh or early readback giving stale data or a defined refusal. It asked for the bytes copied, the backing, the HRESULTs and skips. This PR is that comparison. The first buffer change can then be reviewed on its own.
Refs #1914
Refs #874
Fixture design
Title memory, following XMem (
src/xmem_mapped_pages.cpp): The section pool is a 256 MiB pagefile section of 64 KiB slots. Each allocation takes two slots, mapped as two page views on a placeholder split at the page boundary. The region the GPU reads straddles the split. The private pool is a committed 1 MiBVirtualAllocrange, the only kind slot 133 aliases. Slots 0-2 hold neighbouring data. Every case first runs a previous user (D) on slots 3-4 through the same path and frees it. The buffer under test therefore sits at heap offset0x30000on a reused slot, and that slot must read zero through the title's views before the title fills it. Freed slots stay retired until the fence of their last submission.Paths:
share: one heap per pool. The section usesOpenExistingHeapFromFileMapping. The private range usesOpenExistingHeapFromAddresson its base, afterD3D12_FEATURE_EXISTING_HEAPS. A cross-adapter buffer is placed at the slot offset, and nothing is copied.copy: a default buffer fed from a two-slot upload ring. The ring wraps likereserve_upload_ring, but a slot still in flight is refused withDXGI_ERROR_WAS_STILL_DRAWING. The named copy point copies title memory into the ring atbind(asupload_from_title), atrecord(asframe_copy) or atsubmit, just beforeExecuteCommandLists, which is the contract point. The ring slot is copied into the buffer at the start of the submission. When a use declares GPU writes, the buffer is copied to readback at the end, and completion of that fence copies readback to title memory.fallback: sharing is forced to fail and the actual HRESULT is recorded. The section uses aFILE_MAP_READhandle; the private range uses an interior address. The path falls back to copy only when the copy can keep the guarantees. A GPU-written use with no completion point is refused with the sharing HRESULT.slot133: a model of today's slot 133 fallback. A non-MEM_PRIVATEaddress getsE_INVALIDARGbefore D3D12, and a committed default buffer stands in withS_OKand no copy. The oracle must catch this as a success whose backing holds neither the title's bytes nor a refusal.Cases:
ExecuteCommandLists. The GPU must read B.Waitorders the early query before the GPU write. The oracle isDXGI_ERROR_WAS_STILL_DRAWING, and the P words are its consequence.Distinct sentinels (A, B, C, D, E, G, P, filler, neighbour) make every observed word attributable.
Results
On commit
0e814819(based onmain82f0db65), Windows 11 build 26300, the D3D12 debug layer was tested off and on (X2W_TEST_DEBUG_LAYER=1). The results are identical on in-box WARP (1414:008c, 10.0.26100.9818) and on an AMD Radeon RX 9070 XT (1002:7550, driver 32.0.31044.16).D3D12_FEATURE_EXISTING_HEAPSis 1 on both. The run reports 40 passed, 0 failed, 0 skipped, 2 slot133 stand-ins caught, 0 probe failures, device removed reasonS_OK, and 0 debug-layer errors outside the deliberate refusals.0x30000S_OK0x887A000A, P 1024/1024, then G^key0x887A000A, ring slot 1 reused after the fence. d1b/d1r: A 1024/1024. d2:0x887A000A, then G^key0x80070057(FILE_MAP_READhandle)0x80070057, no resource; GPU-read falls back0x80070057(interior address)E_INVALIDARGbefore D3D12S_OK; b leaves P withS_OKS_OKSkips: none on either adapter.
Agreement: the paths agree on bytes and lifetime at the points the contract names (submit and fence completion). They do not agree at the production copy points. At
bindandrecord, the copy paths read the stale A while sharing reads B, so today's bind-time and record-time copies cannot stand in for sharing when the title writes between bind andExecuteCommandLists.Probes:
0x80070057on both adapters:OpenExistingHeapFromAddresson an interior address or a reserve-only range;OpenExistingHeapFromFileMappingthrough aFILE_MAP_READhandle; andCreatePlacedResourceat offset0x31000or past the end of the 256 MiB heap.OpenExistingHeapFromAddressaccepts a 128 KiBMEM_MAPPEDview of the section at+0x30000on both adapters. A buffer placed on that heap read the view's CPU writes in 1024/1024 words, and its GPU writes appeared through the split run in 1024/1024 words. Slot 133 refusesMEM_MAPPEDbefore calling D3D12.OpenExistingHeapFromAddressgives a 64 KiB heap. A 128 KiB buffer across the split is refused with0x80070057.existing_heapscache keeps it,VirtualFree(MEM_RELEASE)andVirtualFree(MEM_DECOMMIT)both fail with error 87 on both adapters. The range therefore cannot be recommitted at the same base. After the heap is released,VirtualFreesucceeds. With a cache that is never cleared, the observed hazard is that the title's free of that range fails. A later allocation reading a stale heap was not observed.Commands (PowerShell, after
. .\tools\dev.ps1):Negative controls
On both adapters, each mutant must fail every case that its guarantee protects. The run exits 1 only then. The controls are registered on WARP as
WILL_FAIL, and skip if a targeted case could not run.--mutate skip-refresh(copy pointbind): copy and fallback case a readA=1024/1024. 4 of 4 fail.--mutate skip-copy-back: copy and fallback cases b and d2 leaveraw P=1024/1024in the alias, with readback → title = 0. 8 of 8 fail.--mutate reuse-early(no fence checks on slots or the ring): on share, Y gets X's slots 3-4 and the held submission readsC=1024/1024. On copy and fallback, the wrap takes X's ring slot(taken)and the held submission readsE=1024/1024. 6 of 6 fail.S_OKis caught in both cases.Not covered
upload_from_titleorframe_copy. #1860 and slot 148 are unchanged.OpenExistingHeapFromAddressoverMEM_MAPPEDviews is supported by contract on other adapters, and what happens when the view is unmapped while that heap lives.🤖 Generated with Claude Code