startup: sanitize D3D12 sampler descriptions before they reach the desktop device #3201
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!3201
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3199"
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-sampler-sanitize→main· +280 −13 · 9 files · 6 commits · openPart of #870
What this unblocks: title and translated samplers no longer reach the desktop device with values D3D12 rejects, so real GPUs and the debug layer stop failing those draws.
Console sampler descriptions can carry values that D3D12 does not accept: an anisotropic filter with MaxAnisotropy 0 or above 16, MinLOD above MaxLOD, a MipLODBias outside [-16, 15.99], a comparison filter with no valid comparison function, address modes outside 1..5, or border colors outside [0, 1] (see "D3D12_SAMPLER_DESC (d3d12.h)" and "D3D12_STATIC_SAMPLER_DESC (d3d12.h)" on Microsoft Learn). WARP is lenient with several of these; the debug layer and hardware drivers are not.
The new header
src/startup_stubs/sampler_desc_check.hrepairs such a description on a copy and keeps every field the selected filter ignores. It runs at:CreateSampler(device slot 22); an unreadable description is refused instead of forwarded,decode_statics) and dynamic samplers (dynamic_sampler),A reversed LOD pair takes MinLOD = MaxLOD:
min(max(lod, MinLOD), MaxLOD)already yields MaxLOD for every lod, so the sampled result does not change. The decoder still reports both title fields unchanged.Tests:
startup_sampler_desc_check(CPU): valid descriptions stay byte-identical; each invalid field is repaired and reported, for dynamic and static samplers.startup_sampler_device_warp(titleCreateSamplercalls 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 at slot 22 the debug layer rejects MaxAnisotropy 64, MipLODBias 20 and AddressU 0 and removes the WARP device, see Verification).startup_sampler_device_hardwareskips (77) without a hardware adapter.startup_translated_sampler_bindingsandstartup_sampler_comparisonupdated: a reversed dynamic or static LOD pair now has MinLOD = MaxLOD; the first smpl fixture uses an ordered pair so both fields keep their decode check.Verification:
x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_sampler_desc_check.cpp-> OKx86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_sampler_device.cpp-> OKx86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc -x c++ -include d3d12.h src/startup_stubs/plane_compositor.h-> OKcmake -S . -B <tmp> -G Ninja -DDXC_EXECUTABLE=/bin/true-> configure OKpython3 tests/bidi_controls_check.py-> passed771ba414, targetsd3d12_xs_device_obj d3d12_xs_shim d3d12x_device_check native_recording_check offscreen_check startup_sampler_comparison_check startup_sampler_desc_check startup_sampler_device startup_translated_sampler_bindings_check startup_present_composite_warp:ctest --preset dev -R 'sampler|^startup_present_composite_warp$|native_recording|binding_mips'-> 34/38 passed, 4 skipped (SPIR-V sampler tests matched by the regex, not built in this target set)/O2): same regex -> 34/38 passed, same 4 skippedctest --preset dev -R '^startup_sampler_device_warp$'-> 0/1 passed (debug errors=4 removed=0x887a0001)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.
@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
771ba41(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:53 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
771ba41ℹ️ 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:53 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
771ba4143aℹ️ 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".
@ -0,0 +21,4 @@const unsigned basic = filter & ~0x180u;if ((filter & ~0x1d5u) || (basic != 0x55u && (basic & ~0x15u))) {filter = (filter & 0x180u) | 0x15u;s.Filter = static_cast<D3D12_FILTER>(filter);@chatgpt-codex-connector[bot] on GitHub · 2026-11-28 10:53 UTC · original
On a device advertising
AnisoFilterWithPointMipSupported,D3D12_FILTER_MIN_MAG_ANISOTROPIC_MIP_POINT(0x54) and its reduction variants are valid filters. This predicate rejects those encodings, so a valid sampler submitted through device slot 22 is now rewritten to 0x15 (or its reduction variant), removing anisotropy and replacing point mip selection with linear mip blending. Recognize both 0x54 and 0x55 as anisotropic base encodings, including in the subsequent anisotropy-range check, so sanitization preserves valid sampling behavior.Useful? React with 👍 / 👎.
@tedin7 on GitHub · 2026-11-28 11:10 UTC · original
On
src/startup_stubs/sampler_desc_check.hline 24 (outdated):Valid, fixed in
122ddf3c4onup-sampler-sanitize.sampler_desc_check.hnow treats both0x55and0x54(anisotropic with a point mip filter, plus the reduction bits) as anisotropic. Both the filter-shape check and theMaxAnisotropyrange check use the same predicate, so a valid0x54sampler keeps its filter and its anisotropy.Test:
startup_sampler_desc_check.cpphas two new cases, an untouched0x54and0x154(minimum reduction) description, and a0x54sampler withMaxAnisotropy = 0that is clamped to 1 while the filter stays0x54.Gate on aws-1 with WARP (
x2w_pipe.py win2025 3199 --host aws-1 --regex startup_sampler --force, head122ddf3c): dev and release 17/17 passed. Mutant (the old== 0x55predicate), run after the main gate:startup_sampler_desc_checkfails in dev and release.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-28 22:08 UTC · original
Merged current
maininto this branch (merge commit, no force push, no conflicts); head is now32754bec2. The anisotropic-filter finding was already fixed in122ddf3c4.Verification (Windows Server 2025, D3D12 WARP, head
32754bec2):x2w_pipe.py win2025 3199 --regex '^startup_sampler_'-> 17/17 passed.@MasterDomino ready for review and merge when you have time.
AI-assisted; commands listed were executed locally.
@Alexofbulgaria on GitHub · 2026-11-29 05:15 UTC · original
Windows Arc A770 validation at
32754becI built a clean, separate checkout of exact head
32754bec269122fecb55505b9d007fea35568a7b, Release, with MSVC 19.44.35230 and Windows SDK 10.0.26100.0. Windows26300.10075, Intel Arc A7708086:56a0, driver32.0.101.9175. WARP runtime10.0.26100.10068.startup_sampler_desc_checkstartup_sampler_device_hardware0x00000000startup_sampler_device_warp0x00000000Each ran once, serially, with zero skips. Both device logs explicitly show the D3D12 debug layer enabled and
build=32754bec. The descriptor control verifies byte-identical valid anisotropic descriptions, including0x54and0x154, and the invalid-0x54anisotropy clamp. Warning counts were not measured; the device fixture counts corruption/errors. This checks descriptor preservation and sampler creation, without claiming rendered sampler-output coverage.I configured with
CMAKE_TRY_COMPILE_CONFIGURATION=Release, built onlystartup_sampler_desc_checkandstartup_sampler_device, and ran each registered test withctest --test-dir <build> --no-tests=error -R '^<test>$' -j1 -V. Source remained clean. Raw logs, JUnit results, environment and binary hashes are preserved locally.AI-assisted: yes.
@pigalot on GitHub · 2026-11-29 08:45 UTC · original · requested changes
Independently reviewed
32754becintegrated overmainae45c4ff(tree23db61ae). The trial merge is clean andgit diff --checkis clean.I traced
sanitize_sampler_commonagainst the D3D12 filter encoding and the documentedD3D12_SAMPLER_DESCranges, the slot 22 hook inview_slot, and the four call sites intranslated_sampler_bindings.handplane_compositor.h. I also ran a small standalone probe that callsID3D12Device::CreateSamplerdirectly, one description per process, to see what the runtime does with descriptions the sanitizer leaves alone.Blocking: a non-anisotropic filter with
MaxAnisotropyabove 16 still removes the device.sanitize_sampler_commonclampsMaxAnisotropyonly when the filter is anisotropic, on the reasoning that other filters ignore the field. The runtime validates it for every filter:Filter = MIN_MAG_MIP_LINEAR,MaxAnisotropy = 64, everything else valid:ID3D12Device::CreateSampler2: MaxAnisotropy must be in the range [0 to 16]. 64 specified., thenGetDeviceRemovedReason()=0x887a0001. Same result on WARP and on the RTX 5090, with the debug layer on and with it off (off: no message, the device is still removed).tests/startup_sampler_device.cpp,cases[6].MaxAnisotropy = 64;(case 6 is otherwise the valid linear description), makesstartup_sampler_device_warpandstartup_sampler_device_hardwarefail withdebug errors=2 removed=0x887a0001. The shim logs no repair for that case.So a title or translated sampler can still reach the desktop device with a value D3D12 rejects, through the same field this PR handles. Suggested direction (I have not built it): clamp
MaxAnisotropy > 16to 16 for every filter, keep the< 1repair for anisotropic filters only (the runtime accepts 0), and add the linear case to bothstartup_sampler_desc_checkandstartup_sampler_device.Non-blocking notes
(!anisotropic(filter) && (basic & ~0x15u))clause passes all three CPU tests: the two invalid filters in the tests (0x182,0x82) are both caught by the other clause. A filter such as0x40or0x50(anisotropic bit without the full encoding) would pin it; the probe shows the runtime rejects0x40("Filter unrecognized", device removed). With that clause in place the first clause,(filter & ~0x1d5u), is redundant: every value it catches is also caught by the second.CreateSampleraccepts border components of 2.0, -1.0 and NaN with no message and no removal. The clamp to [0, 1] follows the documented range, but it is not needed to keep the device alive, and it changes the border value for a title that uses an out-of-range one with a float format. Worth a sentence in the header on why it is clamped, or dropping the clamp for finite values. The same probe shows the runtime also accepts anisotropic withMaxAnisotropy = 0,MinLOD > MaxLODand a comparison filter with function 0; those repairs are harmless, but the device test cannot tell them apart from no repair (the negative control reports 4 errors:MaxAnisotropy 64,MipLODBias 20,AddressU 0, plus the removal).0x54is kept, which is right whereAnisoFilterWithPointMipSupportedis set (it is on both adapters here). On a device without it the description is forwarded unchanged; I could not test such a device.create_sampler_snapshot_heapor its reserved fallback entry (see the surviving mutants).fix:rather than an area prefix; the PR title is fine.Tests. Built
startup_sampler_desc_check startup_sampler_device startup_sampler_comparison_check startup_translated_sampler_bindings_check d3d12_xs_shim offscreen_check d3d12x_device_check startup_present_composite_warpindevandrelease.dev:startup_sampler_desc_check,startup_sampler_comparison,startup_translated_sampler_bindings3/3 passed;startup_sampler_device_warppassed (debug errors=0 removed=0x00000000);startup_sampler_device_hardwarepassed on the RTX 5090.release(/O2):ctest --test-dir out/build/release --no-tests=error -j 1 -R '^(startup_sampler_desc_check|startup_sampler_comparison|startup_translated_sampler_bindings|startup_translated_sampler_bindings_shared_axis_control|startup_sampler_device_warp|startup_sampler_heap_warp|startup_sampler_heap_wrapped_warp|startup_sampler_lod_warp|startup_sampler_lod_dropped_warp|mesh_heap_sampler_draw_warp|startup_present_composite_warp|startup_sampler_x_warp|dynamic_sampler_index_warp|d3d12x_pso_static_sampler_warp)$'-> 14/14 passed, no skips;startup_sampler_device_hardware(-j 1) passed,debug errors=0 removed=0x00000000.mainae45c4ff.args[0] = reinterpret_cast<u64>(&repaired_sampler);removed from slot 22,startup_sampler_device_warpfails withdebug errors=4 removed=0x887a0001andstartup_sampler_device_hardwarefails too. This matches the PR body.Mutants (
dev; each applied alone, sources restored,git diff --quietclean afterwards).startup_sampler_desc_check: anisotropic predicate back to== 0x55; filter repair drops the reduction bits; anisotropy upper bound 16 -> 32; anisotropy lower bound off; anisotropy clamp applied to every filter; NaNMinLODnot reset; NaNMaxLODnot reset; NaN bias not reset; bias minimum clamp off; bias maximum clamp off; comparison filter accepts function 0; non-comparison upper bound 8 -> 9; comparison repair picksNEVER; address lower bound off; address upper bound 5 -> 6;AddressVunchecked;AddressWunchecked; border low clamp off; border high clamp off;MaxLOD = MinLOD;startup_sampler_comparison:decode_staticsnot sanitized;startup_translated_sampler_bindings:dynamic_samplernot sanitized;startup_sampler_device_warpand_hardware: slot 22 forwards the title description (the negative control above).(basic & ~0x15u)clause (note 1);sampler &&instead of!sampler ||):startup_sampler_device_hardwarestill passes, since no test passes null;startup_sampler_device,startup_sampler_heap,startup_sampler_heap_wrapped,startup_sampler_lod,startup_sampler_lod_dropped,mesh_heap_sampler_draw,startup_sampler_x,dynamic_sampler_index) pass;(filter & ~0x1d5u)clause (note 1);Title run (prwatch job 24, head merged onto the baseline commit): flaky. It failed once and passed on the re-run (job 27), so it 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; Microsoft Basic Render Driver (WARP); D3D12 debug layer on (
X2W_TEST_DEBUG_LAYER=1, and the fixture's ownX2W_D3D12_DEBUG=1).CI:
Build and test on Windowspassed on32754bec.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 13:05 UTC · original
Review of head
32754becagainstmain94b679e7. I read the source and ran trial merges only; I did not build or run anything.git merge-tree --write-tree origin/main 32754becexits 0.mainhas not touchedtranslated_sampler_bindings.horplane_compositor.hsince the branch's merge base.Status: pigalot's change request on this head is still open, with no push or reply since. In that finding, a non-anisotropic filter with
MaxAnisotropyabove 16 still removes the device. That holds the merge, so I am not merging. I have nothing to add to it.SHOULD
Repairs on the translated paths are silent. Slot 22 logs each repaired field (
x2w-d3d12 sampler repaired: %s). The other four call sites drop the mask thatsanitize_sampler*returns:sanitize_static_sampler(sampler);indecode_staticssanitize_sampler(result);indynamic_samplersanitize_sampler(sampler);calls increate_sampler_snapshot_heapAll four run for translated draws on the default launcher path, with no switch. A sampler-word decode bug (an address mode or filter decoded wrong) now becomes
CLAMPor trilinear and leaves no trace. Onmainthe bad value at least reached the desktop device, where the debug layer or a device removal showed it. Could these sites count the repairs, or log the first few per field as slot 22 does, so a decode bug stays visible?NIT
view_slot. Both insert right afterif (default_view) args[desc_index] = 0;. With either one merged ontomain, the other conflicts insrc/startup_stubs/d3d12_xs_device.cpp(trial merges both ways). Whichever goes second needs a merge.AI-assisted.
@tedin7 on GitHub · 2026-11-30 13:58 UTC · original
Fixed anisotropy handling, added repair logging, and added a regression test covering the anisotropy fix. Ready for CI and re-review.
@Alexofbulgaria on GitHub · 2026-11-30 23:54 UTC · original
Updated Windows sampler checks at
fc7e538eTested clean PR head
fc7e538e8408af51b93dce618e461cc8c39937cdin Release with MSVC 14.44.35207 and Windows SDK 10.0.26100.0 on Windows build26300.10075.startup_sampler_desc_check8086:56a0), driver32.0.101.9175startup_sampler_device_hardware10.0.26100.10068startup_sampler_device_warpBoth D3D12 runs selected the intended adapter with the debug layer enabled, logged zero debug errors and reported device removal reason
0x00000000. Both logged sampler repairs, including anisotropy. Each test ran once with zero skips. These are descriptor and device sampler-creation checks. AI assisted with setup and reporting. The tests executed locally.@R0Y00 on GitHub · 2026-12-03 03:35 UTC · original · reviewed
Independent re-review of
fc7e538e, trial-merged ontoaa70e516. The updated condition clampsMaxAnisotropy > 16for every filter and still leaves zero alone for non-anisotropic filters. The previously reported 0x54/0x154 preservation cases passed in the descriptor suite. MSVC Debugctest --preset dev --no-tests=error -j 1 -V -R '^(startup_sampler_desc_check|startup_sampler_device_(warp|hardware)|startup_sampler_comparison|startup_translated_sampler_bindings)$'passed 5/5 with no skips. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 reported zero D3D12 debug errors and no device removal (Windows build 26300, debug layer enabled).I restored only the old anisotropic-only predicate in
sanitize_sampler_common, keeping the new linear case in the fixture. The CPU descriptor test failed, and both device tests reported two debug errors and removal0x887a0001. After restoring the fix, all three tests passed again. This addresses the non-anisotropic device-removal case in the earlier review. @pigalot, could you re-review the current head when available?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.