Skip to content

D3D12.X: set the HDR colour space on an HDR swap chain (#103) - #786

Open
Luxuryig wants to merge 1 commit into
xcl-dev:mainfrom
Luxuryig:d3d12x-hdr-color-space
Open

Luxuryig wants to merge 1 commit into
xcl-dev:mainfrom
Luxuryig:d3d12x-hdr-color-space

Conversation

@Luxuryig

Copy link
Copy Markdown

Part of #103. An HDR swap chain was created as R10G10B10A2_UNORM or R16G16B16A16_FLOAT and left on DXGI's default colour space, so HDR10 is shown as gamma 2.2 / BT.709. The chain now calls SetColorSpace1: PQ / BT.2020 for R10G10B10A2, scRGB for RGBA16F. An output that cannot present that space keeps the default, and a resize back to an SDR format restores gamma 2.2 / BT.709.

This is item 3 of #103 only. The multi-plane, frame-clock, and QPC-flag items are unchanged. ivall already fixed the presenter queue pin and the interval tolerance on main.

What is in it

  • crates/xcl/src/hle/d3d12x/present.rs: apply_hdr_color_space runs when the swap chain is created in an HDR format, and again after ResizeBuffers when the format was or becomes HDR. Two tests cover the format map and a real swap chain on this output.

Tested

  • NVIDIA GeForce RTX 4060 Ti, driver 616.64, 8188 MiB (XCL logs 7949 MiB). AMD Ryzen 5 5500. Windows NT 10.0.26200.0. rustc 1.99.1 (58cf8f9c3 2026-10-13), cargo 1.99.1. DXC dxcompiler/dxil 1.8.2502.11. Debug tests, then release binaries for the smoke runs.
  • The two new tests alone: 2 passed, 0 failed, finished in 0.42s. The swap-chain test printed hdr colour space support: HDR10 0x1 (set true), scRGB 0x1 (set true). That run was one log-line dash short of the committed text. The call and the asserts are the same.
  • cargo test --workspace --offline -- --test-threads=1 on the committed tree (parent 6025201, then rebased onto d208e14, which only updates README.md and does not touch this code): 706 passed, 0 failed, 41 ignored, exit 0, 108.56s. Lib: 665 passed, 21 ignored, 61.49s. Package lines: 665/21, 0, 13, 3/4, 1, 3, 2, 7, 0/4, 1, 1, 2, 1, 1, 6/12, 0, 0.
  • Two GPU tests skipped on this adapter (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware. XCL_SAMPLE_* were unset; those tests are part of the 41 ignored.
  • cargo build --release -p xcl --offline succeeded for main d208e14 and for this head 1430c16. The only warning is the pre-existing fetch_update deprecation in xgameruntime.

Regression run
No retail title on this machine, and no HDR display check. Both runs are the in-tree test title with --hello, for 20 seconds, each with its own XCL_DATA_ROOT. scripts/smoke.ps1 on main cannot pass title arguments, so these runs used a local -TitleArgs that is not in this commit. A stock smoke.ps1 without --hello makes the title exit 0x1, and that counts as crashes: 1. Both logs say process ends ( (exit 0), at 1.953s on main and 1.927s on this head, which is before the 2s activity line, so presents and peak commit are empty. The early rust_panic is the title's expected caught C++ exception. The test title's swap chain is SDR, so this run does not exercise SetColorSpace1.

xcl-smoke v1
commit: d208e14b765f469f4b56301b78afa8dac5378339
gpu: NVIDIA GeForce RTX 4060 Ti
title: xcl-smoke-game
seconds: 20
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 
device removals: 0
crashes: 0
peak commit: n/a MB
xcl-smoke v1
commit: 1430c1633f309f044a12a3ff1e24898c070e60cd
gpu: NVIDIA GeForce RTX 4060 Ti
title: xcl-smoke-game
seconds: 20
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 
device removals: 0
crashes: 0
peak commit: n/a MB

Not tested

AI use
Grok Build (Grok 4.7) wrote the colour-space call and its tests, ran the suite and both smoke runs, and opened this pull request.

An R10G10B10A2 chain is HDR10 (PQ, BT.2020) and an RGBA16F chain is scRGB. An output that cannot present that space keeps the default. Resizing back to an SDR format restores gamma 2.2 / BT.709.

Assisted-by: Grok Build (Grok 4.7)
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 1430c1633f309f044a12a3ff1e24898c070e60cd on AMD RDNA4. I merged it onto current main e50836b locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 706 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 665 passed, 0 failed, 21 ignored
  • 0 SKIPPED; hdr_formats_map_to_pq_and_scrgb_sdr_does_not and swap_chain_takes_the_hdr_colour_space_this_output_can_present pass (this output is SDR; the swap-chain test took the path it can present).

Review: This addresses the two things I raised on #238 (open, same item of #103): a resize back to an SDR format now restores G22 / P709, and CheckColorSpaceSupport is asked before SetColorSpace1. The other point still applies here: every R10G10B10A2_UNORM swap chain is taken as HDR10 (PQ / BT.2020), but 10:10:10:2 is also used for 10-bit SDR, and nothing in present.rs learns from the title whether its output is PQ-encoded (XCL's own frame dump reads R10G10B10A2 as display-ready SDR). Unless the title's colour space can be read from PresentX or its configuration, setting PQ only when the title asks for it would be safer. Overlap with #238: only one of the two should land.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A question about 1430c16, from reading the code (not run): hdr_color_space decides from the swap-chain format alone, so every R10G10B10A2_UNORM chain becomes PQ / BT.2020. That format is also a common 10-bit SDR output. A title that presents gamma-2.2 content in it (or one with HDR turned off in its own settings) would be shown as PQ on an HDR display, which is dim and badly wrong, where main shows it correctly. On an SDR display CheckColorSpaceSupport refuses PQ, so only HDR displays see the difference.

Does the retail title switch its PresentX format between SDR and HDR modes? If it can present 10-bit SDR, the colour space needs to come from what the title asks for, not from the format. The PresentX plane records are 0x48 bytes and #615 reads only up to 0x20, so the title's colour space may be in the rest. Failing that, an XCL_HDR opt-in would keep the default safe. The RGBA16F → scRGB mapping is fine either way, since an fp16 chain is almost always linear.

AI-assisted (Claude Code), read-only review.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression runs for this PR's head 1430c16 and for its base main d208e14, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 (release, clean tree at each commit) and pasted unedited, for Regression run.

main:

xcl-smoke v1
commit: d208e14b765f469f4b56301b78afa8dac5378339
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1647 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16733 MB

this PR:

xcl-smoke v1
commit: 1430c1633f309f044a12a3ff1e24898c070e60cd
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1649 (PresentX 1649)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16732 MB

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974 (native Windows), Rust 1.90.0

Not tested

  • the unit tests on this machine
  • an HDR display: this machine ran with an SDR swap chain, so this is a regression check only

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

@iggyvilla

Copy link
Copy Markdown
Contributor

Code read of 1430c16; nothing built or run. The format question (R10G10B10A2 is also 10-bit SDR) is already raised by @upipibi and still needs an answer; I have nothing to add to it. Two code points:

  1. The new test swap_chain_takes_the_hdr_colour_space_this_output_can_present uses expect for the factory, WARP adapter, device, queue, window and swap chain (present.rs:1252-1301). AGENTS.md asks GPU tests to call gpu::recomp::runner::skip_test(reason) and return when the hardware is missing; D3D12.X: triple-buffer Presenter to avoid per-frame fence stalls #674's test does that.
  2. It conflicts with D3D12.X: triple-buffer Presenter to avoid per-frame fence stalls #674 (both rewrite ensure_swapchain): ResizeBuffers(2, …) (:643) and BufferCount: 2 (:666) would have to follow PRESENT_SLOTS, and the test's Presenter { alloc, list, copy_source, dumps, … } literal will not compile after D3D12.X: triple-buffer Presenter to avoid per-frame fence stalls #674's slots. Whichever lands second needs the rebase. It also overlaps open Present: configure HDR swapchain color space via SetColorSpace1 (#103) #238 (same item of D3D12.X Presentation & Frame Pacing: multi-plane PresentX, HDR color space, multi-queue fallback lockout, and frame clock handle race #103).

AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above and drafted this; a person checked it before posting.

@LANgmas

LANgmas commented Nov 24, 2026

Copy link
Copy Markdown

Additional DXGI output-path validation on a hybrid NVIDIA/Intel laptop:

Hardware:

  • NVIDIA GeForce RTX 3050 Laptop GPU (4 GB)
  • Intel Iris Xe
  • ASUS Vivobook Pro OLED K3500PC, internal HDR display
  • Windows build 26300, Windows HDR enabled

A temporary DXGI diagnostic found:

  • The internal OLED output is enumerated under the Intel Iris Xe adapter.
  • The NVIDIA RTX 3050 adapter enumerates zero outputs.
  • On a swap chain associated with a window positioned on the internal OLED, CheckColorSpaceSupport reported:
    • HDR10 PQ / BT.2020: 0x0
    • scRGB / G10 P709: 0x1 (PRESENT)

No SetColorSpace1 call was made by this probe, so this is not evidence of successful HDR10 or scRGB presentation, nor proof that SetColorSpace1 would fail for PQ.

This provides an additional hybrid-rendering/output-path datapoint for evaluating the output-specific color-space handling in this PR. It does not resolve the separate question of whether R10G10B10A2 content is actually HDR10 or 10-bit SDR; that distinction still needs to come from title intent or another reliable signal.

The temporary diagnostic was removed after the run. No XCL source files were modified.

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.

6 participants