GPU: clamp viewport and scissor counts and normalize inverted scissor rects #3176
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3176
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3176"
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?
@fuzeofficlal on GitHub · 2026-11-26 11:11 UTC · original
fuzeofficlal:fix/gpu-viewport-scissor-bounds→main· +120 −4 · 1 files · 1 commits · openProblem
State::viewportsandState::scissorsincrates/victory-gpu/src/draw.rsforwarded arbitrary slices directly toID3D12GraphicsCommandList::RSSetViewports/RSSetScissorRectsand persisted them verbatim inself.fixedfor segment-cut replay (State::cut):D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE(16) viewports or scissor rects violates D3D12's pipeline limit and aborts the process under D3D12 validation (observed fatal exit code2173on both hardware D3D12 and WARP withVICTORY_D3D12_DEBUG=1).right < leftorbottom < top) triggers a D3D12 Debug Layer error:ID3D12CommandList::RSSetScissorRects: In the scissor rect, bottom (...) is less than top (...) or right (...) is less than left (...). An inside-out rect can cause undefined behavior.Fix
State::viewportsandState::scissorstoD3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE(16).right = r.right.max(r.left)andbottom = r.bottom.max(r.top), which preserves empty-clipping semantics across the fulli32range (including negative coordinates) without overflow while satisfying D3D12'sleft <= right && top <= bottominvariant.self.fixedsoState::cutreplays valid bounds onto subsequent host command list segments as well.Verification
Added
draw::tests::viewports_and_scissors_clamp_count_and_inverted_rectscovering empty slices,> 16viewports and scissor rects, inside-out scissor rects (right < left,bottom < top, and negative coordinates), andState::cutsegment replay:origin/main): aborts with exit code2173on both RTX 5090 +VICTORY_D3D12_DEBUG=1and WARP +VICTORY_D3D12_DEBUG=1; inside-out scissor rects emit the D3D12 Debug Layer error above.--features diagnostics+VICTORY_D3D12_DEBUG=1, and WARP--features diagnostics+VICTORY_D3D12_DEBUG=1withhost.log_messages() == None.cargo test -p victory-gpu --lib --lockedpasses on hardware default (230 passed), hardwarediagnostics + DEBUG=1(244 passed), and WARPdiagnostics + DEBUG=1(246 passed).cargo clippy --workspace --all-targets --locked -- -D warnings(default and--all-features) andxtaskpolicy checks pass cleanly.@Dukestar69 on GitHub · 2026-11-26 11:27 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed (includingviewports_and_scissors_clamp_count_and_inverted_rects).cargo test -p victory-gpu --lib list:: -- --test-threads=1: 4/4 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly clamps viewport/scissor counts to the D3D12 limit and normalizes inverted scissor rects.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 11:28 UTC · original
WARP verification of #3176 at
308c228d(software adapter only; no physical GPU used). AI-assisted: Claude Code (Claude Sonnet 5.5).Setup. The head is one commit on top of
main63bcca4(merge-base =63bcca4); head SHA confirmed before and after testing. Windows 11 (26100), rustc/cargo 1.98.1,VICTORY_D3D12_WARP=1(WARP,d3d10warp.dll10.0.26100.9818),VICTORY_DXIL= Windows SDK 10.0.26100.0dxil.dll1.8.2502.11. Every cargo command used-j 4,--locked, a separate target dir.Results
cargo test -p victory-gpu --lib --locked viewports_and_scissors -- --test-threads=1->draw::tests::viewports_and_scissors_clamp_count_and_inverted_rects1 passed. It runs for real on WARP (it returns early only when no host device exists), including the D3D12Close()/executeand a check that the debug layer logged nothing.cargo test -p victory-gpu --lib --locked -- --test-threads=1-> 232 passed, 0 failed, 1 ignored. Baselinemain63bcca4, same command and environment: 231 passed, 0 failed, 1 ignored. The difference is the one new test; no failure to attribute.State::viewports/State::scissorsrestored to the63bcca4bodies, test kept): the test process crashes withSTATUS_ACCESS_VIOLATION(0xc0000005) on WARP when handed 20 viewports/rects. So the test does detect the missing clamp (on this adapter the failure mode is a crash, not an assertion).Diff review. No concrete defect found. Both setters now truncate to
D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE(16) before recording and issuing, and the scissor path normalizesright = max(right, left),bottom = max(bottom, top)and stores the normalized rects infixed.scissors, so the replay inState::cutis also valid. Observations, not defects: an inverted rect becomes an empty rect at its left/top edge, which is a choice about guest semantics that I could not check against console behaviour; a count above 16 is truncated silently (no log line); the test only exercises the host-list path, not an end-to-end draw.Not tested
cargo clippy,cargo fmt --check, release profile.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.