d3d12: HDR10 output, off by default (D3D12-HDR10-OUTPUT) #3462

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "+refs/pull/3462/head:oreofr/hdr10-output"
git switch "oreofr/hdr10-output"
Open
leonida/mandy
OreoFR wants to merge 1 commit from oreofr/hdr10-output into main AGit

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3462/head:oreofr/hdr10-output'
git switch 'oreofr/hdr10-output'
Member

Item: D3D12-HDR10-OUTPUT (claimed in #3312, https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-24954)

What and why

HDR10 output for the DX12 runtime, off by default (LEONIDA_HDR=1 turns it on). XDisplayTryEnableHdrMode always answered "2: disabled", so the title rendered SDR even on an HDR screen. With the switch on:

  • The display is asked once (IDXGIOutput6::GetDesc1). Our card's display is taken first; a card with no display of its own (monitor on the iGPU, hybrid laptop) asks every card's displays and takes one in HDR. Only when Windows HDR is on for it (colour space 12, PQ/BT.2020) is the title told HDR is enabled, with min / peak / full-frame luminance (LEONIDA_HDR_MAX_NITS, 200-10000, overrides the peak). Otherwise there is one warning line (HDR (LEONIDA_HDR=1): Windows HDR is off for this display ...; SDR output) and SDR as before.
  • No host tone mapping: the title does it. It presents its SDR interface plane (colour space 0) and an HDR10 scene plane (12). The queue reads each plane's colour space from the retail PresentX and puts the HDR plane under the interface. Two planes are composed into R10G10B10A2 (scRGB scene: R16G16B16A16F), and the swap chain is tagged with SetColorSpace1 (G2084 P2020 / G10 P709).
  • The composer writes PQ: the SDR interface goes over the scene in linear light at paper white (LEONIDA_HDR_PAPER_WHITE, 80-500 nits, default 150). The F1 and F3 text and the trainer menu are also drawn in PQ at paper white, not at a full code (10000 nits).
  • F1: new row HDR10 (TURN ON WINDOWS HDR) (OFF/ON), which applies at the next start.
  • With the switch off nothing changes: no DXGI query, no plane colour space read, the composer and menu shaders are compiled from exactly the same source, XDisplayTryEnableHdrMode answers 2 and leaves info untouched. The SDR path is unchanged.

Frame generation: DLSS FG here is only given the HUD-less picture, never an interface plane, so Darner's "leave the SDR UI plane untagged" change has nothing to change. FSR 3 FG's fsr.rs has no SDR-only format check like Darner's FSR 4 one, so 838fb926f / d80420d43 have no counterpart. The F3 "HDR n NITS" output row and Darner's F1 display probe (DisplayConfigGetDeviceInfo) were left out to keep this PR small.

Credit

Ported from TrustNo1/Darner (https://git.gtahub.st/TrustNo1/Darner, GPL-3.0-or-later) and adapted to this tree, with credit in each file and in the commit:

  • 0256f5786: CodeFloe PR #174 "Add HDR10 output" by Robbie Groenewoudt (dutchmega), merged by trustno1-coder (host/hdr.rs, compose, queue, display.rs).
  • 45faf75ff (trustno1-coder): a card without a display of its own asks the displays of every card.

Files

leonida-gpu/src/host/hdr.rs (new), compose.rs, host.rs (presenter), host/font.rs, host/trainer.rs, host/menu.rs, queue.rs, lib.rs, leonida-hle/src/modules/display.rs, d3d12/docs/switches.md (regenerated), d3d12/docs/findings.md.

How to test (needs an HDR screen)

  1. Windows: Settings > Display > Use HDR on for the screen the game runs on.
  2. Start with LEONIDA_HDR=1 (or F1 > HDR10 > ON, save and restart). Optional: LEONIDA_HDR_PAPER_WHITE=200, LEONIDA_HDR_MAX_NITS=<peak>.
  3. The log should show, in order: Windows HDR is on for the display; the title renders HDR10, HDR mode: enabled, the colour spaces of the title's present planes (expected [Some(0), Some(12)]), swap chain colour space set with color_space=12, the composer writes PQ.
  4. Look at: highlights (sun, lamps at night), the interface brightness at 150 nits and with another paper white, the F1 menu and F3 panel, and the same with frame generation on.
  5. The same run with Windows HDR off must give one warning line and the usual SDR picture.

OreoFR will test this visually on a TCL 24G645 (Mini-LED, HDR10).

Tests

  • cargo test --locked -p leonida-gpu -p leonida-hle: all pass (leonida-gpu 771, leonida-hle 303). New tests: PQ against ST 2084's codes (80/100/203/400/1000/10000 nits), the BT.709 to BT.2020 matrix derived from the primaries, the HLSL carries the same constants, paper-white clamp (80-500, default 150) and peak override clamp, fallback for a display without Windows HDR (this PC's laptop panel: G22 P709, 270 nits), display pick (own card, then one in HDR, then the first), plane order, composed format, swap-chain colour space by format and plane, the HDR10 compose and menu shaders compile while the SDR sources stay unchanged, and HLE leaves info alone with the switch off.
  • Red/green: with plane_order always [0, 1], the paper-white clamp removed, or the Windows-HDR check inverted, 3 tests fail; they pass on the PR head.
  • cargo clippy --locked -p leonida-gpu --all-targets -- -D warnings: clean. leonida-hle: only the two collapsible_if errors already on main in modules/xmem.rs (not touched here); nothing in display.rs.
  • cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc: builds.
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: OK. check_no_game_data.py on every touched file: OK.

No in-game run yet; this PC's own panel has no HDR (Windows: HDR not supported), so only the SDR fallback could run here, and it wasn't run in game either. Tested on an RTX 4070 Laptop GPU (unit tests and builds only).

Follow-up (not in this PR): a launcher toggle for LEONIDA_HDR (launcher changes go through OreoFR).

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

**Item:** D3D12-HDR10-OUTPUT (claimed in #3312, https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-24954) ## What and why HDR10 output for the DX12 runtime, **off by default** (`LEONIDA_HDR=1` turns it on). `XDisplayTryEnableHdrMode` always answered "2: disabled", so the title rendered SDR even on an HDR screen. With the switch on: - The display is asked once (`IDXGIOutput6::GetDesc1`). Our card's display is taken first; a card with no display of its own (monitor on the iGPU, hybrid laptop) asks every card's displays and takes one in HDR. Only when **Windows HDR is on** for it (colour space 12, PQ/BT.2020) is the title told HDR is enabled, with min / peak / full-frame luminance (`LEONIDA_HDR_MAX_NITS`, 200-10000, overrides the peak). Otherwise there is **one warning line** (`HDR (LEONIDA_HDR=1): Windows HDR is off for this display ...; SDR output`) and SDR as before. - No host tone mapping: the title does it. It presents its SDR interface plane (colour space 0) and an HDR10 scene plane (12). The queue reads each plane's colour space from the retail PresentX and puts the HDR plane under the interface. Two planes are composed into R10G10B10A2 (scRGB scene: R16G16B16A16F), and the swap chain is tagged with `SetColorSpace1` (G2084 P2020 / G10 P709). - The composer writes PQ: the SDR interface goes over the scene in linear light at paper white (`LEONIDA_HDR_PAPER_WHITE`, 80-500 nits, default 150). The F1 and F3 text and the trainer menu are also drawn in PQ at paper white, not at a full code (10000 nits). - F1: new row `HDR10 (TURN ON WINDOWS HDR)` (OFF/ON), which applies at the next start. - **With the switch off nothing changes**: no DXGI query, no plane colour space read, the composer and menu shaders are compiled from exactly the same source, `XDisplayTryEnableHdrMode` answers 2 and leaves `info` untouched. The SDR path is unchanged. Frame generation: DLSS FG here is only given the HUD-less picture, never an interface plane, so Darner's "leave the SDR UI plane untagged" change has nothing to change. FSR 3 FG's `fsr.rs` has no SDR-only format check like Darner's FSR 4 one, so `838fb926f` / `d80420d43` have no counterpart. The F3 "HDR n NITS" output row and Darner's F1 display probe (`DisplayConfigGetDeviceInfo`) were left out to keep this PR small. ## Credit Ported from TrustNo1/Darner (https://git.gtahub.st/TrustNo1/Darner, GPL-3.0-or-later) and adapted to this tree, with credit in each file and in the commit: - `0256f5786`: CodeFloe PR #174 "Add HDR10 output" by **Robbie Groenewoudt (dutchmega)**, merged by trustno1-coder (`host/hdr.rs`, compose, queue, display.rs). - `45faf75ff` (trustno1-coder): a card without a display of its own asks the displays of every card. ## Files `leonida-gpu/src/host/hdr.rs` (new), `compose.rs`, `host.rs` (presenter), `host/font.rs`, `host/trainer.rs`, `host/menu.rs`, `queue.rs`, `lib.rs`, `leonida-hle/src/modules/display.rs`, `d3d12/docs/switches.md` (regenerated), `d3d12/docs/findings.md`. ## How to test (needs an HDR screen) 1. Windows: Settings > Display > Use HDR **on** for the screen the game runs on. 2. Start with `LEONIDA_HDR=1` (or F1 > HDR10 > ON, save and restart). Optional: `LEONIDA_HDR_PAPER_WHITE=200`, `LEONIDA_HDR_MAX_NITS=<peak>`. 3. The log should show, in order: `Windows HDR is on for the display; the title renders HDR10`, `HDR mode: enabled`, `the colour spaces of the title's present planes` (expected `[Some(0), Some(12)]`), `swap chain colour space set` with `color_space=12`, `the composer writes PQ`. 4. Look at: highlights (sun, lamps at night), the interface brightness at 150 nits and with another paper white, the F1 menu and F3 panel, and the same with frame generation on. 5. The same run with Windows HDR **off** must give one warning line and the usual SDR picture. OreoFR will test this visually on a TCL 24G645 (Mini-LED, HDR10). ## Tests - `cargo test --locked -p leonida-gpu -p leonida-hle`: all pass (leonida-gpu 771, leonida-hle 303). New tests: PQ against ST 2084's codes (80/100/203/400/1000/10000 nits), the BT.709 to BT.2020 matrix derived from the primaries, the HLSL carries the same constants, paper-white clamp (80-500, default 150) and peak override clamp, fallback for a display without Windows HDR (this PC's laptop panel: G22 P709, 270 nits), display pick (own card, then one in HDR, then the first), plane order, composed format, swap-chain colour space by format and plane, the HDR10 compose and menu shaders compile while the SDR sources stay unchanged, and HLE leaves `info` alone with the switch off. - Red/green: with `plane_order` always `[0, 1]`, the paper-white clamp removed, or the Windows-HDR check inverted, 3 tests fail; they pass on the PR head. - `cargo clippy --locked -p leonida-gpu --all-targets -- -D warnings`: clean. `leonida-hle`: only the two `collapsible_if` errors already on main in `modules/xmem.rs` (not touched here); nothing in `display.rs`. - `cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc`: builds. - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`: OK. `check_no_game_data.py` on every touched file: OK. **No in-game run yet; this PC's own panel has no HDR** (Windows: HDR not supported), so only the SDR fallback could run here, and it wasn't run in game either. Tested on an RTX 4070 Laptop GPU (unit tests and builds only). Follow-up (not in this PR): a launcher toggle for `LEONIDA_HDR` (launcher changes go through OreoFR). AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LEONIDA_HDR=1 (default off): when Windows shows the display in HDR (DXGI
colour space 12), XDisplayTryEnableHdrMode answers enabled with the
display's luminance (IDXGIOutput6::GetDesc1; LEONIDA_HDR_MAX_NITS sets
the peak). The title tone-maps itself and presents its SDR interface
plane over an HDR10 scene plane: the queue reads each plane's colour
space, puts the HDR plane under the interface, composes into
R10G10B10A2 (scRGB: half floats), tags the swap chain with
SetColorSpace1 and writes PQ, the SDR interface, F1/F3 text and trainer
menu at paper white (LEONIDA_HDR_PAPER_WHITE, 80 to 500, default 150).
A display without Windows HDR gets one warning line and SDR. With the
switch off nothing is queried or read and the shaders are compiled from
the same source as before. F1 row "HDR10 (TURN ON WINDOWS HDR)",
applied at restart.

Ported from TrustNo1/Darner (GPL-3.0-or-later), adapted to this tree:
0256f5786 (CodeFloe PR #174 "Add HDR10 output" by Robbie Groenewoudt,
merged by trustno1-coder) and 45faf75ff (trustno1-coder: a card without
a display of its own asks every card's displays). 838fb926f/d80420d43
(FSR 4 FG on HDR10) have no counterpart here: fsr.rs has no SDR-only
format check. Darner's untagged-UI change for DLSS FG is moot: only the
HUD-less picture is tagged here.

Tests: PQ against ST 2084 codes, BT.709->BT.2020 matrix from the
primaries, shader constants, paper-white and peak clamps, fallback for a
display without Windows HDR, display pick, plane order, composed format,
swap-chain colour space by format and plane, HDR shaders compile, HLE
leaves info alone with the switch off. Not run in game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OreoFR referenced this pull request from a commit 2026-12-04 14:36:14 +00:00
First-time contributor

RUN — In-game (Default SDR Path) & Test Gate (NVIDIA RTX 5070 12 GB, Windows 11)

Tested PR head 785efadf70 merged cleanly onto main (00e245be5), diagnostic release build (-SeriesS, no frame generation, default SDR path with LEONIDA_HDR unset, 315 s automated run from the same save), compared against our recent main (30c683055) baseline:

Metric main baseline (30c683055) PR #3462 (785efadf70, default SDR)
World samples (>=1000 draws) 36 (max_draws=5187) 40 (max_draws=5233)
Median FPS / frame time 23.0 fps (43.5 ms) 24.6 fps (40.7 ms)
Slowest 10% / fastest 10% 13.7 / 25.0 fps 18.0 / 25.4 fps
3000-4999 draws/frame median 23.2 fps (28 samples) 24.7 fps (31 samples)
Errors / warnings / device lost 0 / 0 / 0 0 / 0 / 0

Unit & Repo Checks

  • cargo test -p leonida-gpu --lib --locked hdr — 16/16 PASS (including the_hdr10_menu_shader_compiles and the_hdr10_composer_compiles_and_leaves_the_sdr_one_alone)
  • cargo test -p leonida-hle --lib --locked hdr — 1/1 PASS (hdr_off_by_default_leaves_the_info_alone)
  • cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings — 0 warnings
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md — PASS
  • python -I scripts/check_no_game_data.py — PASS

Verdict

PASS on default SDR regression gate and all HDR unit/shader-compile tests (note: live HDR10 display output with LEONIDA_HDR=1 on a Windows HDR display was not exercised here).

AI-assisted.

### RUN — In-game (Default SDR Path) & Test Gate (NVIDIA RTX 5070 12 GB, Windows 11) Tested PR head `785efadf70` merged cleanly onto `main` (`00e245be5`), diagnostic release build (`-SeriesS`, no frame generation, default SDR path with `LEONIDA_HDR` unset, 315 s automated run from the same save), compared against our recent `main` (`30c683055`) baseline: | Metric | `main` baseline (`30c683055`) | PR `#3462` (`785efadf70`, default SDR) | | --- | --- | --- | | World samples (`>=1000` draws) | `36` (`max_draws=5187`) | `40` (`max_draws=5233`) | | Median FPS / frame time | `23.0 fps` (`43.5 ms`) | `24.6 fps` (`40.7 ms`) | | Slowest 10% / fastest 10% | `13.7` / `25.0 fps` | `18.0` / `25.4 fps` | | `3000-4999` draws/frame median | `23.2 fps` (`28` samples) | `24.7 fps` (`31` samples) | | Errors / warnings / device lost | `0` / `0` / `0` | `0` / `0` / `0` | ### Unit & Repo Checks - `cargo test -p leonida-gpu --lib --locked hdr` — `16/16` PASS (including `the_hdr10_menu_shader_compiles` and `the_hdr10_composer_compiles_and_leaves_the_sdr_one_alone`) - `cargo test -p leonida-hle --lib --locked hdr` — `1/1` PASS (`hdr_off_by_default_leaves_the_info_alone`) - `cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings` — `0` warnings - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` — PASS - `python -I scripts/check_no_game_data.py` — PASS ### Verdict **PASS** on default SDR regression gate and all HDR unit/shader-compile tests (note: live HDR10 display output with `LEONIDA_HDR=1` on a Windows HDR display was not exercised here). AI-assisted.
Sign in to join this conversation.
No description provided.