Skip to content

startup: log the sampled presented colour when it changes - #3490

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:runtime-present-colour-log
Nov 30, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:runtime-present-colour-log

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Refs #3477 (item 5).

Default change: in render mode with X2W_PRESENT_SIGNATURE_EVERY unset, the log now gets one x2w-present sampled colour line for the first sample and one per colour change. X2W_PRESENT_SIGNATURE_EVERY=0 turns it off.

Why

In one long local run of the application the picture went from a uniform fill to black, and no log line says so. The sampled RGBA was logged only under the red-producer diagnostic.

What changes

x2w-present sampled colour: present=<n> rgba=<r>,<g>,<b>,<a> target=<w>x<h> format=<dxgi>
  • Logged for the first plane-0 colour sample and whenever its RGBA changes. Both sources sample the same point: the middle signature row, centre column.
  • While signature sampling runs (X2W_PRESENT_SIGNATURE_EVERY=<n> or a script picture wait), the colour comes from the signature sample.
  • Otherwise it comes from the existing plane-0 readback, for the 8-bit RGBA and BGRA formats that readback already reads.
  • No added GPU readback: the fallback reads one texel from the buffer the plane-0 readback has already mapped. That readback already runs every 6 or 60 presents; the colour is taken at most every 60 presents, so at most one line per 60 presents in the default mode. With X2W_PRESENT_SIGNATURE_EVERY=<n> the bound is one line per sample.
  • Raw-plane readbacks (X2W_PRESENT_COMPOSITE=1) never log.
  • The red-producer gate is unchanged (published && red_producers().enabled() && last_format == R8G8B8A8_UNORM), and it gets the same four bytes as before for that format.
  • Sampler now sets the last-sample fields only when Map succeeds and returns a pointer; a failed Map publishes nothing, as before.
  • present_signature is serialised by a mutex. Lock order is always the outer lock (signature mutex or the readback's), then the colour-log mutex.
  • docs/startup-runtime.md describes the line.

Tests

New startup_present_colour_warp (tests/cmake/startup_present_colour.cmake), driving startup_present_producer through uniform clears:

mode X2W_PRESENT_SIGNATURE_EVERY lines presents
colour (BGRA8) 1 4 1, 3, 5, 7
colour-readback (RGBA8) unset 4 60, 180, 300, 420
colour-readback 0 0
ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^(startup_present_(colour_warp|producer_(warp|hardware)|signature(_held_source|_unheld_source_control)?_warp|log(_control)?|readback)|startup_list_uav_barriers_(warp|hardware))$'

9 passed, 2 skipped, on 7684a835 (base 26df1826), X2W_WITH_OPUS=OFF. The two skips are startup_present_signature_held_source_warp and startup_present_signature_unheld_source_control_warp ("SKIP: no D3D12 debug layer"); they were not run.

Mutations, each rebuilt and run against startup_present_colour_warp:

  • Logging every sample instead of every change: fails, repeat lines at presents 1..7 against the expected 1, 3, 5, 7.
  • Dropping the log call: fails, no lines.

Not covered

  • The fallback samples at most every 60 presents, so a colour that changes and changes back between two samples is not logged.
  • One texel is sampled; a picture that changes elsewhere while the centre stays the same logs nothing.
  • The 10-bit layout is reduced to its top 8 bits per channel and is not exercised by the new test.

Merges cleanly with #3480 and #3482 (git merge-tree --write-tree).

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 7684a835 by reading the diff; not built or run.

Verdict: approve. The colour log does what the body says and adds no GPU work. One SHOULD, which can follow later. No MUST.

  • SHOULD: the line is logged on any exact RGBA change (d3d12_xs_device.cpp:2155). On a title's moving picture, the centre texel differs at almost every sample, so the default mode logs about one line per 60 presents all run. The fill-to-black change from #3477 then sits among lines that carry no signal. A small per-channel tolerance would keep it to real changes, as the luma signature does with its 12-level threshold. Uniform clears in the test cannot show this.
  • Both sources sample the same texel: the sampler copies full-width rows (present_signature_sampler.h:129), and read_back_presented copies the whole surface and returns early for formats other than 8-bit RGBA/BGRA (:2218). Both use sampled_row(cells_y / 2, Height) at Width / 2.
  • frame % 60 == 0 is always a readback frame (readback every 6 or 60 presents, :7815). X2W_PRESENT_SIGNATURE_EVERY=0 returns before anything runs. When it is set to n, the fallback is disabled.
  • Red producer: making capture_center always true is inert there. The R8G8B8A8_UNORM gate stays, sampled_rgba returns the raw bytes for rgba8, and the test asserts no x2w-red sample line.
  • Locks: the readback or signature mutex is taken first, then the colour mutex, never the reverse.

Tests: startup_present_colour_warp covers the signature path (BGRA8), the readback fallback (RGBA8) and the off switch, and both mutations fail it. CI did not run it: the pr preset's include list (CMakePresets.json:51) has neither it nor startup_present_producer_*, and /O2 was skipped on the PR. The body's local run is the only one at this head.

@R0Y00
R0Y00 merged commit c62f59c into R0Y00:main Nov 30, 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