startup: log the sampled presented colour when it changes #3492

Manually merged
github merged 1 commit from github-bot/gh-3490 into gh-pr/3490/base 2026-11-30 08:51:02 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-29 17:38 UTC · original
Leyukaka:runtime-present-colour-log → main · +139 −41 · 6 files · 1 commits · merged 2026-11-30 08:45 UTC

Refs #3479 (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 #3482 and #3484 (git merge-tree --write-tree).

**@⁠Leyukaka** on GitHub · 2026-11-29 17:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3490) `Leyukaka:runtime-present-colour-log` → `main` · +139 −41 · 6 files · 1 commits · merged 2026-11-30 08:45 UTC Refs #3479 (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 ```text 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 | | ```text 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 #3482 and #3484 (`git merge-tree --write-tree`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 17:39:27 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 08:13 UTC · original · approved these changes

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 #3479 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.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 08:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3490#pullrequestreview-6108727917) · **approved these changes** 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 #3479 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.
github-bot changed target branch from main to gh-pr/3490/base 2026-11-30 08:51:01 +00:00
github manually merged commit 7684a83528 into gh-pr/3490/base 2026-11-30 08:51:02 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.