Skip to content

Runtime: PresentX planes follow-up — compose in linear light, sRGB/gamma 2.2 SDR EOTF, Windows SDR white level, tone map for HDR on SDR outputs - #2069

Closed
AlxcBTW wants to merge 3 commits into
ItsNotRexed:mainfrom
AlxcBTW:presentx-planes
Closed

AlxcBTW wants to merge 3 commits into
ItsNotRexed:mainfrom
AlxcBTW:presentx-planes

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What and why

M7, PresentX planes, claimed in #1548. PresentX with one or two planes now composes on Vulkan. This replaces the path where plane parameters were logged and plane 1 was dropped.

How planes compose:

  • Plane 0 is scaled from its source rect into pDestPlacementBase, with point or bilinear filtering kept inside the source rect.
  • Plane 1 is alpha-blended over it, premultiplied by default or straight with a flag.
  • Colour: SDR and HDR10 (PQ) planes are converted to the swapchain's colour space. An ST.2084 swapchain is used when the surface lists one; otherwise HDR10 is clipped to SDR and logged once.

Implementation: a compute pass writes an RGBA16F image that is then copied into the swapchain, so the swapchain stays TRANSFER_DST-only and capture is unchanged. The pass is present_compose.comp, with its SPIR-V embedded the same way as depth24_convert. A plain single plane keeps the old vkCmdBlitImage path byte for byte; the test checks that compose at 1:1 gives the same pixels as the blit. Planes the pass can't read (depth, MSAA, integer, BC) return DXGI_ERROR_UNSUPPORTED, and a bad placement returns E_INVALIDARG.

What's documented, and what's ours:

  • The GameDVR copy: in Microsoft's public HDR10 sample, plane 1 isn't an overlay. It's the SDR copy of the same frame, which GameDVR and screenshots need. So an SDR plane 1 next to an HDR10 plane 0 is dropped as that copy, and logged once. The overlay reading applies when the flag is set or when both planes share a colour space.
  • Field names: pDestPlacementBase, ScaleFilter and Flags come from a public binding. Their layout and enum values aren't known.
  • Hypotheses, labelled in xbox_present.h and in docs/d3d12_vulkan.md §4.5:
    • placement as fractions of the output, read from a third-party mirror of the GDK reference and not confirmed on Microsoft's site;
    • the ScaleFilter values and the Flags bits;
    • premultiplied alpha as the default;
    • black outside plane 0;
    • blending in the encoded output space;
    • 203-nit SDR white.
  • Not done: tone mapping, scRGB, limited-range and YCbCr spaces, ResourceCount > 1, pExtendedDescs, and capturing a separate GameDVR output.

Tested

Head 76262214, AMD Radeon 880M (26.11.2) and NVIDIA RTX 5070 Laptop (617.42), Windows 11:

  • xbox_present_test, every case against a CPU model written from the documented behaviour, not from the shader, with LEONIDA_VK_VALIDATION=1 and 0 VUIDs on both GPUs:

    • point filtering between opaque planes: exact;
    • bilinear, both alpha modes and source rects: within 1 level;
    • HDR10→SDR clip, PQ encoding and white level: within 2 levels.

    Refused planes and bad placements are covered too.

  • Full ctest on both GPUs: 116 tests, and only d3d12_draw fails (on main since Runtime: carry bundle blend factors back to parent draws #1660). A subset of 7 tests (presenter, pacer, COM) passes 100% with validation on.

  • tests/test_ctest_registration.py: passes.

  • Not run on hardware: an actual HDR10 swapchain. Neither test display offers an ST.2084 surface with Windows HDR off, so the test logs that case as skipped. The clip and the PQ encoder were checked through a test hook. A run on an HDR display would be welcome.

Checklist

  • No game data, keys or decryption
  • xbox_present_test extended
  • Docs: §4.5 "Plane composition", the M7 row
  • Hypotheses marked as such

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@Flyander Flyander 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.

ResourceCount > 1 is listed as not implemented, but PresentX only rejects ResourceCount == 0 and both paths use ppResources[0]. A valid call with multiple resources therefore returns success after silently dropping every resource after the first, which can present the wrong frame. Until the format is implemented, please reject ResourceCount != 1 explicitly before either the compose or plain-blit path, and cover the unsupported case.

@IAmNotSiob

Copy link
Copy Markdown
Contributor

Tested 7626221 on NVIDIA RTX 6000 Ada (582.70), Windows 10 22H2, a third GPU and an older Windows: pass :)

  • xbox_present passes (all plane cases)
  • full ctest: 117/117 (d3d12_present skips: no physical display on this box, it's a VM with the GPU passed through)

no HDR display here either, sorry. AI-assisted (Claude Code).

@CharlyRien

Copy link
Copy Markdown

Code review of 7626221 (AI-assisted), with probes on RTX 3090, driver 616.56, Windows 11 23H2, under LEONIDA_VK_VALIDATION=1. The PR's own xbox_present_test passes validation-clean here too. The items below are not covered by it. Proved means reproduced with a probe added to the test in a private copy (nothing pushed). Reasoned means from reading the code.

  1. A resize that shows up at acquire leaves the compose target at the old size, so the blit reads out of bounds (proved). In vulkan_present.h submit(), prepare_compose() (~L329) sizes the RGBA16F target to extent_ before acquire() (~L337). On VK_ERROR_OUT_OF_DATE_KHR, recreate() changes extent_, but prepare_compose() isn't called again before record_planes().

    • When the window grows, the dispatch covers only the old size, and vkCmdBlitImage copies an extent_-sized region out of the smaller image.
    • Repro: composed present at 320×240, window resized to 480×360, next composed present with acquire forced to OUT_OF_DATE (a probe hook, since the 3090's real acquire succeeded after the resize):
      vkCmdBlitImage(): pRegions[0].srcOffsets[0].x is 0 and srcOffsets[1].x is 480 which exceed srcSubresource width extent (320)  (VUID-vkCmdBlitImage-srcOffset-00243)
      
    • Fix: call prepare_compose() again after a successful recreate() in that branch, or size the target in record_planes().
  2. HDR10 output can't be selected by the real runtime (reasoned). VK_EXT_swapchain_colorspace is enabled only in runtime/test/vk_test_device.h (L213). create_vulkan_device_standalone in d3d12_vulkan_device.cpp never enables it, and that is what the game path uses.

    • Without the instance extension, the surface won't list VK_COLOR_SPACE_HDR10_ST2084_EXT formats, so the HDR10 path (vulkan_present.h ~L889) always falls back to SDR outside the test harness.
    • If a driver lists them anyway, the swapchain would be created with a colour space whose extension isn't enabled (VUID-VkSwapchainCreateInfoKHR-imageColorSpace-parameter).
    • I couldn't check either case on hardware: this display has no ST.2084 format.
    • Fix: enable it on the standalone instance when the loader lists it, as the test device does.
  3. Straight-alpha bilinear filtering darkens overlay edges (proved). present_compose.comp fetch_plane interpolates straight-alpha texels without weighting by alpha, then blends with mix(base, over, a), so transparent-black texels pull the colour down.

    • Repro: plane 0 solid grey 128; plane 1 a 4×1 linear straight-alpha texture (two transparent black, two opaque white) stretched over the output. Minimum R across the row is 112, while correct filtering never goes below 128.
    • The test's CPU reference makes the same mistake, which is why it passes.
    • Fix: premultiply before filtering and divide after (and the same in the CPU model).
  4. The GameDVR rule also matches an HDR10 overlay over SDR (reasoned). xbox_present.cpp (~L85) treats any HDR mismatch between the planes as the GameDVR copy (is_hdr10(p1) == hdr0 || flag).

    • An HDR10 plane 1 over an SDR plane 0 counts too. With no placement and the default filter on plane 0, it takes the plain-blit path and plane 1 is dropped.
    • The log then says "HDR10 plane 0 and an SDR plane 1", which is the opposite case.
  5. The swapchain is recreated on every switch between composed HDR10 and plain SDR presents (reasoned, minor). submit() compares want_hdr with swapchain_hdr_req_ (the request) rather than hdr_active_. So on a surface with no ST.2084 format, each switch costs a vkQueueWaitIdle and a swapchain with the same format.

Checked and found correct:

  • Per-frame descriptor sets (2 slots for 2 frames, updated after the fence wait).
  • Plane views released only after the fence: freeing a source right after a composed present was validation-clean.
  • Compose-target and source barriers, and layout rollback.
  • Point and bilinear fetches clamped inside the source rect.
  • pow inputs, and the PQ and BT.709/2020 constants.
  • Un-premultiply and re-premultiply around the conversion.
  • Odd extents.
  • Placement and source-rect validation, NaN included.
  • Blank presents.

Synthetic probes only, no game files.

@JavierBlanco23

Copy link
Copy Markdown
Contributor

Tested 76262214 on NVIDIA GeForce RTX 5080, driver 616.56, Windows 11 (MSVC 19.44, Ninja, HDR10 surface): pass.

  • xbox_present_test.exe: all cases pass (scaled/placed compose, 2-plane overlays, native HDR10 ST.2084 swapchain within 1 code, GameDVR drop, tearing swapchain_maintenance1: yes).
  • d3d12_present_test.exe: passed (70 frames, screen pixel match).

@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 9bf0794 (fast-forward on 7626221) with the review fixes:

  • Resize / out-of-date (HIGH): the compose target is prepared again after the acquire/recreate retry, and record_planes checks the target extent against the swapchain and records nothing on a mismatch. xbox_present_test now resizes the window (320x240 -> 400x300 -> 200x150 -> 320x240) between composed presents and compares every frame with the CPU model. I can't force the out-of-date acquire deterministically, so that exact retry is covered by the guard, not by a test that provably hits it.
  • Struct order (HIGH): XboxPresentPlaneParameters now follows the cited public order exactly (Token, ResourceCount, ppResources, pSrcViewRects, pDestPlacementBase, ColorSpace, ScaleFilter, ExtendedDescCount, pExtendedDescs, Flags; source named in the header and docs; types and sizes are ours). A placement that is not a sub-rectangle of 0..1, an unknown ScaleFilter and extended descriptors are ignored and logged once rather than refused; a single SDR plane with null/zero extras stays on the plain blit.
  • SDR/SDR no longer blends by default (MED): plane 1 is composed only with our xbox_plane_flag_overlay (hypothesis, documented); the test is adjusted.
  • White level (low): present_planes rejects a non-positive or NaN sdr_white_nits.
  • ResourceCount (@Flyander): ResourceCount != 1 returns DXGI_ERROR_UNSUPPORTED (logged once) before either path; tested for the plain, compose and plane-1 cases. Thanks for catching it.
  • Docs: bilinear filtering of HDR10 planes is on PQ-encoded values (unmeasured choice); HDR10 swapchain verified on an RTX 5080 with an HDR10 display by @JavierBlanco23 (not on AMD).

Tested 9bf0794 on AMD Radeon 880M (26.11.2) and NVIDIA RTX 5070 Laptop (617.42), Windows 11: xbox_present_test passes with LEONIDA_VK_VALIDATION=1, 0 VUIDs, on both (including the resize case); presenter/pacer/com subset (7 tests) 100% with validation on both; full ctest on both 116 tests, only d3d12_draw (#1660) fails; pytest tests/test_ctest_registration.py 4 passed.

Thanks @JavierBlanco23 for the RTX 5080 HDR10 run, and @IAmNotSiob for the RTX 6000 Ada / Windows 10 run.

AI-assisted (Claude Code).

@Flyander Flyander 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.

Thanks, the ResourceCount != 1 guard from my previous review is now present and covered. Two remaining runtime issues still block this head:

  1. The HDR10 path selects VK_COLOR_SPACE_HDR10_ST2084_EXT, but create_vulkan_device_standalone does not enable VK_EXT_swapchain_colorspace on the instance. The test device does enable it, so harness coverage does not prove the game runtime can enumerate or create that surface format; in the standalone path HDR10 will fall back to SDR or fail to select the intended surface. Please enable the instance extension when enumerated and add coverage on the real instance path.

  2. For a straight-alpha overlay with linear filtering, fetch_plane bilinearly interpolates unassociated RGB before the blend. Transparent black next to opaque white therefore produces RGB=0.5, A=0.5, then mix(base, 0.5, 0.5), which contributes only 0.25 over a black base instead of 0.5. Premultiply before filtering (or filter RGB*A and alpha separately), and add a case with a transparent edge; the current CPU reference must model the correct premultiplied filtering independently.

@lahlousaad4

Copy link
Copy Markdown
Contributor

Tested 9bf0794813 on Windows 11 build 26200, MSVC 19.44, RTX 4060 driver 610.88, Khronos validation 1.4.369. The four targeted CTest cases (xbox_present, frame_pacer, d3d12_present, d3d12_com) passed with no Vulkan validation errors.

The PresentX test verified the one- and two-plane paths, scaling, blending, resize and HDR10 ST.2084 swapchain readback within one code value. It presented 30 frames in 503 ms. The forced-encoding fallback cases were skipped because an HDR10 surface was available. The GDI screen-colour check was skipped because the test window was in the background. No game files used.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression. RTX 4080 SUPER: 115/116. Not from this PR: d3d12_draw (the bundle-blend regression on main, fixed by #1995). The other Intel UHD 770 failures are known (#2078): d3d12_descriptor, d3d12_present, d3d12_m3_frame, d3d12_subgroup.

@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 0a3bf1e (fast-forward on 9bf0794), fixing both points from @Flyander's review:

  1. VK_EXT_swapchain_colorspace on the real instance: create_vulkan_device_standalone now enables it when the loader lists it (it did not; only the test device did), so the HDR10 ST.2084 surface formats can actually be listed in the game runtime. New VulkanDeviceInfo::swapchain_colorspace and device_has_swapchain_colorspace(); xbox_present_test now goes through create_vulkan_device_standalone, checks the flag against the loader's instance extensions, builds a window presenter on it and presents. Both GPUs report it enabled.
  2. Straight alpha + bilinear: straight-alpha planes are now filtered on premultiplied colour (colour times alpha, then divided by the filtered alpha), so a transparent texel adds no colour of its own. The CPU model does the same independently (weights per texel, associated-colour accumulation), and a new transparent-edge case (opaque white next to transparent black, linear filter) also checks one pixel against the hand-computed value (red 102, blue 236; the old behaviour gives about 54 for red).

Tested 0a3bf1e on AMD Radeon 880M (26.11.2) and NVIDIA RTX 5070 Laptop (617.42), Windows 11: xbox_present_test passes with LEONIDA_VK_VALIDATION=1, 0 VUIDs, on both; the 7-test presenter/pacer/com subset passes with validation on both; full ctest on both is 116 tests with only d3d12_draw (#1660) failing. Docs §4.5 updated.

AI-assisted (Claude Code).

@Flyander Flyander 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.

The follow-up addresses the remaining issues from my reviews: the standalone runtime instance now enables VK_EXT_swapchain_colorspace when available, and straight-alpha bilinear filtering now accumulates premultiplied colour before unassociating it. The earlier ResourceCount guard is still present. The author reports validation-clean runs on the Radeon 880M and RTX 5070 Laptop, including the new standalone-path and transparent-edge cases. I found no remaining blocker in these paths.

@nonverifiedperson

Copy link
Copy Markdown
Contributor

Tested 9bf07948 on two GPUs: no regressions. Every result matches the main baseline, and the tests this PR touches pass in all four runs.

Windows 10 22H2, MSVC 19.44, Vulkan SDK 1.4.363.0, scripts/build_runtime.ps1 (RelWithDebInfo, Ninja), builds clean. GPU chosen with LEONIDA_VK_DEVICE.

  • AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, RDNA2), AMD driver 32.0.13036.4
  • NVIDIA RTX 5070 Ti, driver 32.0.16.2135

ctest, PR vs baseline (baseline = 4eb6155d, the merge base, built the same way):

GPU LEONIDA_VK_VALIDATION PR main VUIDs (PR / main)
Radeon 0 2 of 116 fail same 2 —
Radeon 1 2 of 116 fail same 2 1 / 1
RTX 5070 Ti 0 1 of 116 fails same 1 —
RTX 5070 Ti 1 1 of 116 fails same 1 1 / 1
  • xbox_present, frame_pacer, d3d12_present and d3d12_com pass in all four runs.
  • Already failing on main, identical with and without the PR: d3d12_draw on both GPUs (bundle blend check, "got 128,0,128,255, expected red 64") and, on the Radeon only, d3d12_vulkan_device at line 3594: argument_mismatches <= 0. The only VUID is VUID-vkDestroyPipeline-pipeline-00765, also on main.

scripts/run_gpu_tests.py at the PR head: Radeon 167/180 passed, 13 skipped; RTX 5070 Ti 136/180 passed, 44 skipped (wave64 tests without emulation). No failures, same as main.

This is the current head; the earlier Radeon 880M and NVIDIA runs in the thread were at 76262214. What it doesn't cover: no HDR display here, so the HDR plane path is checked only by the tests; nothing looked at on screen.

No game files. AI-assisted (Claude Code).

…F, Windows SDR white level, tone map

- Compose pass decodes every texel to linear (premultiplied) before filtering, converts the plane to the output's linear
  working space (Rec.2020 nits for HDR10, Rec.709 relative to SDR white for SDR), blends there and encodes once.
- SDR EOTF is piecewise sRGB by default (community-sourced Windows behaviour), gamma 2.2 by
  XboxPresentation::set_sdr_eotf or LEONIDA_SDR_EOTF=gamma22.
- SDR white: set_sdr_white_nits override, else DISPLAYCONFIG_SDR_WHITE_LEVEL of the window's output while HDR10 is
  active, else 203 nits (BT.2408).
- HDR10 on an SDR output: extended Reinhard on luminance (white point at the content peak, default 1000 nits) instead of a
  hard clip.
- HDR metadata stays unsent; docs section 4.5 documents the decisions and cites the sources.
- CPU reference model and xbox_present_test updated (linear model, EOTF option, 50% overlay, tone map, white level query).
- present_compose.inc rebuilt with glslc 2026.4 (byte-reproducible, spirv-val clean).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@Flyander the head moved after your approval (97daa1a -> 0963784), so please re-check. It changes the PresentX plane compose pass only; the single-plane SDR blit path is untouched (a plain SDR plane still goes through the old vkCmdBlitImage, and at 1:1 the compose pass is still byte-equal to it).

What changed (docs section 4.5 has the details and all links):

  1. Linear-light filtering and blending. Each texel is decoded to linear (premultiplied) before it is weighted, the plane is converted to the output's linear working space (Rec.2020 nits for HDR10, Rec.709 relative to SDR white for SDR), plane 1 is blended there, and the result is encoded once. Basis: Microsoft's Advanced Color doc (DWM composes in linear scRGB; apps that mix SDR and HDR scale SDR by SdrWhiteLevel/80 in linear; convert HDR10 to linear before adjusting). A 50% white overlay on black is now byte 188, not 128. Whether the title expects encoded-space blending is still unmeasured and stays flagged as such.
  2. SDR EOTF selectable. Default is piecewise sRGB, option gamma 2.2 (set_sdr_eotf or LEONIDA_SDR_EOTF=gamma22). The default is community-sourced (Xaver Hugl's KDE blog, 2025-03-31; ledoge/win11hdr-srgb-to-gamma2.2-icm), not a Microsoft statement. The Xbox's own behaviour is unmeasured.
  3. SDR white level. set_sdr_white_nits still overrides. Otherwise, while the swapchain is HDR10, the layer reads DISPLAYCONFIG_SDR_WHITE_LEVEL for the window's output (nits = level / 1000 * 80, at most once a second); else 203 nits (BT.2408).
  4. HDR10 on an SDR output is tone mapped instead of hard clipped: extended Reinhard on luminance (Reinhard et al. 2002, eq. 4) with the white point at the content peak (default 1000 nits, set_hdr_peak_nits, an assumption since no metadata is read). Known trade-off, documented: SDR white (203 nits) comes out at about half the linear light (byte 191); a knee or BT.2390 is not done.
  5. No HDR metadata is sent (vkSetHdrMetadataEXT is never called). Microsoft no longer recommends SetHDRMetaData, and vkd3d-proton forwards it only for an explicit HDR10 block; we invent no mastering values.

Tests: the CPU reference model in xbox_present_test is now linear-light (decode, convert, blend, encode in double precision); tolerances unchanged and documented (0 for point, 1 for bilinear/alpha/EOTF, 2 where PQ or the tone map is involved). New cases: sRGB vs gamma 2.2 50% overlay, tone map at peaks 1000 and 600, SDR white level conversion and the live Windows query. The push constants grew from 96 to 112 bytes; the SPIR-V was rebuilt with glslc --target-env=vulkan1.1 -O -mfmt=c (glslc 2026.4; the old shader reproduced byte for byte first, the new one twice; spirv-val --target-env vulkan1.1 clean).

Tested 0963784 on AMD Radeon 880M (RDNA3.5, AMD driver 26.11.2, Windows 11) with LEONIDA_VK_VALIDATION=1: pass. xbox_present_test all cases pass, 0 VUIDs; full ctest 124/124 passed (5 skipped by their own conditions, gameinput disabled), 0 VUIDs.
Tested 0963784 on NVIDIA GeForce RTX 5070 Laptop GPU (617.42, Windows 11) with LEONIDA_VK_VALIDATION=1: pass. xbox_present_test all cases pass, 0 VUIDs; full ctest 124/124 passed (6 skipped, gameinput disabled), 0 VUIDs.
Not run: a real HDR10 swapchain (neither laptop has HDR enabled; the Windows white-level query returned 80.0 nits on this SDR desktop). The earlier RTX 5080 HDR10 check by @JavierBlanco23 covered the pass-through path before this change; a re-run with the new pass would be welcome.

AI-assisted (Claude Code).

…ath, review fixes

- Tone map: identity up to 0.8 of SDR white, extended Reinhard shoulder above it, continuous in value and slope, content
  peak maps to 1.0 (SDR-range content is no longer darkened).
- The Windows SDR white level is read by a background thread (about once a second, only while HDR10 is in use);
  PresentX reads an atomic. A failed query keeps the last good value; QueryDisplayConfig retries on
  ERROR_INSUFFICIENT_BUFFER.
- LEONIDA_SDR_EOTF is case-insensitive, unknown or too long values are logged; setters are atomics; <cwchar> for wcscmp.
- Tests: eight-step HDR10 ramp with hand-calculated bytes, curve properties (monotonic, identity below the knee, peak 1,
  slope continuity), HDR10 plane 1 over SDR plane 0 on HDR10 and SDR outputs, hand-calculated 50% overlay bytes, query cost.
- Docs 4.5: shoulder description, query cost, sources marked (KWin claim unverified, vkd3d-proton file partly read, the
  measured 80 nits only covers the SDR fallback path).
- present_compose.inc rebuilt with glslc 2026.4 (reproducible, spirv-val clean).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Review fixes pushed: head is now d3b774ee (was 09637840). Changes since the last comment:

  1. SDR white query is off the present path. A background thread reads DISPLAYCONFIG_SDR_WHITE_LEVEL about once a second, only while an HDR10 swapchain is in use; PresentX reads an atomic. Measured cost of one query (50 calls, xbox_present_test, HDR off): AMD run 12 us mean / 70 us worst, NVIDIA run 47 us mean / 361 us worst. That is small on this machine; the worst case with several displays or during a mode change is unmeasured, which is why it stays off the present lock. Stated in docs 4.5.
  2. QueryDisplayConfig retries on ERROR_INSUFFICIENT_BUFFER, and a failed query keeps the last good value instead of falling back to 203.
  3. Tone map is now a shoulder: identity up to 0.8 of SDR white (162 nits at 203), extended Reinhard on the excess above it, continuous in value and slope at the knee, content peak maps to exactly 1.0. SDR-range content is untouched. The docs no longer say "dark colours unchanged" about the old curve. Above the knee it still compresses (203 nits -> byte 243 at peak 1000).
  4. Tests: an eight-step HDR10 grey ramp (50..1000 nits, peaks 1000 and 600) checked against hand-calculated bytes (written separately from the model), plus curve properties (monotonic, identity below the knee, peak -> 1, slope continuity); HDR10 plane 1 (premultiplied, alpha 2/3) over SDR plane 0 on a forced HDR10 output (byte 155) and on the SDR output (byte 211), both hand calculated; the 50% overlay now also asserts literal 188 / 186. The reverse case (SDR plane 1 over HDR10 plane 0) was already covered.
  5. Docs: the KWin claim is marked unverified (search snippet only, URL given); the Microsoft SetHDRMetaData statements cite the page, vkd3d-proton swapchain.c is marked as partly read (first ~100k of ~175k characters); the scaled-Reinhard remark is attributed to the Advanced Color document; the measured 80 nits is stated to cover only the SDR path where the layer ignores it, and the HDR value has not been read on real HDR hardware.
  6. LEONIDA_SDR_EOTF is case-insensitive, unknown or too long values (ERANGE) are logged, the setters are atomics, <cwchar> is included.

SPIR-V rebuilt with glslc --target-env=vulkan1.1 -O -mfmt=c (2026.4): second build identical, spirv-val --target-env vulkan1.1 clean. Merge-tree against fresh origin/main is clean.

Tested d3b774e on AMD Radeon 880M (RDNA3.5, AMD driver 26.11.2, Windows 11), LEONIDA_VK_VALIDATION=1: xbox_present_test all cases pass, 0 VUIDs; full ctest 123/124 in one parallel (-j2) run, 124/124 after re-running the one failure alone (d3d12_vulkan_device).
Tested d3b774e on NVIDIA GeForce RTX 5070 Laptop (617.42, Windows 11), same settings: xbox_present_test all cases pass, 0 VUIDs; full ctest 123/124 in one -j2 run, 124/124 after re-running the failure alone (queue_proxy). The two failures are in host-runtime comparison tests, different on each GPU and not in the presenter; I did not find their cause, they passed alone, and the machine was busy with other builds. Skipped tests are the usual ones (5 on AMD, 6 on NVIDIA, gameinput disabled). No real HDR10 swapchain was available.

AI-assisted (Claude Code).

@AlxcBTW AlxcBTW changed the title Runtime: PresentX planes — scaled/placed plane 0, alpha-blended overlay plane 1, SDR/HDR10 to the swapchain colour space (M7) Runtime: PresentX planes follow-up — compose in linear light, sRGB/gamma 2.2 SDR EOTF, Windows SDR white level, tone map for HDR on SDR outputs Nov 22, 2026
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Merge round 41 merged this PR's earlier head 97daa1ae into main (as 76262214), so plane composition itself has landed. Thanks!

I merged main back in (cea9d05e). The only conflict was the M7 row in docs/d3d12_vulkan.md, where main had the M6 and M7 rows twice. I kept one of each, with the updated M7 text. What's left in this PR is the follow-up from 09637840 and d3b774ee, all described above:

  • composition in linear light;
  • SDR decoded with piecewise sRGB by default, gamma 2.2 as an option;
  • the SDR white level read from Windows off the present thread;
  • HDR on SDR swapchains tone mapped instead of clipped.

I've renamed the PR to match.

AI-assisted (Claude Code).

@jeremygold02 jeremygold02 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.

A fully transparent overlay changes the brightness of a scaled UNORM frame. I compared base f847748c with head cea9d05e using the real PresentX and a readback of the SDR swapchain. On head, adding a 1×1 RGBA-zero overlay changed 38,400 of 76,800 pixels on both GPUs. The maximum change was 73 gray levels out of 255. On base, the largest change was one level.

Plane 0 was an opaque 2×1 black/white edge scaled across a 320×240 output. The table gives RGB byte values at output columns 119, 159 and 199. The full-frame error checks below include all three color channels.

Plane 0 and present call Base Head
RGBA8 UNORM, default filter, one plane 63 / 127 / 190 63 / 127 / 190
Same plane and filter, transparent overlay enabled 63 / 127 / 190 136 / 187 / 224
Same plane alone, explicit linear filter 63 / 127 / 190 136 / 187 / 224
RGBA8 sRGB source control, all three calls 136 / 187 / 224 136 / 187 / 224

The three samples agree on the sRGB control. Across the whole frame, the sRGB blit and composition differed by up to 3 levels. For UNORM on head, the plain blit matched encoded-space interpolation within 1 level and the compositor matched linear-light interpolation within 1 level. The independent CPU references use w = clamp(2*(x+0.5)/320 - 0.5, 0, 1), then round either 255*w or 255*sRGB_OETF(w). Both UNORM calls captured B8G8R8A8_UNORM. The compose counter advanced only for the overlay and explicit-linear calls. The legacy blit and the compositor therefore apply different transfer behavior to plane 0, even when plane 1 contributes zero light. Path selection at the checked head · Compositor sampling

Could scaled UNORM plane 0 use the same transfer behavior whether or not an overlay is present? The existing 1:1 comparison would still cover the unscaled fast path. If maintaining the legacy scaled blit takes precedence, please document the visible transition and cover it with this two-texel case. The intended console behavior remains unmeasured.

Reproduction. In runtime/test/xbox_present_test.cpp, insert the block below immediately before // 1 plane, solid colour, RGBA8. on either revision. Build xbox_present_test in Release, set LEONIDA_OVERLAY_PROBE=1 and LEONIDA_SDR_EOTF=srgb, then run it once with LEONIDA_VK_DEVICE=NVIDIA and once with LEONIDA_VK_DEVICE=Intel. It performs six synthetic frame captures per run.

Hardware exercised. Intel Core Ultra 7 265K, Windows 11 Home 26200.9974, MSVC 19.44. Each GPU independently rendered and read back all six cases on both revisions: NVIDIA GeForce RTX 5070, driver 621.01 (32.0.16.2101), and Intel(R) Graphics, driver 32.0.101.9150. The stock xbox_present CTest also passed all four revision/GPU combinations. Vulkan validation was off. This measures swapchain image bytes before desktop composition.

AI-assisted by GPT-6.2 Astra.

Exact probe block
if (GetEnvironmentVariableA("LEONIDA_OVERLAY_PROBE", nullptr, 0)) {
    const FLOAT clear[4] = {0, 0, 0, 0}, black[4] = {0, 0, 0, 1}, white[4] = {1, 1, 1, 1};
    const D3D12_RECT right{1, 0, 2, 1};
    Source overlay;
    EXPECT(make_source(DXGI_FORMAT_R8G8B8A8_UNORM, overlay, 1, 1));
    EXPECT(fill(overlay, clear));
    for (auto format : {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB}) {
        Source edge;
        EXPECT(make_source(format, edge, 2, 1));
        EXPECT(fill(edge, black) && fill(edge, white, 1, &right));
        Frame plain;
        for (int pass = 0; pass < 3; ++pass) {
            clock.advance_us(4 * period);
            EXPECT(next_token(token));
            rt::d3d12::XboxPresentPlaneParameters planes[] = {plane_of(edge, token), plane_of(overlay, token)};
            planes[1].Flags = rt::d3d12::xbox_plane_flag_overlay;
            if (pass == 2) planes[0].ScaleFilter = rt::d3d12::xbox_scale_filter_linear;
            auto before = xbox.presenter().composed_presents();
            EXPECT(xbox.PresentX(pass == 1 ? 2 : 1, planes, nullptr) == S_OK && grab(frame));
            EXPECT(frame.format == VK_FORMAT_B8G8R8A8_UNORM || frame.format == VK_FORMAT_R8G8B8A8_UNORM || frame.srgb());
            if (pass == 0) plain = frame;
            unsigned changed = 0;
            int max_delta = 0, encoded_error = 0, linear_error = 0;
            for (UINT x = 0; x < width; ++x) {
                double w = std::clamp((x + 0.5) * 2.0 / width - 0.5, 0.0, 1.0);
                int encoded = int(std::lround(255 * w));
                int linear = int(std::lround(255 * (w <= 0.0031308 ? 12.92*w : 1.055*std::pow(w, 1.0/2.4)-0.055)));
                for (UINT y = 0; y < height; ++y) {
                    Px a = frame.at(x, y), b = plain.at(x, y);
                    int delta = std::max({std::abs(a.r-b.r), std::abs(a.g-b.g), std::abs(a.b-b.b)});
                    changed += delta != 0;
                    max_delta = std::max(max_delta, delta);
                    for (int c : {a.r, a.g, a.b}) {
                        encoded_error = std::max(encoded_error, std::abs(c-encoded));
                        linear_error = std::max(linear_error, std::abs(c-linear));
                    }
                }
            }
            std::printf("probe src=%d pass=%d vkfmt=%d composed=%llu x119/159/199=%d/%d/%d changed=%u max_delta=%d err_encoded=%d err_linear=%d\n",
                        int(format), pass, int(frame.format), (unsigned long long)(xbox.presenter().composed_presents()-before),
                        frame.at(119, 0).r, frame.at(159, 0).r, frame.at(199, 0).r, changed, max_delta, encoded_error, linear_error);
            EXPECT(xbox.presenter().composed_presents() - before == (pass == 0 ? 0u : 1u));
            EXPECT(region_is(frame, 0, 0, width / 4, height, {0, 0, 0}, 0));
            EXPECT(region_is(frame, 3 * width / 4, 0, width, height, {255, 255, 255}, 0));
        }
    }
    return 0;
}

@AlxcBTW

AlxcBTW commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Both follow-up commits from this PR, 09637840 (linear light, SDR EOTF, Windows SDR white) and d3b774ee (tone-map shoulder, SDR white query moved off the present path), are now on main. The only thing left on the branch is my merge commit, so I'm closing this as done. Thanks to everyone who tested it, in particular @Flyander and @JavierBlanco23.

AI-assisted (Claude Code).

@AlxcBTW AlxcBTW closed this Nov 23, 2026
ItsNotRexed pushed a commit that referenced this pull request Nov 23, 2026
Section 6's milestone table had M2, M3, M6 and M7 twice each, an older row
next to the one that replaced it, left by merges. The two M6 rows disagreed on
the BVH builder's FSSM programs (42 pass with four rules left, or 51 with one).
Kept: M2 with the d3d12_m2_formats results, M3 with the single-output
occlusion probe (D3D-209, as the text under the table says), M6 at 51 of 52,
and M7 with plane compose done (#2069). Dropped the older copies.

tests/test_docs_table_ids.py fails when a Markdown table names the same bold
ID (`**M2**`) in two rows. Tables keyed by plain values repeat them on purpose
and are not checked. It fails on main f847748 and passes here.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	docs/d3d12_vulkan.md
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.

9 participants