fix(hdr): read the peak luminance by one rule in the title and the swap chain #427

Manually merged
github merged 1 commit from github-bot/gh-427 into main 2026-12-04 04:24:41 +00:00 AGit
Owner

@⁠Luxuride on GitHub · 2026-12-04 02:21 UTC · original
Luxuride:fix/hdr-nits-peak → main · +15 −5 · 2 files · 1 commits · merged 2026-12-04 04:23 UTC

What is wrong

VICTORY_HDR_NITS is parsed twice, by two different rules, and both results are used as if they were the same number.

Title side, crates/victory-hle/src/modules/display.rs:66-83:

.filter(|v| v.is_finite() && *v >= 0.0)   // accepts 0
let most = get("VICTORY_HDR_NITS", 1000.0);

Swap chain side, crates/victory-gpu/src/host.rs:7639-7646:

.filter(|v| *v > 0.0)                     // rejects 0, accepts inf

hle's own doc says the host presents HDR10 "the same variable". Two divergences:

  • VICTORY_HDR_NITS=0 (one character from the shipped default of 1000): the title is told a 0-nit peak and tone-maps to black, while the swap chain publishes MaxMasteringLuminance: 1000.
  • VICTORY_HDR_NITS=1e40 parses to f32::INFINITY: the title's is_finite rejects it and tells 1000, while the swap chain accepts it and the float→int casts saturate to 4294967295 / 65535 in DXGI_HDR_METADATA_HDR10.

Neither side says anything.

The change

One rule for a peak (finite, above 0 — a display has no 0-nit peak), keeping the minimum's own rule, since 0 is a real minimum:

let peak = |name: &str, or: f32| {
    std::env::var(name)
        .ok()
        .and_then(|v| v.trim().parse::<f32>().ok())
        .filter(|v| v.is_finite() && *v > 0.0)
        .unwrap_or(or)
};
let most = peak("VICTORY_HDR_NITS", 1000.0);
[get("VICTORY_HDR_MIN_NITS", 0.0), most, peak("VICTORY_HDR_FULL_NITS", most)]

and the swap chain side adds is_finite to its filter, so the metadata conversion can never saturate.

Validation

Both files are Windows-only against a real HDR device, which this host does not have. The three closures were compiled verbatim and run side by side (rustc -O):

input    title most/full    host
unset    (1000, 1000)       1000     agree
1000     (1000, 1000)       1000     agree
0        (1000, 1000)       1000     agree   [before: title 0, host 1000]
1e40     (1000, 1000)       1000     agree   [before: title 1000, host 4294967295]
-5       (1000, 1000)       1000     agree
nan      (1000, 1000)       1000     agree
4000     (4000, 4000)       4000     agree

Before the change the 0 and 1e40 rows disagreed. cargo check -p victory-hle --target x86_64-pc-windows-msvc --lib and cargo check -p victory-gpu --target x86_64-pc-windows-msvc --lib: no errors, no new warnings.

Overlap

An open PR owns both files for its HDR10 swap-chain work, but its diff contains no VICTORY_HDR_NITS/hdr_nits change — it is a conflict risk in the same function, not a fix for this. No issue mentions the variable.

**@⁠Luxuride** on GitHub · 2026-12-04 02:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/427) `Luxuride:fix/hdr-nits-peak` → `main` · +15 −5 · 2 files · 1 commits · merged 2026-12-04 04:23 UTC ### What is wrong `VICTORY_HDR_NITS` is parsed twice, by two different rules, and both results are used as if they were the same number. Title side, `crates/victory-hle/src/modules/display.rs:66-83`: ```rust .filter(|v| v.is_finite() && *v >= 0.0) // accepts 0 let most = get("VICTORY_HDR_NITS", 1000.0); ``` Swap chain side, `crates/victory-gpu/src/host.rs:7639-7646`: ```rust .filter(|v| *v > 0.0) // rejects 0, accepts inf ``` `hle`'s own doc says the host presents HDR10 "the same variable". Two divergences: - `VICTORY_HDR_NITS=0` (one character from the shipped default of 1000): the title is told a 0-nit peak and tone-maps to black, while the swap chain publishes `MaxMasteringLuminance: 1000`. - `VICTORY_HDR_NITS=1e40` parses to `f32::INFINITY`: the title's `is_finite` rejects it and tells 1000, while the swap chain accepts it and the float→int casts saturate to `4294967295` / `65535` in `DXGI_HDR_METADATA_HDR10`. Neither side says anything. ### The change One rule for a peak (finite, above 0 — a display has no 0-nit peak), keeping the minimum's own rule, since 0 is a real minimum: ```rust let peak = |name: &str, or: f32| { std::env::var(name) .ok() .and_then(|v| v.trim().parse::<f32>().ok()) .filter(|v| v.is_finite() && *v > 0.0) .unwrap_or(or) }; let most = peak("VICTORY_HDR_NITS", 1000.0); [get("VICTORY_HDR_MIN_NITS", 0.0), most, peak("VICTORY_HDR_FULL_NITS", most)] ``` and the swap chain side adds `is_finite` to its filter, so the metadata conversion can never saturate. ### Validation Both files are Windows-only against a real HDR device, which this host does not have. The three closures were compiled verbatim and run side by side (`rustc -O`): ``` input title most/full host unset (1000, 1000) 1000 agree 1000 (1000, 1000) 1000 agree 0 (1000, 1000) 1000 agree [before: title 0, host 1000] 1e40 (1000, 1000) 1000 agree [before: title 1000, host 4294967295] -5 (1000, 1000) 1000 agree nan (1000, 1000) 1000 agree 4000 (4000, 4000) 4000 agree ``` Before the change the `0` and `1e40` rows disagreed. `cargo check -p victory-hle --target x86_64-pc-windows-msvc --lib` and `cargo check -p victory-gpu --target x86_64-pc-windows-msvc --lib`: no errors, no new warnings. ### Overlap An open PR owns both files for its HDR10 swap-chain work, but its diff contains no `VICTORY_HDR_NITS`/`hdr_nits` change — it is a conflict risk in the same function, not a fix for this. No issue mentions the variable.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 02:27:46 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 03:14 UTC · original

Checked on Windows 11 (MSVC). victory-hle tests pass (display ones included), the victory-gpu lib suite fails the same tests as main on one NVIDIA desktop card, and clippy has nothing new in either crate.

The 0 and inf cases are fixed as described. Two small things though.

The description says the metadata conversion can never saturate, but the u16 fields still can. Any finite value above 65535, say VICTORY_HDR_NITS=70000, passes both filters, the title is told 70000, and MaxContentLightLevel and MaxFrameAverageLightLevel end up at 65535 while MaxMasteringLuminance gets 70000. Clamping the peak to 10000 (the PQ ceiling) on both sides would close that. Values under 1 also truncate to 0 in the metadata, if you want a lower bound too.

The new doc comment in display.rs says victory_gpu reads the same two variables, but the host only reads VICTORY_HDR_NITS, not VICTORY_HDR_FULL_NITS.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 03:14 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/427#issuecomment-7399845821) Checked on Windows 11 (MSVC). victory-hle tests pass (display ones included), the victory-gpu lib suite fails the same tests as main on one NVIDIA desktop card, and clippy has nothing new in either crate. The 0 and inf cases are fixed as described. Two small things though. The description says the metadata conversion can never saturate, but the u16 fields still can. Any finite value above 65535, say `VICTORY_HDR_NITS=70000`, passes both filters, the title is told 70000, and `MaxContentLightLevel` and `MaxFrameAverageLightLevel` end up at 65535 while `MaxMasteringLuminance` gets 70000. Clamping the peak to 10000 (the PQ ceiling) on both sides would close that. Values under 1 also truncate to 0 in the metadata, if you want a lower bound too. The new doc comment in display.rs says victory_gpu reads the same two variables, but the host only reads `VICTORY_HDR_NITS`, not `VICTORY_HDR_FULL_NITS`. AI-assisted: yes
github manually merged commit fdb03f9b92 into main 2026-12-04 04:24:41 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.