Skip to content

D3D12.X: preserve the sRGB base with linear overlays - #2811

Closed
CryingLaughing wants to merge 4 commits into
xcl-dev:mainfrom
CryingLaughing:fix/present-primary-srgb-transfer
Closed

CryingLaughing wants to merge 4 commits into
xcl-dev:mainfrom
CryingLaughing:fix/present-primary-srgb-transfer

Conversation

@CryingLaughing

@CryingLaughing CryingLaughing commented Nov 26, 2026 •

Copy link
Copy Markdown

Stacked on #2763, which follows #2537. The top commit 96b0b189fd0a8991c8e7883823191cf54d896223 is the change under review.

An UNORM overlay could force an sRGB scene to be stored as linear bytes. The primary plane already selects the SDR swap-chain format. Use it to select the compositor’s output transfer too, and keep each input plane’s own SRV format.

What is in it

  • Selects the 8-bit SDR output RTV and pipeline state from the opaque base plane in present.rs.
  • Extends the offscreen compositor regression to mixed input formats, including the reverse case where the base is UNORM.

Tested

  • Exact head 96b0b189fd0a8991c8e7883823191cf54d896223, with D3D12.X: encode sRGB compositor output for presentation #2763 head 0d380f427797fb91a07512d074a5f6f4e1892674 as its parent. RTX 4080 driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11, debug.
  • The WARP control on D3D12.X: encode sRGB compositor output for presentation #2763 failed at the mixed-format assertion with [128,55,0,255]. The native RTX 4080 fixture on the new production revision passed 1/0/0 with no capability skips over five offscreen cases. With an sRGB base and transparent UNORM overlay, it read [188,128,0,255]. A fractional overlay read [137,161,0,255]. The reverse case read [0,64,127,255] for the fractional sample. The BGRA case also passed.
  • The exact portable compositor_blends_ui_plane_over_scene_plane test passed 1/0/0. cargo build --workspace --locked -j 4 succeeded. cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output reported 1,436 passed, 0 failed, 47 ignored across 37 harnesses. The pass count includes 29 capability skips.

Regression run

Independent retail smoke by Anon64 compared release builds of main and this exact head on an RTX 3060 12 GB (driver 581.80), Core i9-14900KF, and Windows 11 build 26200. The 60-second runs used the same title. The head retained 101.4% of the baseline frames and used 97.7% of its peak commit, with zero crashes or device removals. The run did not establish whether the title reached the changed code.

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1462)
presents per 2 s (last 3): 10 1 1
device removals: 0
crashes: 0
peak commit: 23855 MB

PR:

xcl-smoke v1
commit: 96b0b189fd0a8991c8e7883823191cf54d896223
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1482 (PresentX 1482)
presents per 2 s (last 3): 23 4 5
device removals: 0
crashes: 0
peak commit: 23309 MB

Not tested

  • Physical display output, mixed-format retail coverage, and other GPU vendors.

ramon-victor and others added 4 commits November 25, 2026 18:47
Select the output transfer from the opaque primary plane. A transparent UNORM overlay must preserve encoded scene colors. Cover RGBA and BGRA mixed formats and keep UNORM output when only an overlay is sRGB.
@CryingLaughing
CryingLaughing marked this pull request as ready for review November 26, 2026 14:17
@Anon64

Anon64 commented Nov 26, 2026

Copy link
Copy Markdown

Regression run of 96b0b18 on a newer retail title: no device removal, no crash, frames and commit within the limits.

Setup: RTX 3060 12 GB (NVIDIA 581.80), i9-14900KF, Windows 11 26200, release builds of main b49be18 (this PR's base) and of this PR's exact head, scripts/smoke.ps1 -Game <title> for 60 s with XCL_NETWORK=0 and A pressed every 4 s from 20 s. Main ran before and after a batch of 11 PRs and peaked at 23,855 and 23,844 MB, so the baseline held steady over the batch.

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1462)
presents per 2 s (last 3): 10 1 1
device removals: 0
crashes: 0
peak commit: 23855 MB

this PR:

xcl-smoke v1
commit: 96b0b189fd0a8991c8e7883823191cf54d896223
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1482 (PresentX 1482)
presents per 2 s (last 3): 23 4 5
device removals: 0
crashes: 0
peak commit: 23309 MB

101 % of main's frames, 97 % of its peak commit. One run each.

Not tested: the suite on this head; whether the title reaches the code this PR changes in its first 60 s; AMD.

AI use: Claude Code (Claude Opus 5.5) ran these runs on this machine and wrote this report.

@SzczepanGrela

SzczepanGrela commented Nov 26, 2026 •

Copy link
Copy Markdown

RX 9070 / Wine offscreen verification of the mixed sRGB/UNORM compositor change.

Tested

  • Head 96b0b189fd0a8991c8e7883823191cf54d896223 against its exact parent, D3D12.X: encode sRGB compositor output for presentation #2763 head 0d380f427797fb91a07512d074a5f6f4e1892674. This isolates the top commit of this stacked PR; main at the time of these runs was b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.
  • RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.
  • Native fixtures explicitly select RX 9070 instead of WARP and assert that the created D3D12 device LUID equals the selected adapter LUID. Logged PCI ID 1002:7550, LUID 00000000:000003ef. XCL_NETWORK=0, private caches.

Fixtures and controls

Both source copies receive the same current-head blend fixture and existing single-plane fixture with the hardware selector and sample logging. An identical local clone, compositor_mixed_formats_collects_all_native_pixels, collects every pixel of each 8x8 output over all five format cases before asserting. It retains the upstream exact transparent/opaque/alpha expectations and RGB tolerance of 2 for fractional blending.

All production bytes remain original to each revision. Removing the documented test replacements/addition reconstructs the exact original source files.

Results

Three fresh serial processes per fixture/revision:

  • Current-head blend fixture: head 1 passed / 0 failed, parent 0 passed / 1 failed at the first mixed-format transparent sample.
  • All-pixel clone: head 1/0 in all five cases; parent 0/1 after collecting all cases. Parent differs from the committed fixture's expected values at 32 pixels in each of the two sRGB-base/UNORM-overlay cases, RGBA and BGRA. Other cases pass on both.
  • Single-plane concrete sRGB preservation: 1/0 on both revisions.

For both affected format families, stored bytes are:

Sample Parent Head
Transparent overlay [128,55,0,255] [188,128,0,255]
Fractional overlay [64,91,0,255] [137,161,0,255]
Opaque overlay [255,0,0,255] [255,0,0,255]

The UNORM/UNORM, sRGB/sRGB and reverse UNORM-base/sRGB-overlay controls match on both. In the reverse case the fractional sample is [0,64,127,255].

The complete hle::d3d12x::present::frame_dump_tests:: module with four test threads gives head 5 passed / 0 failed versus parent 3 passed / 2 failed, with only the two mixed-format fixtures failing on the parent. Both frame-dump/report controls also pass separately on each revision; the mapped-buffer decoder control retains its original WARP device.

The final matrix contains 24 verified invocations. One earlier passing head module invocation was repeated with --show-output because concurrent stdout/stderr interleaved its diagnostics; both gave 5/0. One additional Wine launch failed with recvmsg: Connection reset by peer before libtest started; its exact retry passed. Raw logs for both observations are retained. No runtime skips or ignored tests in the completed selections. Independently checked all 2560 raw pixels from the final serial/concurrent clone runs, adapter/device identities, summaries, source reconstruction and executable hashes.

Build: cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run. GE-Proton Wine: <libtest.exe> hle::d3d12x::present::frame_dump_tests::<fixture> --exact --nocapture --test-threads=1; full module filter without --exact, with four threads. Final concurrent verification uses --show-output.

Not tested

Console presentation-plane transfer semantics as an independent oracle. The expected values above come from the committed test; these measurements establish the stored bytes produced by each implementation, not which interpretation of mixed UNORM/sRGB planes matches a console.

Physical display/swap-chain output, HDR, overlays beyond these five synthetic cases, native Windows, other GPUs, full workspace suite, retail workload, scripts/smoke.ps1, performance or FPS.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the stacked delta, adapted the native fixtures and all-pixel collection, ran and independently verified the paired evidence, and drafted this report. Publication authorized by the account owner.

Scope wording clarified after the discussion about the console transfer assumption; no additional hardware measurements were made.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Question on the mixed-format rule in present.rs:851-863 (96b0b18). With an sRGB base the RTV is sRGB, but a UNORM overlay keeps its UNORM SRV (plane_srv_format), so its bytes are sampled as linear and then sRGB-encoded on write: an opaque UNORM overlay texel of 64 is stored as ~137. Flip-model scanout treats UNORM bytes as already encoded (_SRGB only changes shader reads/writes), so I'd expect a UNORM UI plane holding 64 to stay 64. The new row (sRGB scene, UNORM UI, [0,64,0,128] -> green 161) asserts the linear reading; treating the overlay as encoded gives ~128. The opaque-overlay check uses only 255/0, which is the same in both transfers, so the tests can't see the shift. The reverse row (UNORM base, sRGB UI: 137 -> 64) darkens the overlay the same way. Before, the base was wrong in the mixed case; now the overlay is. Would sampling each plane through a view whose transfer matches the RTV (the typeless case already allows it), or blending in encoded space with UNORM views, keep both? Caveat: this assumes the console's planes scan out UNORM bytes as encoded, the way DXGI does.

AI-assisted (Claude Code, Claude Opus 5.5): read the diff and the tests; nothing was run for this.

@CryingLaughing

Copy link
Copy Markdown
Author

The opaque midtone does distinguish the two interpretations. I ran the same five-case offscreen fixture on exact parent 0d380f427797fb91a07512d074a5f6f4e1892674 and head 96b0b189fd0a8991c8e7883823191cf54d896223. The only source overlay adds the native readback test. Both passed 1/0/0 with no capability skips on the RTX 4080 / 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11, debug.

For an sRGB base and UNORM overlay, input [0,64,0,255] stored [0,64,0,255] on the parent and [0,137,0,255] on the head, for RGBA and BGRA. A transparent overlay over the same scene read back [128,55,0,255] on the parent and [188,128,0,255] on the head. In the reverse-format case, the same 64 input in an sRGB overlay stored 13 on both revisions.

The readback confirms the chosen SRV/RTV transfer on Windows. It leaves the Xbox overlay interpretation open. This GDK example sets ColorSpace independently for each submitted plane. XCL currently uses the resource format here and does not read that field. A verified per-plane color-space capture for the mixed-format case would help establish whether to use an encoded view or keep the linear overlay. D3D12 can support typed sibling views through relaxed casting; a valid cast alone does not establish which transfer the title intended.

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.

5 participants