startup: sanitize viewports and scissors and draw with no DSV format when no depth view is bound #3197
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!3197
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3195"
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:25 UTC · original
tedin7:up-viewport-check→main· +277 −7 · 8 files · 4 commits · openPart of #870
What this unblocks: title draws whose viewport, scissor or missing depth view made the D3D12 debug layer report errors on desktop GPUs now reach the GPU as valid state.
The device shim forwarded title
RSSetViewports/RSSetScissorRectsas they came, and a translated draw took itsDSVFormatfrom the pipeline even when the pass bound no depth view. D3D12 requires viewport depth in [0, 1], origin and extent insideD3D12_VIEWPORT_BOUNDS_MIN/MAXand no negative size ("D3D12_VIEWPORT structure"), scissor rectangles with right >= left and bottom >= top ("ID3D12GraphicsCommandList::RSSetScissorRects"), and a PSODSVFormatthat matches the bound depth view ("D3D12_GRAPHICS_PIPELINE_STATE_DESC", DSVFormat).src/startup_stubs/viewport_check.h:sanitize_viewport(NaN and out-of-range depth clamped to [0, 1], an inverted depth range is kept, origin clamped to the bounds, NaN/negative size -> 0, extent trimmed to the bound) andsanitize_scissor(an inverted rectangle becomes an empty one at its left/top edge).pass_dsv_formatuses only the depth view bound to the pass, so a pipeline created with a depth format draws withDSVFormatUNKNOWN and no depth-stencil state when no depth view is bound.Tests:
startup_viewport(CPU rules: valid values untouched, NaN/inf/out-of-range repaired, DSV format and depth-state choice).startup_viewport_device_warp/_hardware(debug layer on a shim list: an out-of-range depth range, a negative width and an inverted scissor give no debug-layer error and no device removal; on main these calls are forwarded as they came).startup_slot57_depth_warp/_hardware: new casestream_no_dsv(a stream pipeline created with a depth format, drawn with no depth view bound: picture still read back green, no debug-layer error, no device removal).Verification:
cmake -S . -B /tmp/up-viewport-check-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true-> configure OKpython3 -m py_compile tests/startup_slot57_depth_check.py-> OKx86_64-w64-mingw32-g++-posix -std=c++20 -fsyntax-only -Isrc tests/startup_viewport_check.cpp-> OKx86_64-w64-mingw32-g++-posix -std=c++20 -fsyntax-only -Isrc tests/startup_viewport_device.cpp-> OK5c157e4866947f1962e366594f213a61f9d88c33:cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_slot57_depth startup_viewport startup_viewport_device startup_draw_depth_target startup_stream_depth, thenctest --preset dev -R '^(startup_viewport|startup_slot57_depth_|startup_draw_depth_target|startup_stream_depth_)' --no-tests=error-> 13/13 passed/O2: same targets and regex -> 13/13 passedd3d12_xs_device.cpp/d3d12_draw.inlchanges reverted (tests kept), dev,-R '^(startup_viewport|startup_slot57_depth_)'-> 4 of 5 failed as expected:startup_viewport_device_warp/_hardwareandstartup_slot57_depth_warp/_hardware(debug layer: "The depth stencil format does not match that specified by the current pipeline state"); the CPU teststartup_viewportpasses either way.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:52 UTC · original
Review of
5c157e48(single commit):@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
5c157e4(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:52 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
5c157e4ℹ️ 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.
@tedin7 on GitHub · 2026-11-28 22:07 UTC · original
Merged current
maininto this branch (merge commit, no force push, no conflicts); head is now9fb65760b. No change to the PR's own files.Verification (Windows Server 2025, D3D12 WARP, head
9fb65760b):x2w_pipe.py win2025 3195 --regex '^startup_viewport'-> 3/3 passed (startup_viewportand the device tests).@MasterDomino ready for review and merge when you have time. KelboLive's review of
5c157e48has no open asks.AI-assisted; commands listed were executed locally.
@pigalot on GitHub · 2026-11-29 08:05 UTC · original · requested changes
Independently reviewed
9fb65760integrated overmain212d4b5f(treece819832). The trial merge is clean andgit diff --checkis clean.Requesting changes for one thing: the viewport half of this PR has no test that fails without it.
1.
startup_viewport_devicepasses when the viewports are forwarded unsanitized (blocking).Mutant: in
list_viewports, changelist->RSSetViewports(count, copy.data());back tolist->RSSetViewports(count, viewports);and leave everything else as it is. Then:Both pass, on WARP and on the RTX 5090, with
debug errors=0 removed=0x00000000.startup_viewportandstartup_slot57_depth_warppass too, so no test in the PR notices that the title's{0, 0, 4, 4, -0.5, 1.5}and{0, 0, -4, 4, 0, 1}viewports reach the list as they came. Expected: a test that fails.So here the debug layer reports nothing for an out-of-range depth range or a negative width at
RSSetViewports,CloseorExecuteCommandListswhen no draw follows. The body's control ("with thed3d12_xs_device.cppchanges reverted ...startup_viewport_device_*failed") holds only because of the scissor: with only the scissor forwarding reverted, the test fails with "RSSetScissorRects: In the scissor rect, bottom (4) is less than top (0) or right (2) is less than left (10)". That also means the body's premise for the viewport part (a viewport that makes the debug layer report errors) is not shown by anything in the PR.Suggested direction (unconfirmed): follow the viewport call with a draw in the fixture, if the debug layer validates viewports at draw time, and show the message it gives on
main; or have the test check the shim's ownx2w-d3d12 RSSetViewports: repaired invalid viewportline, which at least pins the wiring. If no debug-layer message can be produced for these values, please say in the body what the viewport sanitizing is based on instead.What I traced.
pass.bound_depthandpass.dsv_formatare set together, only inlist_targets, and both are reset at its top, sodraw_dsv_format(pass.bound_depth != nullptr, ...)differs from the old expression only when no depth view is bound: the stream format is no longer used, and with ituse_depth_stencilis off for a stream pipeline drawn with no depth view.view_format_offalls back to the resource format, so a bound view never gives UNKNOWN.sanitize_viewportkeeps an inverted depth range, clamps NaN depth to 0 / 1, and trims the extent in double before narrowing;count <= 16bounds thestd::arraycopies.Tests. Built
d3d12_xs_shim startup_slot57_depth startup_viewport startup_viewport_device startup_draw_depth_target startup_stream_depthindevandrelease, then ranctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_viewport|startup_viewport_device_warp|startup_slot57_depth_warp|startup_draw_depth_target.*_warp|startup_stream_depth_warp)$'and the_hardwarevariants (-j 1): 7/7 WARP and 6/6 hardware passed in Debug and in Release/O2, no skips.Mutants (dev;
startup_viewport,startup_viewport_device_warp,startup_slot57_depth_warp):Killed:
startup_viewport_device_warpfails (message above).pass_dsv_format(fall back to the stream format):startup_slot57_depth_warpfails, fixture exit 70 instream_no_dsv. This is the negative control for the DSV half and it works.draw_depth_state_enabledreturnshas_state:startup_viewportandstartup_slot57_depth_warpfail.use_depth_stencilexpression inpipeline_for:startup_slot57_depth_warpfails.viewport_check.h, each killed bystartup_viewportonly: noMinDepthclamp, noMaxDepthclamp, noTopLeftXclamp, negative size kept, no extent trim, nobottom < toprepair.Surviving:
std::nextafterline inextent: no test input reaches it (an origin such as0.0005fwith a width past the bound would).Equivalent: none.
Non-blocking notes.
startup_slot57_depthnow returns 20 ("no debug layer") whenID3D12InfoQueue1or the callback registration is unavailable, andstartup_viewport_devicereturns 4. Before this PRstartup_slot57_depth_*did not need the debug layer in the fixture.startup_draw_depth_target_debug_*reports a skip (77) in that case; the same here would keep the other 13 cases usable on a machine without the debug layer. I did not run without the debug layer; this is from reading the code.BoundPipeline::dsv_formatis still filled from the stream (d3d12_draw.inl:1120) but nothing reads it now; the third parameter ofdraw_dsv_formatis unnamed and unused.Title run of this head (merged onto the baseline commit): pass, judged no worse than the baseline.
Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and Microsoft Basic Render Driver (WARP); debug layer on.
CI:
Build and test on Windowspassed on9fb65760.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 13:05 UTC · original
Review of head
9fb65760againstmain94b679e7. I read the source and ran trial merges only; I did not build or run anything.git merge-tree --write-tree origin/main 9fb65760exits 0.On the default launcher path, both halves are on with no switch. I traced the DSV half in the merged tree.
pass_dsv_formathas two callers,pipeline_forand the scoped stencil-ref check (pass_dsv_format(*bound, pass) != DXGI_FORMAT_UNKNOWN). Both now seeUNKNOWNonly when no depth view is bound. The other two PSO sites,draw_missing_translationanddraw_pipeline_colour, already usedpass.dsv_formatdirectly. So the DSV change only affects draws where depth state had no target, andstream_no_dsvshows the picture is the same. That half looks right to me.Status: pigalot's change request on this head (finding 1: the viewport half has no test that fails without it) is still open, with no push or reply since. That holds the merge, so I am not merging. I have nothing to add to that finding.
SHOULD
log("x2w-d3d12 RSSetViewports: repaired invalid viewport")andlog("x2w-d3d12 RSSetScissorRects: repaired invalid scissor")are the only trace that a title viewport or scissor was changed on the default path. The values are what show whether the input was garbage or meant something. One example: a negativeHeightused as a Y flip becomes a zero-size viewport here, so the draw disappears. Could you print the six input floats and the repaired ones (and the fourLONGs for a scissor) in those first 6 lines? A fixture for finding 1 could then also check the line.NIT
ctest --preset pr. Its include list matches none ofstartup_viewport,startup_viewport_device_*orstartup_slot57_depth_*(checked againstCMakePresets.jsononmain). So the green Windows check on9fb65760did not run this PR's tests. The runs that cover them are pigalot's and the Win2025 ones in the thread. A line in the body saying so would save the next reviewer the same check.Trial merges onto
mainplus one other PR from this group: this PR merges cleanly with #3201 and with #3202 in either order.AI-assisted.
@tedin7 on GitHub · 2026-11-30 13:59 UTC · original
Merged current
main(077bff3ac) to resolve conflicts and logged viewport/scissor repair values.@JB2WIN on GitHub · 2026-12-02 20:09 UTC · original · edited 2026-12-02 20:46 UTC
Full application run for this PR, on a local retail package. No game files or captures leave this machine. Both builds are release builds launched with
tools/startup/run_preset.py --console x --gpu nvidiaon an RTX 3080 / Windows 11 and stopped after 900 s:main46d465d9main46d465d9+ this PR (4a4e420c)RSSetViewports/RSSetScissorRectsrepairs loggedNo regression. The repair log lines never fired in this window, so this run does not exercise the sanitizer. The 4,196 undrawn draws on
mainwere cache warm-up, not a difference between the builds. Two pipelines were translated (ok) during that run and refused asmanifest_absentuntil their translation was published, after which they drew. The PR worktree already had both in its translation cache from an earlier, aborted run. The fps and draw-count differences are therefore not evidence for or against this change either.AI-assisted.
@R0Y00 on GitHub · 2026-12-02 20:33 UTC · original · reviewed
I reproduced pigalot's viewport-only control on
4a4e420c. MSVC Debug baseline passed 5/5 (startup_viewport, bothstartup_viewport_devicecases and bothstartup_slot57_depthcases) on Windows 11 build 26300 with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The device fixture had the D3D12 debug layer enabled. Replacing onlylist->RSSetViewports(count, copy.data());withlist->RSSetViewports(count, viewports);still passed both device cases withdebug errors=0 removed=0x00000000. Disabling both sanitizers failed both cases with the inverted-scissor diagnostic (D3D12 message 1338). The current fixture clears the render target, so its observable result is independent of the forwarded viewport. Please add a draw with a known viewport-sensitive pixel or depth readback, and show that the one-line forwarding control fails on both adapters.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.