Skip to content

fix(hdr): re-anchor SDR white before HDR encoding - #1008

Merged
qiin2333 merged 1 commit into
masterfrom
codex/fix-hdr-sdr-white
Aug 29, 2026
Merged

fix(hdr): re-anchor SDR white before HDR encoding#1008
qiin2333 merged 1 commit into
masterfrom
codex/fix-hdr-sdr-white

Conversation

@qiin2333

@qiin2333 qiin2333 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

改了啥呀

  • 把客户端/主机 SDR 白点比值抽成统一的线性 scRGB 预编码变换,PQ 与 HLG 共用同一条路径
  • 从当前物理输出读取 Windows SDR reference white;VDD 有 producer metadata 时优先使用,并与光标常量缓冲状态解耦
  • 用对数亮度区间平滑回落增益,保证 0.5–2.5 倍范围内映射严格单调,不再出现亮度反转
  • 让全帧、未缩放和缩放分析都复用编码前变换,使 HDR10+、HDR Vivid 与 Dolby Vision 元数据描述实际编码像素
  • 允许加密 PQ/HLG 会话在运行中更新客户端白点,不重建显示器或编码器

为啥要改

PQ 是绝对亮度编码,主机 scRGB 桌面的 SDR band 却锚定在主机自己的 Windows SDR 白点。客户端白点没参与换算时,普通桌面内容会被送进错误的绝对亮度,怎么调 PQ 参数都只是在错误基准上继续调,结果就是那种白茫茫的杂鱼画面啦。

这次在进入 PQ/HLG OETF 前完成重锚,同时让动态元数据分析看到同一份变换后的像素。旧客户端没有上报白点时保持原行为;SDR 会话和其他客户端路径不受影响。

配套 Moonlight 客户端修复:qiin2333/moonlight-qt#203

验证

  • cmake --preset dev-win -DBUILD_TESTS=ON -DBUILD_WEB_UI=OFF -DFETCH_GUI=OFF -DSUNSHINE_ENABLE_TRAY=OFF -DCMAKE_BUILD_TYPE=Release
  • ninja -C build -j 6 sunshine tests/test_sunshine.exe
  • 93 个 HDR10+/HDR Vivid/Dolby Vision/动态白点相关测试通过
  • 24 个 PQ、HLG 与 HDR analysis shader 变体通过 FXC 编译
  • 白点增益 0.5–2.5 数值扫描无亮度反转
  • git diff --check origin/master...HEAD

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4bb5e683-c5c7-4628-99ca-ae221c334a53

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb2095 and f00653c.

⛔ Files ignored due to path filters (6)
  • src_assets/windows/assets/shaders/directx/hdr_luminance_analysis_cs.hlsl is excluded by !**/*.hlsl
  • src_assets/windows/assets/shaders/directx/include/convert_hybrid_log_gamma_base.hlsl is excluded by !**/*.hlsl
  • src_assets/windows/assets/shaders/directx/include/convert_perceptual_quantizer_base.hlsl is excluded by !**/*.hlsl
  • src_assets/windows/assets/shaders/directx/include/convert_yuv420_nv12p010_cs_base.hlsl is excluded by !**/*.hlsl
  • src_assets/windows/assets/shaders/directx/include/convert_yuv420_nv12p010_cs_scaled_base.hlsl is excluded by !**/*.hlsl
  • src_assets/windows/assets/shaders/directx/include/hdr_pre_encode_transform.hlsl is excluded by !**/*.hlsl
📒 Files selected for processing (5)
  • src/platform/common.h
  • src/platform/windows/display.h
  • src/platform/windows/display_base.cpp
  • src/platform/windows/display_vram.cpp
  • src/stream.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (2)
平台抽象层代码(Windows/Linux/macOS)。确保各平台实现一致, 注意 Windows API 调用的错误处理和资源释放。

⚙️ CodeRabbit configuration file

Files:

  • src/platform/common.h
  • src/platform/windows/display_base.cpp
  • src/platform/windows/display.h
  • src/platform/windows/display_vram.cpp
Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

⚙️ CodeRabbit configuration file

Files:

  • src/platform/common.h
  • src/platform/windows/display_base.cpp
  • src/stream.cpp
  • src/platform/windows/display.h
  • src/platform/windows/display_vram.cpp
🔇 Additional comments (2)
src/stream.cpp (1)

2079-2079: LGTM!

Also applies to: 2089-2090

src/platform/windows/display_vram.cpp (1)

738-738: 🩺 Stability & Availability

无需为 clientSdrWhiteNits 增加并发同步。

动态参数处理和 session->convert(*img) 都在同一视频线程中顺序执行。当前调用路径不会并发读写 hdr_pre_encode.clientSdrWhiteNits


Summary by CodeRabbit

  • 新功能

    • 改进 Windows HDR 显示处理,支持更准确地识别和应用显示器 SDR 白电平。
    • HDR 预处理现统一支持 HDR10(PQ)与 HLG,提升不同 HDR 内容的显示一致性。
    • 捕获链路可优先使用来源设备提供的 SDR 白电平信息。
  • 问题修复

    • 加密 HDR 会话现可正确应用 HDR 转换参数,不再局限于 HLG 模式。
    • 更新相关说明,使 HDR 转换与显示行为描述更加准确。

Walkthrough

本次变更新增 Windows SDR 白电平查询和缓存。捕获白点优先使用生产者元数据。HDR 预编码流程现在同时支持 PQ 和 HLG。客户端 SDR 白点更新适用于所有加密 HDR 动态范围。

Changes

HDR 白电平处理

Layer / File(s) Summary
显示器 SDR 白电平查询与捕获白点
src/platform/windows/display.h, src/platform/windows/display_base.cpp, src/platform/windows/display_vram.cpp
display_base_t 记录选定输出并查询缓存的 DisplayConfig SDR 白电平。display_vram_t 优先使用生产者白电平,其次使用显示器查询值,最后回退到 300 尼特。光标生产者白电平会单独保存。
PQ/HLG 预编码与分析派发
src/platform/windows/display_vram.cpp, src/platform/common.h
HlgDisplayParams 和相关函数统一为 HDR 预编码结构与流程。预编码现在支持 PQ 和 HLG。HDR 分析使用统一输入源,并绑定预编码常量缓冲。相关注释改为 HDR 术语。
HDR 会话白点更新
src/stream.cpp
CLIENT_SDR_WHITE_NITS 更新仅在 SDR 动态范围时拒绝。所有加密 HDR 动态范围均可更新该参数。

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to f0065

The PR re-anchors HDR encoding to the client SDR white point while keeping updates authenticated and isolated to the active session. No actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant 加密HDR会话
  participant stream.cpp
  participant display_vram_t
  participant display_base_t
  participant QueryDisplayConfig
  加密HDR会话->>stream.cpp: 更新 CLIENT_SDR_WHITE_NITS
  stream.cpp->>display_vram_t: 设置客户端 SDR 白点
  display_vram_t->>display_vram_t: 读取生产者 SDR 白点
  display_vram_t->>display_base_t: 查询显示器 SDR 白点
  display_base_t->>QueryDisplayConfig: 查询活动显示路径
  QueryDisplayConfig-->>display_base_t: 返回 SDR 白电平
  display_base_t-->>display_vram_t: 返回缓存值
  display_vram_t->>display_vram_t: 更新 HDR 预编码参数
Loading

Suggested reviewers: yundi339

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.83% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 标题准确概括了主要变更:在 HDR 编码前重新锚定 SDR 白点。标题简洁、明确,并与 PQ、HLG 共用的预编码变换及 Windows SDR 白点查询逻辑相关。
Description check ✅ Passed 描述与变更内容直接相关。它说明了 SDR 白点重锚定、PQ 与 HLG 共享变换、Windows 输出查询、VDD 元数据优先级、动态更新范围及验证结果。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-hdr-sdr-white

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qiin2333
qiin2333 merged commit ce6b69a into master Aug 29, 2026
4 checks passed
@qiin2333
qiin2333 deleted the codex/fix-hdr-sdr-white branch August 29, 2026 09:37
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.

1 participant