startup: repair invalid D3D12 calls that flood the debug layer #3199
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!3199
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3197"
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?
@tedin7 on GitHub · 2026-11-27 21:27 UTC · original
tedin7:up-debug-noise→main· +529 −44 · 8 files · 7 commits · openPart of #870
What this unblocks: runs with
X2W_D3D12_DEBUG=1keep the debug-layer log for real errors instead of filling it with repeated rejections of invalid calls the shim forwards.The startup device shim forwards several console requests that desktop D3D12 rejects, each with a debug-layer error (and the log budget of 400 lines ran out on them). This change repairs them before the desktop call:
ID3D12Device::CreateCommittedResource/CreatePlacedResource,D3D12_CLEAR_VALUE): dropped for buffers, for textures without render-target or depth-stencil use, for typeless formats and for a colour/depth kind mismatch; a depth clear outside [0, 1] is clamped. Applied at device slots 27/29, the committed-resource path and the title-memory texture path (optimized_clear_value.h).ID3D12Resource::Mapon a DEFAULT heap, or a CUSTOM heap withD3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE, answersE_INVALIDARGwithout the call.Unmapis forwarded only against a counted successful desktopMapof that subresource.descriptor_heap_rules.h): shader-visible CBV/SRV/UAV heaps are clamped to 1,000,000 descriptors and sampler heaps to 2048, the counts every Resource Binding tier guarantees ("Hardware Tiers"); the rest uses the existing CPU-only tail heap and title memory. RTV/DSV heaps dropSHADER_VISIBLE("Descriptor Heaps Overview"). The driver probe now starts at 1,000,000.debug_drain_budget.h): 4000 error/corruption lines plus 400 others, at most 32 lines per message id, then one "repeated N times" line at each power of two.Tests:
startup_debug_noise_check(pure): Map counting, every clear-value drop/clamp case, heap repairs, drain budget.startup_debug_noise_device_warp/_hardware(debug layer on,ID3D12InfoQueue1callback): creates a non-target texture with a clear value, a D32 target with depth 2.0, a buffer with a clear value, maps/unmaps a DEFAULT-heap texture, and creates a 1,048,577-descriptor view heap, a 4096 sampler heap and a shader-visible RTV heap through the shim. Passes only with zero debug-layer errors and no device removal; on main the invalid calls reach the runtime.Verification:
cmake -S . -B /tmp/up-debug-noise-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true-> configure OKx86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_debug_noise_check.cpp-> OKx86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_debug_noise_device.cpp-> OKpython3 tests/bidi_controls_check.py-> OK;python3 tests/startup_build_rev_check.py-> OK99cc8de8(pull/3197/head), dev and release legs in parallel:x2w_pipe.py win2025 3197 --targets startup_debug_noise_check,startup_debug_noise_device,startup_view_heap_check,startup_descriptor_increment,startup_title_heap_check,startup_resource_desc,startup_clear_depth_stencil,startup_clear_uav,startup_committed_heap_state_check,startup_descriptor_heap_type_check --regex '^startup_(debug_noise_.*|view_heap_.*|descriptor_.*|title_heap.*|resource_desc_.*|clear_depth_stencil_.*|clear_uav_.*|committed_heap_state.*)$' --forcestartup_view_heap_warp/_hardwareskipped (77: this adapter accepts the oversized heap directly)/O2: 21/23 passed, same two skipsstartup_debug_noise_device_warpfails witherrors: 1as requiredDraft until an independent peer review and the Win2025 WARP gate pass.
Thanks to @Makto94 for the testing that found this.
AI-assisted; commands listed were executed locally.
@R0Y00 on GitHub · 2026-11-27 21:39 UTC · original · reviewed
Draft review: the new
resource_mapsentries are removed only after matching Unmaps. D3D12 permits a CPU-accessible resource to stay mapped until its final release. This shim keeps wrapper addresses registered, so a successful persistent Map followed by Release leaves a nested map entry for the rest of the run. Please retire the entry at final resource release and cover a mapped-resource lifetime in the fixture. Also consider the allocation in++resource_maps[self][subresource]under a manually held SRW lock: an allocation failure after a successful desktop Map currently escapes the wrapper and leaves the lock held.The clear-value call sites overlap #3196. When refreshing the drafts, preserve the ordering of console-to-desktop format mapping before
safe_clear, including the distinct reserved-resource slot 30 clear-argument index. The existing format-118 fixture should still preserve a valid clear value after the two changes are combined.@tedin7 on GitHub · 2026-11-27 23:20 UTC · original
Pushed
2b71e99a5for both findings.ResourceMapCounts).E_OUTOFMEMORY, with the lock released.safe_clearand the slot 30 argument index when the draft is refreshed after #3196.Verification:
2b71e99a:x2w_pipe.py win2025 3197 --regex '^startup_debug_noise' --forcectest --preset dev3/3 passed; Release /O2 3/3 passed (startup_debug_noise_check,_device_warp,_device_hardwareon WARP).cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true,public_guard.py.AI-assisted; commands listed were executed locally.
@R0Y00 on GitHub · 2026-11-27 23:38 UTC · original · reviewed
I independently retested the revised
2b71e99aovermainfad97f47(clean trial tree0a8a1993). The previous Map lifetime findings are addressed: final resource release retires the tracked entries, and an allocation failure after a successful desktop Map now unmaps, returnsE_OUTOFMEMORY, and releases the lock. The helper fixture covers retirement and reuse of the same address, and the device fixture releases a persistently mapped upload resource without an explicit Unmap.I built
startup_debug_noise_check startup_debug_noise_device d3d12_xs_shimand ranctest --test-dir <build> --no-tests=error -j1 -V -R '^startup_debug_noise_(check|device_(warp|hardware))$'in Debug and Release /O2: 3/3 each, no skips. WARP 10.0.26100.9818 and RTX 4060 Laptop (32.0.16.1656) on Windows 11 26200.9974 both reported zero debug-layer errors and no device removal. The separate clear-value coordination with #3196 still applies when that draft changes the shared call sites.@KelboLive on GitHub · 2026-11-27 23:51 UTC · original
Review of
2b71e99a(integrated over main):@tedin7 on GitHub · 2026-11-28 10:49 UTC · original
Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11):
Tested at
99cc8de. The current head is2b71e99, so commits pushed after the tested sha are not covered by this run. dev preset, ctest run one test at a time:These complement the existing WARP runs.
AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:49 UTC · original · edited 2026-11-28 10:56 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
2b71e99ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:56 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
2b71e99a5eℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:56 UTC · original
On
src/startup_stubs/descriptor_heap_rules.hline 15 (outdated):With
X2W_D3D12_RENDER=1on an adapter that accepts the full request, this unconditional clamp breaks previously supported UAV clears, even with debugging disabled. Such adapters are recorded indocs/startup-runtime.md:2714-2715. Ind3d12_xs_device.cpp,owning_view_heap()recognizes onlyheap.countphysical descriptors, andlist_clear_uav()refuses GPU handles outside that range. Consequently, a clear at descriptor index 1,000,000 or above is now dropped even when its matching CPU descriptor is in a valid staging heap. The CPU-only tail preserves descriptor writes but cannot service this GPU operation; tail descriptors need a shader-visible clear path before applying the clamp unconditionally.Useful? React with 👍 / 👎.
@ -449,3 +448,1 @@++debug_lines;log("x2w-d3d12-debug [%s %d] sev=%d id=%d %.900s", context, slot, message->Severity, message->ID,message->pDescription);const auto decision = debug_budget.record(message->Severity, message->ID);@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:56 UTC · original
With
X2W_D3D12_DEBUG=1, recording a previously unseen message ID now allocates throughDebugDrainBudget::counts_[id]. If that allocation fails,std::bad_allocescapes this call whiledebug_lockis held, bypassing its release and the normal HRESULT return from the shim. This can terminate the caller, or permanently block subsequent drains if an outer handler catches the exception. Allocation failure was reproduced against the new helper; the previous fixed-size drain required no bookkeeping allocation. Make budget recording best-effort and ensure the lock is released on failure.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:56 UTC · original
On
src/startup_stubs/d3d12_xs_device.cppline 334 (outdated):If the fallback can create a heap with 65,536–124,999 descriptors but not 125,000, the new halving sequence never discovers that usable capacity: it probes 1,000,000, 500,000, 250,000 and 125,000, then exits because 62,500 is below
view_heap_probe_floor. It consequently caches a zero limit and leaves heap creation failing for subsequent requests. The parent sequence explicitly reached 65,536, so this is a regression caused by changing the ceiling away from a power of two. Probe the floor separately or clamp the last halving step to it before recording failure.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:56 UTC · original
On
CMakeLists.txtline 1776 (outdated):These new registrations bypass the layout documented in
AGENTS.md: “One<family>.cmakefile per test family or pull request.” The referencedtests/cmake/README.mdexplicitly requires newadd_testandset_tests_propertiescalls to go in a family fragment so independent changes do not edit the same central registration file. Move both new debug-noise registrations and their properties intotests/cmake/startup_debug_noise.cmake, which the existing glob automatically includes; the executable target definitions can remain here.AGENTS.md reference: AGENTS.md:L302-L302
Useful? React with 👍 / 👎.
@tedin7 on GitHub · 2026-11-28 11:11 UTC · original
On
src/startup_stubs/descriptor_heap_rules.hline 15 (outdated):Valid, fixed in
2bc79c94bon up-debug-noise. The clamp to 1,000,000 now applies only below resource binding tier 3. The D3D12 resource binding spec lists tier 3 as 1000000+, so on a tier 3 device (CheckFeatureSupport OPTIONS, ResourceBindingTier) a request up to 2^20 = 1,048,576 is kept as asked, the physical heap keeps its descriptors past 1,000,000, and list_clear_uav still resolves them. If the driver refuses the size, the existing probe still shortens it. Larger requests are still clamped (to 1,048,576 on tier 3). Test: startup_debug_noise_check covers the limit parameter of safe_heap_desc (1,000,000 default, 1,048,576 for tier 3).Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head
2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails.AI-assisted; commands listed were executed locally.
@ -449,3 +448,1 @@++debug_lines;log("x2w-d3d12-debug [%s %d] sev=%d id=%d %.900s", context, slot, message->Severity, message->ID,message->pDescription);const auto decision = debug_budget.record(message->Severity, message->ID);@tedin7 on GitHub · 2026-11-28 11:11 UTC · original
Valid, fixed in
2bc79c94b. DebugDrainBudget::record is now noexcept and best effort: if the per-id counter cannot be allocated it catches std::bad_alloc and drops the line (Decision::suppress), so nothing is thrown while debug_lock is held. Test: startup_debug_noise_check replaces operator new, makes it fail while a new message id is recorded, and checks that the call returns suppress and that the id is counted normally afterwards.Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head
2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-28 11:11 UTC · original
On
src/startup_stubs/d3d12_xs_device.cppline 334 (outdated):Valid, fixed in
2bc79c94b. The halving now goes through largest_halving_size() in descriptor_heap_rules.h, which clamps the last step to the floor and probes it explicitly, so a driver whose limit lies between 65,536 and 124,999 is found (1,000,000, 500,000, 250,000, 125,000, then 65,536). Test: startup_debug_noise_check checks limits of 100,000 (found as 65,536), 300,000 (250,000), a driver that refuses everything (0) and exactly 65,536.Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head
2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-28 11:11 UTC · original
On
CMakeLists.txtline 1776 (outdated):Valid, fixed in
2bc79c94b. The add_test calls for startup_debug_noise_check and startup_debug_noise_device_{warp,hardware}, with their set_tests_properties, moved to tests/cmake/startup_debug_noise.cmake. CMakeLists.txt keeps the executable targets and a pointer comment. cmake -S . -B -DDXC_EXECUTABLE=/bin/true configures and the three tests are registered; the gate above ran them from the fragment.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-28 21:58 UTC · original
Merged current
maininto this branch (merge commit, no force push); head is nowa46c69db8. One conflict inresource_unmap: main added a compute-output trace call at the top, this PR the guarded unmap; both are kept, the trace first.The four review findings were already fixed in
2bc79c94b(see the thread replies).Verification (Windows Server 2025, D3D12 WARP, head
a46c69db8):x2w_pipe.py win2025 3197 --regex '^startup_(debug_noise_.*|view_heap_.*|descriptor_.*|title_heap.*|resource_desc_.*|clear_depth_stencil_.*|clear_uav_.*|committed_heap_state.*)$'-> 23/23 passed.@MasterDomino ready for review and merge when you have time.
AI-assisted; commands listed were executed locally.
@pigalot on GitHub · 2026-11-29 12:07 UTC · original · requested changes
Reviewed
a46c69dbagainstmaina30437f7. The branch no longer merges: #3196 (ae45c4ff) landed onmainafter this head was pushed and changed the same clear-value call sites. GitHub reports the PR asCONFLICTING.git merge --no-ff --no-commitofa46c69dbontoa30437f7conflicts insrc/startup_stubs/d3d12_xs_device.cppin four places; every other file merges cleanly andgit diff --checkis clean.mainaddsclear_value_format.h; this PR addspacked_target_format.h,debug_drain_budget.h,descriptor_heap_rules.handoptimized_clear_value.h.create_slot:mainnow handles slots 27, 29 and 30 withx2w_startup::desktop_clear_value(...)and a per-slot clear argument index (N == 30 ? 2 : 4); this PR handles 27 and 29 only, throughpacked_clear_value(...)andargs[4].device_place_resource(the title-memory texture path):desktop_clear_value(clear, desc->Format, texture.Format, ...)onmainagainstpacked_clear_value(clear, desktop_format(desc->Format), texture.Format, ...)followed bysafe_clearhere.create_committed: the same pair of calls.Taking this PR's side of the hunks would not build either:
packed_clear_valueno longer exists onmain(no match undersrc/ortests/);desktop_clear_valueinclear_value_format.hreplaced it and takes the title's unmapped desc format.Requested change: merge
mainand resolve these so the format mapping from #3196 runs first andsafe_clearis applied to its result, as asked in the review of99cc8de8. Concretely:desktop_clear_value(...)at all three sites and pass its result tosafe_clear(...)with the desc that is really created.create_slot, keepmain's slot 30 case and its clear index 2. Slot 30 (CreateReservedResource) takes the sameD3D12_CLEAR_VALUE, so it should go throughsafe_clearas well, or the PR should say why it is left out. A device-fixture case for a reserved resource with an invalid clear value would cover it.startup_clear_depth_stencil) has to keep a valid clear value after the two changes are combined.optimized_clear_valuetreatsD24_UNORM_S8_UINTas a depth format, so I expect it to, but I have not run it.What I did not do: because the branch cannot be built on current
main, I did not build it, run its tests, run mutants, or ask for a title run at this head. I will do those on the next head. I readoptimized_clear_value.handclear_value_format.hfor the notes above, and nothing else in the diff in depth.The four inline threads (tier 3 heap sizes, non-throwing drain budget, capacity floor probe, registrations in a fragment) were answered with
2bc79c94; I have not verified those fixes yet and they are still open on the PR.Environment: Windows 11 25H2 build 26200.9974; git trial merge only, nothing built.
CI:
Build and test on Windowspassed ona46c69db, before #3196 landed.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 13:05 UTC · original
Review of head
a46c69dbagainstmain94b679e7. I read the source and ran trial merges only; I did not build or run anything.MUST
main.git merge-tree --write-tree origin/main a46c69dbexits 1 withCONFLICT (content): Merge conflict in src/startup_stubs/d3d12_xs_device.cpp, 4 hunks. These are the four hunks pigalot lists, and pigalot's review already gives the resolution (#3196'sdesktop_clear_valuefirst, thensafe_clear, slot 30 included). I have nothing to add to it.On the default launcher path
run.shandrun.ps1do not setX2W_D3D12_DEBUG:git grep -l X2W_D3D12_DEBUG origin/main -- tools/finds no file. So the drain budget only changes opt-in debug runs. TheMap/Unmapguard, the clear-value drops and the heap repairs are on with no switch.main, the first 16 loggedCreateDescriptorHeapcalls hold one shader-visible CBV/SRV/UAV heap of 1,245,184 descriptors. The rest are CPU-only heaps and one 128-entry shader-visible sampler heap. None is a shader-visible RTV/DSV heap or a sampler heap above 2048. On a tier 3 device that accepts 1,048,576, this PR's clamp gives the same size asmain's probe path. A driver that takes only 1,000,000 also ends at the same size. On this path the heap change just removes the failed first create. That matches what the body says.NIT
resource_map_lockis one exclusive lock held across every desktopMap:AcquireSRWLockExclusive(&resource_map_lock); hr = !real ? E_FAIL : cpu_hidden ? E_INVALIDARG : real->Map(subresource, range, &mapped);. That serializesMapcalls from all threads. Only the count needs the lock.Mapcould run first, then the lock could cover justrecord, with the existingUnmaponbad_alloc. A title cannotUnmapa subresource before itsMaphas returned, so nothing races.safe_clearlogsx2w-d3d12 optimized clear dropped reason=%uonce per reason, with no clear format, desc format or dimension. Printing those once per reason would show which console clear values are being dropped.AI-assisted.
github-bot referenced this pull request2026-11-30 02:46:04 +00:00
@tedin7 on GitHub · 2026-11-30 13:58 UTC · original
Merged current
main(077bff3ac) and addressed the map-lock and clear-value comments. Ready for CI and re-review.@R0Y00 on GitHub · 2026-12-03 03:49 UTC · original · requested changes
The four clear-value conflicts are resolved at
fe1af87b. In a clean trial merge withmain41a83a9a,desktop_clear_valueruns beforesafe_clearon the creation paths, and slot 30 keeps clear argument index 2.startup_debug_noise_checkand bothstartup_clear_depth_stencilcases passed, including format 118 mapped to DXGI 45 and depth readback of 0.25/0.75 with zero debug errors on WARP and RTX 4060 Laptop.One current blocker:
startup_debug_noise_device_warppasses, butstartup_debug_noise_device_hardwarefails on the RTX 4060 Laptop. The fixture requests 1,048,577 shader-visible CBV/SRV/UAV descriptors.device_create_descriptor_heapuses the Tier 3 shortcut and sends 1,048,576 to the first desktopCreateDescriptorHeapcall. Its debug callback reportsNumDescriptors 1048576, but the limit for shader visible view heaps is 1000000. The retry succeeds at 1,000,000 and the device remains healthy, but the first error is exactly what this PR's fixture requires to avoid. A local diagnostic changing only the fixture request to 1,000,000 passed with zero errors. Please keep the oversized fixture and ensure the first call respects adapters whose effective limit is 1,000,000, while preserving the larger path where support is established.MSVC Debug:
ctest --preset dev --no-tests=error -j 1 -V -R '^(startup_debug_noise_(check|device_(warp|hardware))|startup_clear_depth_stencil_(warp|hardware))$', four passed, one failed, no skips. Windows 11 build 26300, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656, debug layer enabled for the device cases.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.