startup: validate title UAV, RTV and DSV views before forwarding #3202
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!3202
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3200"
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:29 UTC · original
tedin7:up-target-view-check→main· +460 −3 · 7 files · 5 commits · openPart of #870
What this unblocks: title UAV, RTV and DSV views that D3D12 would reject are repaired or refused before they reach the desktop device, so real GPUs and the debug layer stop failing on them.
Console view descriptions can name a MipSlice past the resource, an array or W range longer than what remains, a PlaneSlice on a single-plane format, a view format outside the resource's format family, a DSV with a color or UNKNOWN format, a read-only-stencil DSV on a format without stencil, a multisample dimension on a single-sample resource (or the reverse), a multisample UAV, or a UAV counter on a resource or offset D3D12 does not allow (see "ID3D12Device::CreateUnorderedAccessView", "ID3D12Device::CreateRenderTargetView", "ID3D12Device::CreateDepthStencilView" and "D3D12_UNORDERED_ACCESS_VIEW_DESC" on Microsoft Learn). Forwarding these breaks the debug layer and can remove the device on hardware.
The new header
src/startup_stubs/target_view_check.hchecks device slots 19-21 after the existing dimension and format checks inview_slot:CastingFullyTypedFormatSupported), DSV format replaced by the resource's depth format, read-only-stencil flag dropped without a stencil plane, a counter offset without a counter resource reset to 0,The depth-format and format-cast helpers are local to this header; if the sibling SRV validation draft lands first, the two share one copy.
Tests:
startup_target_view_check(CPU): valid descriptions stay byte-identical; each repair and each refusal above.startup_target_views_warp(title view calls through the shim on a WARP device with the debug layer on; passes only with zero debug-layer errors and no device removal; without the new check inview_slotthe bad MipSlice RTV reaches the debug layer and removes the WARP device, see Verification).startup_target_views_hardwareskips (77) without a hardware adapter.Verification:
x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Wall -Isrc tests/startup_target_view_check.cpp-> OKx86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_target_views_device.cpp-> OKcmake -S . -B <tmp> -G Ninja -DDXC_EXECUTABLE=/bin/true-> configure OKpython3 tests/bidi_controls_check.py-> passed9e6d28f7, targetsd3d12_xs_device_obj d3d12_xs_shim startup_target_view_check startup_target_views_device startup_view_dimension startup_null_views_check startup_resource_retire_views:ctest --preset dev -R '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)'-> 18/18 passed/O2): same regex -> 18/18 passedview_slotcheck reverted (tests kept),ctest --preset dev -R '^startup_target_views_warp$'-> 0/1 passed (debug layer:CreateRenderTargetView ... MipSlice (value = 9), then device removed0x887a0001)Draft 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.
@KelboLive on GitHub · 2026-11-27 23:44 UTC · original · approved these changes
Review of PR #3202 — startup: validate title UAV, RTV and DSV views before forwarding
Summary
This PR adds
src/startup_stubs/target_view_check.h— a device-independent validation library for D3D12 target views (UAV, RTV, DSV). It validates view descriptors against their underlying resources, repairing invalid fields when possible and refusing when fundamentally incompatible.Changes reviewed
src/startup_stubs/target_view_check.h: New 167-line header withcheck()template function for UAV/RTV/DSV validation. Includes format cast fitting logic (respecting typeless casting rules), planar video format handling, depth-stencil aspect selection, mip/array bounds checking, counter placement validation (check_uav), and repair callback pattern.d3d12_xs_device.cppapplies this validation before forwarding views to the desktop device, with refusal counting for diagnostics.Assessment
The implementation is thorough and well-designed:
constexpr if.check_uavensures proper alignment and size for structured buffer counters.Verdict: Approve
@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
9e6d28f(current head). 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:55 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
9e6d28fℹ️ 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:55 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
9e6d28f7bfℹ️ 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".
@ -5184,0 +5238,4 @@}if (view) {std::memcpy(desc_copy, view, sizeof(*view));args[desc_index] = reinterpret_cast<u64>(desc_copy);@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:55 UTC · original
When a UAV is repaired,
record_view(created)still callsnote_viewwith the originalc, not the repaired description.record_translated_dispatch()reads that record ind3d12_compute_dispatch.inl:473–520and recreates the UAV at lines 622–623 without this validation. For example, anR32_FLOATview on anR8G8B8A8_UNORMresource is repaired initially, but the incompatibleR32_FLOATdescription is forwarded again during dispatch, reintroducing the debug-layer/device-removal failure. Repaired array sizes and plane slices can instead cause the dispatch to be refused. Store the effective description for downstream consumers rather than changing only the initial native-call arguments.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:55 UTC · original
On
src/startup_stubs/target_view_check.hline 131 (outdated):On hardware supporting NV12 RTV/UAVs, legal plane views use
R8_UNORMfor plane 0 orR8G8_UNORMfor plane 1, notNV12. Those formats are not in the resource's typeless format family, soformat_cast_fits()returns false and this branch replaces a legal view format withNV12. The resulting invalid view is then forwarded to D3D12, introducing a device-removal path for descriptions that previously passed through unchanged; P010/P016 plane views have the same problem. Account for resource/plane/view-format compatibility before applying the generic format-family fallback.Useful? React with 👍 / 👎.
@ -5184,0 +5238,4 @@}if (view) {std::memcpy(desc_copy, view, sizeof(*view));args[desc_index] = reinterpret_cast<u64>(desc_copy);@tedin7 on GitHub · 2026-11-28 11:05 UTC · original
Valid, fixed in
f67d16272onup-target-view-check.record_view()now stores the description that was actually forwarded (the repaired copy) for slots 19, 20 and 21, so the translated dispatch (d3d12_compute_dispatch.inl) recreates the UAV from the repaired description and no longer sends the original one again.Test:
startup_compute_dispatch_texture_check.pyhas a new casetexture-store-viewfmt(a UAV with an incompatibleR32_FLOATview format over an RGBA16_FLOAT texture, then a translated dispatch). It checks the readback and that the debug layer stays silent.Gate on aws-1 with WARP (
x2w_pipe.py win2025 3200 --host aws-1 --regex 'startup_target_view|startup_compute_dispatch_texture' --force, headf67d1627): dev 5/5 and release 5/5 passed. Mutants run after the main gate: reverting the record fix failsstartup_compute_dispatch_texture_warpand_hardware(dev and release); removing the planar rule failsstartup_target_view_check(NV12 plane 0, NV12 plane 1, P010 plane 1).AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-28 11:06 UTC · original
On
src/startup_stubs/target_view_check.hline 131 (outdated):Valid, fixed in
f67d16272.target_view_check.hhas a newplanar_view_fits(): for NV12 plane 0R8_UNORMand plane 1R8G8_UNORM, for P010/P016 plane 0R16_UNORMand plane 1R16G16_UNORMare kept as they are. This is the plane-format rule in the D3D12 resource binding spec (planar formats). Any other format on a planar resource is still repaired to the resource format. The format check now allows a view when eitherformat_cast_fits()orplanar_view_fits()is true.Test:
startup_target_view_check.cppcovers NV12 plane 0 and 1, plane 1 with the plane 0 format (repaired), P010 plane 1, and an unrelated P010 format (repaired).Gate on aws-1 with WARP (
x2w_pipe.py win2025 3200 --host aws-1 --regex 'startup_target_view|startup_compute_dispatch_texture' --force, headf67d1627): dev 5/5 and release 5/5 passed. Mutants run after the main gate: reverting the record fix failsstartup_compute_dispatch_texture_warpand_hardware(dev and release); removing the planar rule failsstartup_target_view_check(NV12 plane 0, NV12 plane 1, P010 plane 1).AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-28 22:22 UTC · original
Merged current
maininto this branch (merge commit, no force push); head is now78c320f56. One conflict insrc/startup_stubs/d3d12_xs_device.cpp(record_view): kept main'sViewRecord::srv_desc_bytes/uav_desc_bytessizes and this PR's repaired-description pointer passed tonote_view.Both automated review findings were already fixed in
f67d16272(see the replies in the threads: the record keeps the repaired description, andplanar_view_fits()allows the legal plane formats).Verification (Windows Server 2025, D3D12 WARP, PR head
78c320f56, dev and release):x2w_pipe.py win2025 3200 --regex '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)'-> 18/18 passed in both legs.@MasterDomino ready for review and merge when you have time.
AI-assisted; commands listed were executed locally.
@pigalot on GitHub · 2026-11-29 08:50 UTC · original · requested changes
Independently reviewed
78c320f5integrated overmain7c123092(tree01e2b13c). The trial merge is clean andgit diff --checkis clean.I read
target_view_check.hagainst theview_slotpath and the record consumers (view_format_of,resolve_view, the translated dispatch), and compared its verdicts with what desktop D3D12 accepts, using a standalone probe that creates each view on a fresh debug-layer device and callscheck/check_uavon the same description.Blocking: legal 32-bit UAV casts are refused or rewritten. D3D12 lets a UAV name
R32_UINT,R32_SINTorR32_FLOATover a 32-bit texture of another format family.format_cast_fits()starts withcompatible_formats(), which is family equality, so these never fit. Onmainthey are forwarded unchanged (slot 19 has no format check there).ALLOW_UNORDERED_ACCESS)check_uavat78c320f5R8G8B8A8_TYPELESSR32_UINTRefusal::formatR8G8B8A8_TYPELESSR32_FLOATRefusal::formatR10G10B10A2_TYPELESSR32_UINTRefusal::formatR16G16_TYPELESSR32_UINTRefusal::formatB8G8R8A8_TYPELESSR32_UINTRefusal::formatR8G8B8A8_UNORM(CastingFullyTypedFormatSupported= 1)R32_UINTR8G8B8A8_TYPELESS(control)R8G8B8A8_UNORMR8G8B8A8_TYPELESS(control)R16G16B16A16_FLOAT0x887a0001Refusal::formatThe results are the same on WARP and on the hardware adapter below. So a view that works today is skipped (first five rows), and in the typed case the title's
R32_UINTview silently becomes anR8G8B8A8_UNORMone, which changes what a shader reads and writes through it.To reproduce without a device, add to
tests/startup_target_view_check.cpp:It fails at
78c320f5withFAIL: R32 UAV over a 32-bit family. Suggested direction (unconfirmed beyond the rows above): for UAVs, letR32_UINT/R32_SINT/R32_FLOATpass over the 32-bit families D3D12 allows, next toplanar_view_fits(), with a device case instartup_target_views_device.cppso the debug layer confirms it. I did not testB8G8R8X8_TYPELESSorR32_SINT.What I ran. Built all targets in
devandrelease, thenctest --test-dir out/build/<preset> --no-tests=error -j 4 -E '_hardware$|startup_audio' -R '^(startup_target_view_check|startup_target_views_warp|startup_view_dimension.*|startup_null_views_.*|startup_resource_retire_views_.*|startup_compute_dispatch_texture_warp|startup_compute_dispatch_warp|startup_packed.*)$':28/28 passed in Debug and Release
/O2, no skips. Under the GPU lock with-j 1andX2W_TEST_DEBUG_LAYER=1,startup_target_views_hardwareandstartup_compute_dispatch_texture_hardwarepassed in both presets, no skips.Negative control: with the refusal in
view_slotdisabled (if (false && refusal != Refusal::none)),startup_target_views_warpfails (the debug layer reports the views and the device is removed with0x887a0001; the process then exits0xc0000409).The record change is sound as far as I traced it: the record now holds the description that was forwarded (desktop format, repaired fields), and the consumers that map the format again (
view_format_of, the dispatch) are unaffected becausedesktop_format()maps its outputs to themselves.Mutants (dev; CPU test, plus
startup_target_views_warpandstartup_compute_dispatch_texture_warpwhere marked "device"):Killed (13):
*p.mip >= r->MipLevels->>(device; the CPU test does not catch it, only the mip-4 UAV in the WARP test does)*p.first >= limit->>~0exception removedWidth - 4->Widthview_slotignores the refusal (device)startup_compute_dispatch_texture_warp)Surviving (5), all with the device tests included; none blocks on its own, but they are untested rules:
ArraySize/WSizerefusal removed (!*p.count)*p.plane > 1->> 2(no plane-2 case on a planar resource)D32_FLOAT_S8X24_UINT(onlyD24_UNORM_S8_UINTis covered)CastingFullyTypedFormatSupported(no test passestyped_cast)Equivalent: none found.
Smaller notes, not blocking:
check()names only the UAV and DSV descriptions; it also handles RTVs.Real-title run of this head merged onto the baseline commit: flaky. It was judged worse than the baseline on the first run (
[fail] judgement: Judged worse than the baseline: black-frame) and passed on the re-run ([warn] repeat: Failed on the first run and passed on a re-run (job 28).). That does not block on its own.Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; NVIDIA GeForce RTX 5090 driver 32.0.16.1088, D3D12 debug layer on; WARP for the
_warptests.CI:
Build and test on Windowspassed on78c320f5.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 13:05 UTC · original
Review of head
78c320f5againstmain94b679e7. I read the source and ran trial merges only; I did not build or run anything.git merge-tree --write-tree origin/main 78c320f5exits 0.Status: pigalot's change request on this head is still open, with no push or reply since. In that finding, legal
R32_*UAV casts are refused, or rewritten to the resource format. That holds the merge, so I am not merging. I have nothing to add to the cast rule itself.SHOULD
A refused RTV, DSV or UAV keeps the slot's previous view.
refuse_viewwrites a null view only for slot 18. The comment above it says: "A skipped UAV, RTV or DSV does not write a replacement to the desktop heap, so its previous descriptor record must stay live." This PR sends many more slot 19-21 calls down that path, with no switch on the default launcher path.OMSetRenderTargetsand draws into whatever view was there before. The only trace is the first 6x2w-d3d12 view refused: slot%d %slines per reason.maintoday reach this path, so a wrong refusal costs more than an empty target.Could the refusals this PR adds write a null RTV, DSV or UAV of the requested dimension too? If keeping the old view is the safer choice for one of them, the body could say why.
NIT
CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, ...)runs on each slot 19-21 call whose format differs from a typed resource's format.CastingFullyTypedFormatSupporteddoes not change for a device, so one query per device would do.main): with this PR in, #3201 conflicts ind3d12_xs_device.cpp(view_slot). #3216 then conflicts inCMakeLists.txt,d3d12_xs_device.cppandd3d12_draw.inl, where the last is its existing conflict withmain. The body already says the depth-format and cast helpers should be shared with the SRV draft. Settling the order now would also settle which PR keeps those helpers.AI-assisted.
@tedin7 on GitHub · 2026-11-30 14:05 UTC · original
Merged current
main(077bff3ac) and fixed the cross-family R32 UAV typeless cast check (with a regression test covering legal R32 UAV casts while keeping invalid casts refused). Ready for CI and re-review.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.