Repository navigation
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
Conversation
Flyander
left a comment
There was a problem hiding this comment.
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.
|
Tested
no HDR display here either, sorry. AI-assisted (Claude Code). |
|
Code review of 7626221 (AI-assisted), with probes on RTX 3090, driver 616.56, Windows 11 23H2, under
Checked and found correct:
Synthetic probes only, no game files. |
|
Tested
|
|
Pushed 9bf0794 (fast-forward on 7626221) with the review fixes:
Tested 9bf0794 on AMD Radeon 880M (26.11.2) and NVIDIA RTX 5070 Laptop (617.42), Windows 11: Thanks @JavierBlanco23 for the RTX 5080 HDR10 run, and @IAmNotSiob for the RTX 6000 Ada / Windows 10 run. AI-assisted (Claude Code). |
Flyander
left a comment
There was a problem hiding this comment.
Thanks, the ResourceCount != 1 guard from my previous review is now present and covered. Two remaining runtime issues still block this head:
-
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.
-
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.
|
Tested 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. |
|
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: |
|
Pushed 0a3bf1e (fast-forward on 9bf0794), fixing both points from @Flyander's review:
Tested 0a3bf1e on AMD Radeon 880M (26.11.2) and NVIDIA RTX 5070 Laptop (617.42), Windows 11: AI-assisted (Claude Code). |
Flyander
left a comment
There was a problem hiding this comment.
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.
|
Tested Windows 10 22H2, MSVC 19.44, Vulkan SDK 1.4.363.0,
This is the current head; the earlier Radeon 880M and NVIDIA runs in the thread were at 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>
|
@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 What changed (docs section 4.5 has the details and all links):
Tests: the CPU reference model in Tested 0963784 on AMD Radeon 880M (RDNA3.5, AMD driver 26.11.2, Windows 11) with 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>
|
Review fixes pushed: head is now
SPIR-V rebuilt with Tested d3b774e on AMD Radeon 880M (RDNA3.5, AMD driver 26.11.2, Windows 11), AI-assisted (Claude Code). |
# Conflicts: # docs/d3d12_vulkan.md
|
Merge round 41 merged this PR's earlier head I merged
I've renamed the PR to match. AI-assisted (Claude Code). |
# Conflicts: # docs/d3d12_vulkan.md
jeremygold02
left a comment
There was a problem hiding this comment.
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;
}|
Both follow-up commits from this PR, AI-assisted (Claude Code). |
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>
# Conflicts: # docs/d3d12_vulkan.md
What and why
M7, PresentX planes, claimed in #1548.
PresentXwith 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:
pDestPlacementBase, with point or bilinear filtering kept inside the source rect.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 asdepth24_convert. A plain single plane keeps the oldvkCmdBlitImagepath 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) returnDXGI_ERROR_UNSUPPORTED, and a bad placement returnsE_INVALIDARG.What's documented, and what's ours:
pDestPlacementBase,ScaleFilterandFlagscome from a public binding. Their layout and enum values aren't known.xbox_present.hand indocs/d3d12_vulkan.md§4.5:ScaleFiltervalues and theFlagsbits;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, withLEONIDA_VK_VALIDATION=1and 0 VUIDs on both GPUs:Refused planes and bad placements are covered too.
Full ctest on both GPUs: 116 tests, and only
d3d12_drawfails (onmainsince 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
xbox_present_testextendedAI-assisted (Claude Code).
🤖 Generated with Claude Code