Skip to content

runtime: composite the presented planes in the output window - #2647

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
pigalot:present/plane-composite
Nov 26, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
pigalot:present/plane-composite

Conversation

@pigalot

@pigalot pigalot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Change

Slice 1 of 4 from #2591, the compositor. It runs under any profile.

A console present (CommandQueue slot 32) can carry several plane records
(present_planes.h: 0x48 bytes each, +0x08 resource count, +0x10 resource array). The output window
showed plane 0 alone. On a two-plane present I measured, plane 0 (1920x1080) stayed black and plane 1
(3840x2160) held the picture with alpha 255, so the window was black.

The window now composites the planes. The draw (shaders, root signature, opaque and blend pipelines,
per-plane SRVs and draws) moves out of d3d12_present.inl into src/startup_stubs/plane_compositor.h.
The window presenter and the new WARP fixture use the same PlaneCompositor, so the fixture runs the
same draw code as the window, not a copy of it.

Supported alpha and order contract (also in docs/startup-runtime.md#presented-planes):

  • Order: plane 0 first, then each later plane over it, in plane order (composite_steps). At most
    four planes are read.
  • Bottom plane: the lowest drawn plane is opaque. Its colour replaces the target and its alpha is
    ignored.
  • Later planes: blended by their own straight (not premultiplied) alpha:
    rgb = src.rgb * a + dst.rgb * (1 - a) (SRC_ALPHA / INV_SRC_ALPHA; alpha ONE /
    INV_SRC_ALPHA). Alpha 0 keeps what is below, alpha 255 replaces it, and the target alpha stays 255.
  • Left out: an unreadable or empty record, a surface that is not a known resource or cannot be
    drawn (present_view_format.h), and a repeat of a surface already drawn. If plane 0 is left out,
    the next drawn plane becomes the opaque base.
  • Not decoded: the source and destination rectangles in the record. Each plane is scaled to the
    whole window.

X2W_PRESENT_PLANE=<n> (diagnostic) shows plane n alone. The first presents log each plane's shape.
The x2w-render presented readback now reports the topmost drawn plane and adds a mean alpha. This
answers the review report of a top plane with alpha about 5/255 on hardware: that plane now
contributes about 5/255 of its colour over the plane below it. It no longer replaces it.

Refs #2591. Independent of the other three slices (slot 76, view dimensions, console profile).

Verification

Build: this branch, one commit cb137898 on main at 02368737. From the worktree in PowerShell:
. .\tools\dev.ps1, cmake --preset release, cmake --build --preset release (Python env
out/pe-env from requirements-dev.txt).

Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200.9974. The new fixtures
use in-box WARP, with the debug layer off.

  • ctest --preset release --no-tests=error -R '^startup_present_(planes|composite_warp)(_control)?$' -V:
    4/4 passed. startup_present_planes and startup_present_composite_warp print ok. Both controls
    print FAIL: lines, as their regex requires.
  • ctest --preset release -j 8 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_': 642
    tests, 635 passed, 6 skipped (capability, exit 77), 1 failed. The failure was startup_inflate,
    which timed out at 60 s under -j 8. Rerun alone with
    ctest --preset release --no-tests=error -R '^startup_inflate$' it passed in 9.1 s. This change
    does not touch it. (Run before a final amend that only moved an #include / CMake block to avoid a merge conflict with the sibling slices; the slice's own tests were rerun after it and pass.)
  • python -B tests/docs_links_check.py: pass (19 Markdown files, 508 links).
    python -B tests/bidi_controls_check.py: pass (no bidirectional controls).
    git diff --check origin/main...HEAD: clean.

Evidence

startup_present_composite_warp builds 64x32 RGBA8 planes from source (cells of 16x16 texels). It
passes them through synthetic 0x48-byte plane records, then present_plane_resource, then
composite_steps, then PlaneCompositor::record into a render target cleared to
(64,128,191,0). It reads every texel back. Observed on WARP:

Case Planes Read back (every texel of each cell)
single-plane baseline one plane of eight colours, one cell alpha 0 and one alpha 128 each cell exactly its colour, alpha 255
stacked black opaque plane 0; plane 1 cells with alpha 0 / 128 / 5 / 255; plane 2 with half red over plane 1's opaque blue, opaque yellow, opaque cyan, alpha 0 0,0,0 / 0,128,0 / 5,5,5 / 0,0,255; 128,0,127 / 255,255,0 / 0,255,255 / 0,0,0; alpha 255 everywhere
skipped black, plane 1, plane 1's surface again, a record with no resource two steps; the same picture as black + plane 1 (a drawn repeat would give 0,191,0 and 10,10,10)

Opaque cells are exact. Blended cells are within 1 level of the expected value. 128,0,127 depends on
plane order: plane 1 under plane 2. --control composites only the black first plane. The baseline
still passes, and every overlay cell plus both step counts print FAIL:. The test exits 77 when no
WARP adapter is available.

startup_present_planes (from #2591, unchanged) checks the record layout and the composite order on
synthetic records. Its control reads 0x40-byte records and composites plane 0 alone.

All inputs are written in source (MIT). Why plane 0 stays black on the console path is still unknown,
and the record's rectangles are not decoded. A start-up run with a local console executable (not
included) showed a picture with this change. That run is recorded in #2591, not repeated here.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

A console present (CommandQueue slot 32) can carry several planes. The
output window showed plane 0 alone; on a two-plane present plane 0 was
black and plane 1 held the picture. The window now composites the planes
bottom to top: the lowest drawn plane opaque (its alpha ignored), each
later plane blended by its own alpha (src-alpha / inv-src-alpha) in plane
order. Unreadable or empty records, surfaces the presenter cannot draw
and repeats of a surface are left out. X2W_PRESENT_PLANE=<n> shows one
plane alone for diagnosis, and the first presents log each plane.

The draw (shaders, opaque and blend pipelines, per-plane draws) moves
into plane_compositor.h, shared by the window presenter and a new WARP
readback fixture.

New fixtures with negative controls: startup_present_planes (record
layout and order) and startup_present_composite_warp (single-plane
baseline, stacked transparent, partly transparent and opaque overlays,
skipped repeats; the control composites only the black first plane).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment review of head cb13789 (code and fixture tests only).

What I checked:

  • present_planes.h: composite_steps keeps plane order, drops unreadable planes and repeats of a surface already drawn, and makes the lowest drawn plane the opaque base. Matches the contract in the PR body and in docs/startup-runtime.md.
  • plane_compositor.h: the opaque pipeline writes float4(rgb, 1). The blend pipeline uses SRC_ALPHA / INV_SRC_ALPHA for colour and ONE / INV_SRC_ALPHA for alpha, so straight alpha over an opaque base keeps target alpha at 255. Window presenter and the WARP fixture share this class, so the fixture exercises the window's draw code.
  • d3d12_xs_device.cpp: presented_planes() bounds the loop by window_planes, falls back to the first known surface when none can be drawn, and X2W_PRESENT_PLANE still selects one plane.
  • The new WARP fixture compares GPU readback with CPU-computed expected colours for the baseline, stacked and skipped cases, not string checks.
  • No other open or merged PR covers this slice (search "composite planes present": only #2591, the series issue-PR this one is slice 1 of).

Commands run (Linux, in a worktree of this head):

  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: passed (19 files, 508 links).
  • python3 tests/bidi_controls_check.py: passed.
  • g++ -std=c++17 tests/startup_present_planes_check.cpp (pure logic, builds on Linux): ok.
  • Mutation 1: first drawn plane no longer marked opaque/blended correctly (PlaneStep{i, false}): startup_present_planes: FAIL, "plane 1 is drawn over plane 0, blended".
  • Mutation 2: repeat-surface check removed: FAIL, "a surface presented twice is drawn once".
  • The D3D12 WARP fixture (startup_present_composite_warp) needs Windows; I did not run it here.

Findings: no bugs found in the code. The branch is 20 commits behind main.

Why this is not merged by me: the PR describes a measured black window on a real two-plane present (blocker seen while running the console executable), and its fix is meant to advance that run. We have no access to the executable, so the fixture results above are the only thing verified. Whether the window now shows the picture, and the hardware report of a top plane with alpha about 5/255, must be confirmed by whoever merges, on the executable. The merge stays with MasterDomino or @R0Y00.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Windows Release at cb137898 reproduced the WARP composite and the expected overlay pixel differences. Two things remain for this slice. The PASS_REGULAR_EXPRESSION "FAIL: " accepts queue or compositor setup failure and device removal as a successful negative control. Make the control succeed only after the baseline matches, a fence completes, and removing the overlay produces the expected pixel differences. Also keep the new multi-plane presentation behind an explicit experimental option until there is a matched executable comparison of this standalone candidate. The #2591 run combined four changes. Preserve the existing baseline capture and label the highest-plane sample as a raw plane so it cannot be mistaken for final composited pixels.

The output window shows plane 0 alone again by default; the multi-plane
composite runs only with the experimental X2W_PRESENT_COMPOSITE=1.

The baseline capture is restored: the frame capture, the presented
signature, the surface dump and the x2w-render presented readback read
plane 0's first resource as before. Under the switch the highest plane
above plane 0 is sampled separately and logged as
"x2w-render raw plane <i> (not composited)".

The WARP control is renamed
startup_present_composite_overlay_removed_control_warp. It runs the
baseline, stacked and skipped cases, then removes the overlays, and
passes only on "control ok:", printed when the baseline matched, every
fence completed without device removal and the overlay-free picture
differs from the stacked expectation in exactly the six overlay cells.
Any FAIL line, including setup failure, a fence that does not complete
or device removal, now fails it.
@pigalot

pigalot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reproducing it at cb137898. Both points are addressed in fddd5f70 (a new commit on top; nothing rebased).

1. The negative control now passes only on success

  • It is renamed startup_present_composite_overlay_removed_control_warp, to follow the other _control_warp tests. It runs the same baseline, stacked and skipped cases as startup_present_composite_warp. Then it removes the overlays and composites the black plane 0 alone.
  • It prints control ok: baseline matched, <n> fences completed, removing the overlay changed 6 of 8 cells as expected and exits 0 only when all of these hold:
    • the baseline and stacked cases matched;
    • every fence completed (Gpu::run now fails on a close or signal error, a wait that does not reach the value, or a completed value of UINT64_MAX), and GetDeviceRemovedReason reports no removal;
    • the overlay-free picture is black and differs from the stacked expectation in exactly the six cells the overlays draw. The other two cells must still match.
  • Registration: PASS_REGULAR_EXPRESSION "control ok: baseline matched", FAIL_REGULAR_EXPRESSION "FAIL: ", SKIP_RETURN_CODE 77 (no WARP). Every failure path prints FAIL:, including queue, compositor, target and plane setup.

2. Multi-plane presentation is now experimental and opt-in

  • By default the window shows plane 0 alone, as on main. Plane 0 is the only plane drawn, through the same opaque full-window draw with a linear, clamped sampler. No swap chain is created when plane 0 cannot be drawn.
  • The composite runs only with X2W_PRESENT_COMPOSITE=1. It stays opt-in until there is a matched comparison on the same executable with this change alone. X2W_PRESENT_PLANE=<n> still shows plane n alone, with or without the switch.
  • The baseline capture is restored, with or without the switch. The frame capture, the presented signature, X2W_D3D12_DUMP_SURFACE and the x2w-render presented readback all read plane 0's first resource again. The x2w-render presented line is back to its main format (I dropped the mean-alpha field).
  • Under the switch, the highest plane above plane 0 is sampled separately on the same frames and logged as x2w-render raw plane <i> (not composited): surface ..., sample <k>, mean level ..., mean alpha .... It does not touch the window copy, the note or the dump.
  • The x2w-present frame <n> plane <i>/<count> shape lines (first presents and every 300th) are still logged in both modes. They only log.
  • docs/startup-runtime.md#presented-planes and the switch table describe the default, the opt-in and the raw plane line. The fixture still tests the compositor directly, without the switch.

Results

Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200, Release preset, debug layer off (the composite fixture does not enable it). Commit fddd5f70.

. .\tools\dev.ps1
cmake --preset release
cmake --build --preset release
ctest --preset release --no-tests=error -R 'present' -V

14/14 passed, 0 failed, 0 skipped. Among them:

  • startup_present_composite_warp: passed (baseline, stacked and skipped on WARP).
  • startup_present_composite_overlay_removed_control_warp: passed, control ok: baseline matched, 8 fences completed, removing the overlay changed 6 of 8 cells as expected.
  • startup_present_planes and startup_present_planes_control: passed. These are unchanged; that control is pure CPU and has no setup or device path.
python -B tests/docs_links_check.py      # Checked 19 Markdown files and 509 links (exit 0)
python -B tests/bidi_controls_check.py   # no bidirectional controls (exit 0)
git diff --check origin/main...HEAD      # clean

Mutation checks (each applied locally, the target rebuilt, ctest --preset release --no-tests=error -R '^startup_present_composite_' run, then reverted):

Mutation startup_present_composite_warp control
Overlay pipeline BlendEnable = FALSE (plane_compositor.h) Failed: FAIL: stacked cell row 0 column 0: got 255,255,0,0 want 0,0,0,255 and others Failed: FAIL: regex matched
compositor.create result forced to E_FAIL Failed: FAIL: compositor setup 0x80004005 Failed: FAIL: regex matched. The old PASS_REGULAR_EXPRESSION "FAIL: " would have passed it.
Fence completed value forced to UINT64_MAX (device removal) Failed: FAIL: fence 1 not completed (completed 18446744073709551615, ...) Failed: FAIL: regex matched

After reverting, both tests pass again on the rebuilt tree.

This change was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Windows Release builds the production shim and passes all four presenter CTests at ac59fc3. The default setup uses one descriptor and only the opaque pipeline. The same fixture then configures the opt-in compositor and checks stacked and skipped planes. The overlay-removed control completed all eight fences and found exactly six changed cells out of eight. This addresses the two review findings. A matched real-executable comparison remains separate.

@R0Y00
R0Y00 merged commit c99b7b8 into R0Y00:main Nov 26, 2026
5 checks passed
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