runtime: check the struct-return adapter's refusals and heap type #1711
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1718"
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 Asimmimx on 2026-11-24T17:40:22Z.
Refs #1149.
Change
src/d3d12x_struct_return.hdeclaresd3d12x_struct_return::get_custom_heap_properties, the adapter for the struct-returningGetCustomHeapPropertiescall. It gets two candidate pointers and the live device, takes the candidate that is not the device as the output buffer, and writes the desktop method's result there. It returns that buffer, ornullptrwhen it cannot tell the two apart (src/d3d12x_struct_return.cpp).One test reaches it:
d3d12x_device_struct_return_warp(and its_hardwaretwin), thestruct-returnscenario oftests/d3d12x_device_check.cpp. It calls the adapter withD3D12_HEAP_TYPE_UPLOADand the device and output buffer in both orders, once with a stale vtable word in the buffer. Every call has exactly one candidate equal to the device, so none of thenullptrpaths ran, and only one heap type was used. 9 of 13 single-point mutants left the test passing (table below).New cases in
struct_return_checks, after the existing three (no existing case changed):defaultandreadback, device first and return buffer firstheap_typereaches the device. ADEFAULTheap has no CPU page property on any adapter, so its properties differ fromUPLOAD's. The check fails if they are equal on an adapter. On a cache-coherent UMA adapterUPLOADandREADBACKcan return the same properties, soREADBACKalone would not be enough.null_first:(nullptr, device)nullptrinstead of writing through a null pointernull_second:(device, nullptr)device_twice:(device, device)nullptrinstead of writing over the device objectneither_is_device: two buffers, each seeded with the device's vtable wordnullptrand writes neither buffer. Only the address comparison tells the buffers from the devicenull_device:(buffer, device)with a null live devicenullptrEach reject case also checks that both guarded buffers are unchanged byte for byte.
Negative control:
d3d12x_device_struct_return_neither_control_warpbuildstests/d3d12x_device_check.cppagainst a build-tree copy ofd3d12x_struct_return.cpp. In that copy the finalelsewrites through the second candidate (output = second;instead ofreturn nullptr;). CMake makes the copy with a regex that tolerates CRLF, stops withFATAL_ERRORif the anchor is gone, and re-runs when the source file changes (CMAKE_CONFIGURE_DEPENDS). The test usesPASS_REGULAR_EXPRESSION "FAIL: struct_return reject neither_is_device: returned "instead ofWILL_FAIL, so it passes only when the check reports this specific defect. A crash does not pass it. When run directly, the control printsFAIL: struct_return reject neither_is_device: returned 0000001F494FEE10 instead of nullptrafter the earlier cases pass, and exits 1.The change touches
tests/d3d12x_device_check.cpp(74 added lines), adds 21 lines toCMakeLists.txtdirectly after thed3d12x_device_*registrations and updates thed3d12x_device_struct_return_*row indocs/experiments.md. It also adds a row for the control there.src/d3d12x_struct_return.*is unchanged.Verification
Commit
37608bfcon18a2942a(main),devpreset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Microsoft Basic Render Driver (WARP) 10.0.26100.9818, debug layer enabled. No_hardwaretest was run.d3d12x_device_struct_return_warpnow prints 12struct_returnlines (3 existing, 4 heap-type, 5 reject) andd3d12x_device_check struct-return warp: PASS.tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --checkpassed.Mutation probe
I applied each mutation to
src/d3d12x_struct_return.cppalone, rebuiltd3d12x_device_check, rand3d12x_device_struct_return_warpand reverted. None of this is committed. For mutants that remove the control's anchor, I probed with theCMAKE_CONFIGURE_DEPENDSline taken out, so the configure guard would not stop the build.!devicetest dropped!firsttest dropped!secondtest droppedfirst == secondtest droppedFAIL: struct_return reject device_twice)firstneither_is_device)second(the control)neither_is_device)heap_typereplaced byD3D12_HEAP_TYPE_UPLOADdefault device_first)node_maskreplaced by0node_maskreplaced by1Not pinned
node_maskforwarding. The fixture device has one node, so masks 0 and 1 return the same properties, and other masks are invalid there. A multi-node adapter would be needed.!devicetest. With a null device, two distinct non-null candidates match neither branch, so the function returnsnullptreither way. Thenull_devicecase documents the contract but cannot kill this mutant.FAIL:line. The adapter writes through the null pointer before it returns, so the check cannot report first.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:46:59Z.
Review: COMMENTED
Review of head
37608bfc3f59d6fdaa9953f96480d8048be6f254. Changes:tests/d3d12x_device_check.cpp(+74), test-only CMake (a build-tree control target and one ctest entry), and a docs table row; no production code,src/d3d12x_struct_return.cppuntouched. Verdict: 0 P1, 0 P2.Linux limits. Linux x86_64. No Windows, no D3D12, no WARP, no DXC:
d3d12x_device_checkand the new control executable were not run, and neither was CMake configure/build of the repository. Below, the PR'sstruct_return_checksfunction was compiled verbatim with MinGW and run under wine against a fake device (a hand-built vtable whoseGetCustomHeapPropertiesreturns values derived from node mask and heap type), so heap-type pass-through and the address logic are exercised, the real desktop call is not.What I ran
x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -fsyntax-only tests/d3d12x_device_check.cpp(with a stub for the DXC-generatedd3d12x_pso_cs.h): no errors.struct_return_checks+ the real adapter, fake device, wine: all cases pass, including DEFAULT/READBACK in both orders and the five reject cases.struct_return reject neither_is_device: returned ..., which is the exact text the new CTest control requires.default device_first).first == secondallowed: FAILED (device_twice).!secondcheck dropped: caught, the run faults (null write).device_first: did not return the caller's output pointer).!devicecheck dropped: PASSED, not caught. I believe it is redundant: with a null device neither candidate can equal it, so the function returnsnullptranyway; thenull_devicecase passes either way.string(REGEX REPLACE "} else {(\r?\n +)return nullptr;" ...)anchor changes the real file when run in acmake -Pscript, and theFATAL_ERRORguard fires if it stops matching;d3d12x_pso_headeris defined above its use. ThePASS_REGULAR_EXPRESSIONtext matches the message the check prints.git diff --check,docs_links_check,bidi_controls_checkclean; no non-ASCII bytes in the diff. Existing assertions untouched (additions only after the existing loop).Notes
PASS_REGULAR_EXPRESSIONonly, so it passes when the line appears whatever the exit code; fine for a negative control, but it only runs on WARP.d3d12x_device_struct_return_{warp,hardware}and the new control).Not approving (comment only).
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:50:21Z.
Review: COMMENTED
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) and Linux at commit
37608bfc3f59d6fdaa9953f96480d8048be6f254(0 P1, 0 P2; test-only CMake + test + docs, zero production files changed, zero assertions weakened):git diff --check origin/main...HEAD: PASSpython3 tests/docs_links_check.py: PASS (17 Markdown files, 364 links)python3 tests/bidi_controls_check.py: PASS (1283 tracked files)--preset dev):cmake --build --preset dev --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap d3d12_xs_shim d3d12x_device_check d3d12x_device_struct_return_control -- -j 6: PASS (4.80s)ctest --preset dev -R '^(cpu_aot_trap|d3d12x_device_create_warp|d3d12x_device_negative_warp|d3d12x_device_struct_return_neither_control_warp|d3d12x_device_struct_return_warp|d3d12x_pso_reject_warp|d3d12x_pso_static_sampler_warp)$' --parallel 4 --no-tests=error --output-on-failure: 7/7 passed (1.83s)/O2(--preset release):cmake --build --preset release --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap d3d12_xs_shim d3d12x_device_check d3d12x_device_struct_return_control -- -j 6: PASS (3.12s)ctest --preset release -R '^(cpu_aot_trap|d3d12x_device_create_warp|d3d12x_device_negative_warp|d3d12x_device_struct_return_neither_control_warp|d3d12x_device_struct_return_warp|d3d12x_pso_reject_warp|d3d12x_pso_static_sampler_warp)$' --parallel 4 --no-tests=error --output-on-failure: 7/7 passed (1.83s)src/d3d12x_struct_return.cppon Win2025 (heap_type->D3D12_HEAP_TYPE_UPLOAD):d3d12x_device_struct_return_warpfailed as expected (FAIL: struct_return default device_first: pointer, guards or properties differ from the desktop call).d3d12x_device_struct_return_neither_control_warp(return nullptr;->output = second;): passed in both Debug and Release/O2.AI-assisted; commands listed were executed locally.