Skip to content

fix: default viewport and scissor for translated draws - #1657

Merged
R0Y00 merged 6 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-p04-viewport
Nov 24, 2026
Merged

R0Y00 merged 6 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-p04-viewport

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

A command list that never calls RSSetViewports (list slot 21) or RSSetScissorRects (slot 22) draws no pixel on desktop D3D12, yet every translated draw is counted as drawn. Pass now remembers whether the title set each one. A translated draw with no viewport covers the first render target (width, height, depth 0 to 1); with no scissor it gets the same rectangle. A viewport or scissor the title set is never replaced.

  • Title-neutral: applies only when the list did not set the state.
  • The two flags are the last members of Pass, cleared on Close (existing Pass reset) and on Reset.
  • A call with count 0 (or one that is not forwarded) leaves the state not set.
  • A draw with no render target 0 (depth only) gets no default. A render target view of a later mip uses the width and height of mip 0 of the resource; scissor and viewport then exceed the view, which only widens what the title's own pipeline can write to the bound view.

Tests

New startup_stream_viewport_warp and startup_stream_viewport_hardware reuse the startup_stream_consumer fixture (mode chosen by X2W_TEST_VIEWPORT) on an 8x4 target cleared to blue, red pixel shader:

  • none: no slot 21 or 22 -> all 32 pixels red (before: all blue).
  • rect: 4x2 viewport and scissor at (2, 1) -> red inside, blue outside.
  • reset: the rectangle on one list, then Reset of the same list with no slot 21 or 22 -> all 32 pixels red.

Failure message names the first wrong pixel. A mutation that disables the default fails none at pixel (0, 0); one that overrides the title's rectangle fails rect at pixel (2, 1); one that keeps the flags across Reset fails reset at pixel (0, 0). The disable-default-viewport mutation was run on Windows 2025 (see Verification).

Windows 2025 command: ctest --preset dev --no-tests=error -R '^startup_stream_viewport_(warp|hardware)$' -V

Run locally

  • x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only on tests/startup_stream_setup.cpp and tests/startup_stream_draw.cpp: clean.
  • Same on src/startup_stubs/d3d12_xs_device.cpp (includes the draw code): only the pre-existing __try/__except errors of MinGW in local_log.h, none on the changed lines.
  • tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check: pass.
  • Python syntax of the new check parsed.

Verification (Windows Server 2025, build 26100, MSVC 14.44, D3D12 WARP)

At 22989d6 (same tree as 50aaa70):

  • x2w_pipe.py preflight /root/wt/x2w-frontier-p04-viewport: no FAIL. It flagged the identifier small (Windows SDK macro) in tests/startup_stream_setup.cpp; renamed to inset in 50aaa70.
  • x2w_pipe.py win2025 1657 --regex '^(startup_stream_viewport_warp|startup_stream_draw_warp|startup_stubs|d3d12x_graphics_list_warp|startup_cb_blend_warp|stream_root_srv_warp)$' --force:
    • Debug (--preset dev): 6/6 passed.
    • Release /O2 (--preset release): 6/6 passed.
  • Mutation: with the default viewport block disabled (if (false && !pass.viewport_set)), startup_stream_viewport_warp failed on Windows 2025: none: pixel (0, 0) is 0000ffff, expected ff0000ff. The mutation commit was reverted (1f24626, 22989d6).
  • The _hardware variant skips: the node has only WARP.

Open PR overlap

git merge-tree against the heads of #1441, #1469, #1511, #1549, #1555, #1567, #1641 and #1654: no new conflict. The existing conflicts of #1441 and #1469 (CMakeLists.txt, xg_xs.cpp) and #1549 (docs/experiments.md) already exist against main without this change. #1654 also edits tests/startup_stream_setup.cpp and docs/startup-runtime.md; it merges cleanly.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 24, 2026 16:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T16:50:16.475428Z 22989d6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22989d61c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread src/startup_stubs/d3d12_draw.inl Resolved
Keep the title's viewport/scissor flags apart from the automatic default and
remember the size of the default already forwarded, so a list that never sets
its own state follows render target 0 across OMSetRenderTargets. Adds a grow
case to startup_stream_viewport.

AI-assisted; commands listed were executed locally.
AI-assisted; commands listed were executed locally.
@R0Y00
R0Y00 merged commit daa6523 into R0Y00:main Nov 24, 2026
5 checks passed
@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Two ways to overwrite a title-set viewport both survive the fixture

Reviewed 3e895d23. Built at that head, ran the two viewport cases, then mutated the new default in d3d12_draw.inl and rebuilt d3d12_xs_shim (the DLL the consumer loads — the timestamp changed each time, and the untouched build passes 2 of 2).

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_stream_viewport' -V
warp     viewport none: all 32 pixels exact
warp     viewport rect: all 32 pixels exact
warp     viewport reset: all 32 pixels exact
warp     viewport grow: all 128 pixels exact
hardware ... same four, all exact

Mutations

change result
viewport width/height swapped in the default rect caught
the scissor branch disabled (if (false)) caught
viewport branch condition if (true) (always re-issue the default) not caught
scissor branch condition if (true) not caught

Why I am not calling the last two a gap outright

tests/startup_stream_viewport_check.py says the draw "never replaces one the title set", and the rect case is the one that would show it: a 4x2 viewport at (2,1) has to leave the outside pixels blue. With if (true) that expectation should break, and it does not — so in this fixture's ordering the title's own slot-21 call must land after whatever the shim does at submission time, and the overwrite is invisible.

That leaves two readings I cannot separate from the fixture:

  1. the mutant is equivalent for this call order, and a title that sets a viewport once and draws twice would still be safe;
  2. the overwrite is real, and the case that would expose it — set a viewport on draw 1, draw again on draw 2 without re-setting it — is simply not in the fixture.

The way to tell them apart is one more case, and it is small: in grow, draw twice on the first target with the rectangle set once before the first draw, and require red inside the rectangle and blue outside on both. If the second readback is all red, reading 2 is the answer.

I would rather flag this than stay quiet, because the branch's own comment says "Only the title's own calls set the flags; an automatic default is regenerated when render target 0 changes size" — the size cache is what makes the two if (true) mutants indistinguishable, and nothing asserts the cache does its job. Dropping the size comparison entirely (leaving !pass.viewport_set) also survives.

What is solid in the change

The swap and the disabled-scissor mutants being caught means the default rectangle is asserted in both extents and both views, and the reset case proves the default is not inherited across Reset.

Verdict

Reviewed 3e895d23. The default itself is correct and covered; the "never replaces what the title set" half of the contract is not, on the evidence of two surviving mutants. If you want the extra case I can write it against your branch or as a follow-up with Refs #1657 — your call.

denn0x added a commit to denn0x/Xbox2Windows that referenced this pull request Nov 25, 2026
Conflicts resolved keeping both sides:
- d3d12_draw.inl: mip comment line, upstream's wording (R0Y00#1630).
- d3d12_xs_device.cpp: Pass keeps local compute root state and upstream viewport/scissor flags (R0Y00#1657);
  local ExecuteIndirect trace (slot 61) and upstream list_root_cbv (slot 42, R0Y00#1654) both kept.
- xcrdapi.cpp: local failure tally, RDS5 shift/slice and stream cache kept next to upstream's BCPack
  census (R0Y00#1622); queue worker is upstream's CreateThread worker (R0Y00#1410), the local
  tally_failure("exception") moved into fail_entry.
- run.ps1: upstream venv python and exit code (R0Y00#1535/R0Y00#1603) with local --fast-exit/--log-repeats.
- gfx2hlsl.py image(): local 1D lowering (load, sample, sample_l, a16) kept over upstream's
  sample-only 1D guard; startup_image_sample_l_check keeps the local 1D SampleLevel expectation,
  startup_image_3d_check keeps the local 1D assertions plus upstream's cube-dimension refusal.

Tests adjusted for local behaviour: startup_run_ps1_check expects the two local debugger
arguments, startup_translator_check's StubPipeline has ps_entry_reads, and the coverage check's
hand-built Pipeline sets packed_position_vgpr (new in R0Y00#1634).
denn0x added a commit to denn0x/Xbox2Windows that referenced this pull request Nov 25, 2026
Conflict in d3d12_xs_device.cpp list_viewports / list_scissors: kept upstream R0Y00#1657's viewport_set /
scissor_set flags on a forwarded call and the local state_dropped counters on a dropped one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants