Skip to content

Present: configure HDR swapchain color space via SetColorSpace1 (#103) - #238

Closed
slopgobblercobbler wants to merge 1 commit into
xcl-dev:mainfrom
slopgobblercobbler:feat/present-hdr-colorspace
Closed

slopgobblercobbler wants to merge 1 commit into
xcl-dev:mainfrom
slopgobblercobbler:feat/present-hdr-colorspace

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

Addresses #103 Item 3 (HDR color space configuration):
Configures appropriate DXGI color spaces on HDR swapchains instead of leaving them in default SDR G22/P709:

  • DXGI_FORMAT_R10G10B10A2_UNORM -> DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 (HDR10)
  • DXGI_FORMAT_R16G16B16A16_FLOAT -> DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 (Linear FP16 scRGB)

What is in it

  • crates/xcl/src/hle/d3d12x/present.rs:
    • hdr_color_space(format) mapping.
    • Calls IDXGISwapChain3::SetColorSpace1 in ensure_swapchain on creation and resize.
    • Graceful fallback: logs a warning if the host display/driver returns DXGI_ERROR_UNSUPPORTED or query failure, without interrupting presentation.
    • Unit tests: hdr_color_space_format_matching and hdr_color_space_configuration.

Tested

  • cargo test -p xcl -- present (5 passed, 0 failed).
  • Full workspace test suite: cargo test --workspace (604 passed, 0 failed).
  • Windows 11 x64, MSVC toolchain.

Not tested

  • Physical HDR10 display monitor metadata negotiation.

AI use

  • Developed with Antigravity swarm coordinator & dedicated author/verifier agents (author-hdr, verify-hdr). Verified and reviewed independently.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run and review of bc727533d8c240fa30a53bb7749881fdb47ca063 on AMD (RDNA4). The branch is based on 6da33fa, so I merged it onto current main a6f5f7a locally (clean merge, only present.rs) 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
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) on the merge: 678 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 638 passed, 0 failed, 21 ignored (main on this machine: 636 / 676, the difference is the 2 new tests)
  • 0 SKIPPED; hdr_color_space_format_matching and hdr_color_space_configuration pass
  • the description's 604-test count predates current main; it does not name a GPU, which CONTRIBUTING asks for

Review: two points I would want addressed before merging, both from reading the code

  1. An HDR color space stays set after a switch to SDR. In ensure_swapchain, the resize path calls ResizeBuffers(…, fmt) and then configure_color_space(sc, fmt). For an SDR format hdr_color_space returns None, so nothing is called and the swap chain keeps the color space set for the previous R10G10B10A2 / R16G16B16A16 format. Calling SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) for the SDR formats (and checking CheckColorSpaceSupport first) would cover it.
  2. R10G10B10A2 is taken to mean HDR10 (PQ / BT.2020). A 10:10:10:2 back buffer is also used for 10-bit SDR. Nothing in present.rs gets from the title whether its output is PQ-encoded, and XCL's own frame dump (rgb() in the same file) reads R10G10B10A2 as display-ready SDR values. If a title presents SDR in that format, the display would decode it as PQ and the picture would be wrong. Unless the title's color space can be taken from PresentX or its configuration, leaving 10:10:10:2 at the default and setting HDR only when the title asks for it seems safer.

Smaller points:

  • hdr_color_space_configuration asserts nothing on the HDR path (its two calls are let _ =), so it passes whatever SetColorSpace1 does. When the WARP device or swap chain cannot be made it returns without gpu::recomp::runner::skip_test(…), which CONTRIBUTING asks GPU tests to call.
    Not tested: no HDR display and no retail title (I have no unpacked game), so neither point was observed on screen; they come from the code paths above. No regression run, no XCL_SAMPLE_* tests, release build.

Run and review by Claude Code (Claude Opus 5.5) on this machine; each point was checked against the code.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of #786 for the same HDR color-space work; it also handles restoring SDR color space after a format change. This work remains unmerged. Thank you for the contribution.

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.

3 participants