Skip to content

hdr工作面适配 - #24

Open
konodiodaaaaa1 wants to merge 12 commits into
SAOG0721:experimentalfrom
konodiodaaaaa1:local-0.6.5-hdr
Open

hdr工作面适配#24
konodiodaaaaa1 wants to merge 12 commits into
SAOG0721:experimentalfrom
konodiodaaaaa1:local-0.6.5-hdr

Conversation

@konodiodaaaaa1

@konodiodaaaaa1 konodiodaaaaa1 commented Sep 7, 2026

Copy link
Copy Markdown

关联关系

  • 取代并关闭:feat(hdr): HDR 初步适配 DLSS5 #13(feat(hdr): HDR 初步适配 DLSS5)
  • 来源分支:konodiodaaaaa1:local-0.6.5-hdr
  • 目标分支:experimental
  • 当前合入提交:9c2309a283b3bfef59a5197b38a8354b135363f3
  • HDR 管道主提交:06435e47fb878780f4b5b1a2d18cd4937c5f01bf
  • 官方参考:v0.6.5-experimental 2d37f8c
  • 官方 0.6.6:v0.6.6-experimental 9824d75

这次 PR 的定位

这是一条完整的 HDR 工作面适配分支。实现以本地 0.6.5 已经完成的效果、native backend、DLSSNR 残差、Frame Guidance、FG 发布和参数会话为基础,加入官方 0.6.6 的会话生命周期、NGX 异常保护、捕获关闭保护、实时参数队列、inputRevision history 管理、窗口 owner 和 overlay 状态恢复。

HDR 适配采用显式全局开关:

HDR off:
  online 0.6.5 U8/LDR capture -> effect/native baseline -> online presenter

HDR on:
  capture -> HDR decode/exposure normalization
  -> canonical R16G16B16A16_FLOAT
  -> per-effect route adapter
  -> existing backend
  -> inverse adapter
  -> canonical FP16 or presentation terminal

关闭 HDR compatibility 时,HDR boundary 清空,HDR-only 参数进入 inactive/default,HDR capture pool、normalization、HDR compiler variant、HDR presenter 和 HDR terminal 均退出处理链。外部显示器或系统处于 HDR 状态时,关闭这个选项仍然选择线上 U8/LDR 路由;本地 0.6.5 的 DLSSNR residual、Frame Guidance、ZeroMV、FG failure recovery 和原有参数行为保持原逻辑。

Canonical FP16 与 route boundary

inter-effect canonical storage 为 DXGI_FORMAT_R16G16B16A16_FLOAT,并由 HdrFrameMetadata 与 ColorDescription 携带 transfer、primaries、range、reference white、SDR white、display peak、scene/display referred、pre-exposure 和 HDR metadata。

每个效果通过结构化 HdrFormatRoute 描述 input/output format、transfer、range、alpha mode、evidence level、HDR-native、adapter profile、HDR/SDR 默认值和 normalization scale。route 选择使用结构化字段,effect 名称只用于 catalog 分组和诊断。

已落地的 adapter profile:

  • DirectFP16:验证过的浮点 HDR backend,canonical FP16 只做必要的色彩变换。
  • BoundedHDR:backend 需要有界数值范围,使用成对的 normalization/inverse normalization。
  • SDRCompatible:backend 合同为 U8/UNORM/SDR,使用显式 HDR-to-SDR proxy 和 paired reconstruction。
  • ConditionalFP16:保留参考实现或实验支持的 FP16 路径,等待更完整的色彩合同验证。
  • PresentationTerminal:backend 拥有交换链或最终发布面,普通 post-effect 在此结束。

Native backend 适配

DLSSNR

保留本地 DLSSNR 的颜色、depth、motion、exposure、残差、输入分辨率和 history 逻辑。HDR 状态使用 canonical FP16 -> bounded HDR normalization -> DLSSNR color/depth/motion/exposure -> inverse normalization -> canonical FP16。

inputRevision 由 Renderer 传入;上游实时参数或输入 route 变化时刷新 history,避免旧静帧缓存与新输入混合。所有 NGX create/evaluate/release/shutdown、参数访问和 signed snippet 调用统一进入 NgxRuntimeGuard。

DLSS SR / DLSS FG

DLSS SR 使用 route-compatible float 输入和既有 guidance contract。DLSSFG 增加 _dlssFgNormalizedInput、_dlssFgCanonicalGenerated 和 _dlssFgHdrNormalizationScale,在 evaluate 前后完成 bounded/canonical 转换,并在 publication 前检查 canonical FP16 descriptor。原有 CPU Fence、D3D11/D3D12 共享资源、history reset、一次重建和当前会话禁用策略继续保留。

XeSS SR / XeSSFG

XeSS SR 的 HDR FP16 初始化和 SDR U8 初始化分开;XESS_INIT_FLAG_LDR_INPUT_COLOR 只用于 SDR 路由,HDR 浮点输入保留自己的 contract。XeSSZeroMVUpscaler 继续作为独立的线上 ZeroMV backend。

XeSSFG 作为 presentation terminal 使用 canonical FP16 -> Rec.709 to Rec.2020 -> PQ/BT.2100 -> R10G10B10A2_UNORM -> DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 -> XeSSFG proxy swap chain。backbuffer、HUD-less、UI surface 和 proxy swap chain 使用同一 HDR10 contract;HDR off 恢复线上 LDR terminal。

FSR2/FSR3/FSR4、RTX Video、光流

FSR2/3/4 保留本地 ZeroMV、motion、depth、exposure、reactive/transparency mask 和 FG/optical-flow 辅助资源,HDR 只在 boundary 增加 canonical/route conversion。RTX Video 使用显式 normalized-D3D/U8 bridge,inputScale 按实际 float/U8 输入选择。AMD OF 与 NVOF 在 HDR 状态从 canonical frame 做 provider-local conversion,SDR 状态优先线上 B8G8R8A8/U8 contract。

PassThrough 和普通 shader

PassThrough 分为 REFERENCE_HDR_HLSL 与 REFERENCE_LDR_HLSL。Effect compiler 的 MP_HDR_SATURATE、MP_HDR_ALPHA、MP_HDR_COMPATIBILITY 只注入 HDR variant。Group A 效果使用结构化 R8 SDR fallback;CAS 额外保留条件 FP16/linear route 和独立编译 gate。alpha 由 route 显式声明 Preserve、ForceOpaque 或 Premultiplied,publication 和 overlay 边界保持一致。

官方 0.6.6 流程合入

本地 9c2309a 保留官方 0.6.6 的核心设计:

  • ScalingSessionLifetime:session generation 和 stopping 标志,过滤延迟 capture/backend/presentation 回调。
  • NgxRuntimeGuard:NGX Core、DLSSNR、DLSSFG 的统一 SEH/API 保护;fault 后阻止新会话重入已污染的 SDK 状态。
  • capture shutdown:WM_DESTROY 早期发布停止状态,关闭后的 WGC Update 进入 Waiting,旧回调不会访问新会话。
  • window owner:初始化/清理阶段解除 owner,规避同步窗口消息传播等待。
  • overlay session:恢复工具栏、固定状态、分析器和参数窗口位置/尺寸。
  • live parameter queue:last-write-wins、帧边界应用、Applied/Desired 分离;DLSSNR 通过 inputRevision 刷新历史。
  • 15-360 FPS 工具栏滑条、捕获区临时尺寸约束和参数浮窗持久化。

官方 0.6.6 的用户可见设计和 HDR boundary 是两层职责:0.6.6 负责会话与资源生命周期,HDR 层负责 canonical FP16、色彩 metadata、格式适配和 terminal presentation。

配置与回退重点

重点审查入口:

  • ScalingFlags::EnableHdrCompatibility
  • ScalingOptions::IsHdrCompatibilityEnabled()
  • Renderer::_UpdateHdrEffectBoundaryContexts()
  • NativeEffectBackendFactory.cpp
  • EffectDrawer.cpp
  • GraphicsCaptureFrameSource.cpp
  • AdaptivePresenter.cpp
  • CompSwapchainPresenter.cpp
  • XeSSFGPresenter.cpp
  • PassThroughFrames.cpp
  • EffectCompiler.cpp
  • AppSettings.cpp / ProfilePage.xaml

HDR off 的强制合同:

  1. 所有 HdrEffectBoundaryContext 清空。
  2. canonical FP16、HDR normalization 和 HDR terminal 资源保持 inactive。
  3. native factory 选择线上 backend 类、参数和 U8/LDR 输入。
  4. XeSS LDR flag、RTX Video U8 scale、NVOF/AMD OF 原有 U8 provider 和 PassThrough LDR shader恢复线上语义。
  5. HDR-only selector 隐藏或回到基线选项,配置中残留的 HDR 参数不参与 SDR 处理。
  6. publication/presenter 使用线上 format/color-space。

验证

已在 E:\Magpie-0.6.5-build 完成 Release x64 全量重建,版本为 0.6.6-hdr-fp16compat。

  • Magpie.exe SHA-256:DC6FB593B8EABFA29D969274207DCB4304918C40E12EECB0CFE754FCD4B962C5
  • 已运行 scripts/Run-HdrMechanicalValidation.ps1,source-level checks 全部通过。
  • 用户 fork release:v0.6.6-hdr-fp16compat
  • 完整包:Magpie-Experimental-v0.6.6-hdr-fp16compat-x64.zip
  • ZIP SHA-256:18E30C33893127E03CBE2F184D17065DCE215AE2A5585B701383AF4AF169E3C1

R2 更新(2026-09-08):实机颜色修复轮

重要状态说明:DLSSNR 的 HDR 直通探索已回退。 实机日志与数值验证确认社区 DLL 的 Feature 18 模型输入契约是 sRGB 编码(U8 路径一直如此),线性 scRGB 直入导致中间调挤压在模型分布低端(灰蒙蒙、不通透),此前还出现过三处已修复的颜色故障(饱和白双重白点乘法 → 黄色高光泄露;显示器 MaxLuminance 低于 SDR 白时曲线系数 NaN → 黄色斑点;残差参数在 HDR 域的亮度/色度泄漏 → 非默认参数偏色)。当前版本 DLSSNR 在 HDR 模式下的 FP16 实验路径使用扩展 sRGB OETF([0,1] 与 U8 契约逐位一致,>1 延拓同一幂律),experimentalHdrScale 选择器已移除;SDR 模式完全回到线上行为。DLSSNR 的结论是:模型本身不支持直接 HDR 值域,HDR 模式下实际上是带编码的 SDR 域处理。

其余 HDR 兼容能力保持并已实机验证:DLSS SR、DLSSFG、XeSSFG 走 DirectFP16/terminal 路由原生无损;FSR 系、XeSS SR、RTX Video、光流的 HDR 分支保留。HDR 兼容开关关闭时已逐边界复查,与官方 0.6.6 完全等效(capture/effect/native/presenter/compiler 宏全部 gate)。

本轮同时把构建机硬编码的 SDK 路径从 Magpie.vcxproj、Magpie.Core.vcxproj、WinUI.targets 还原为上游原版(机器特定覆盖已移回未跟踪的 BuildOptions.props.user),PR diff 现在只含功能性变更,无文件删除,与上游文档保持一致。

实机构建与验证:fork release v0.6.6-hdr-r1(含 r1+r2 修复,SHA-256 见 release 页)。

Review focus

请按下面顺序审阅:

  1. 以官方 v0.6.6-experimental 对比 local-0.6.5-hdr,确认 0.6.6 session/NGX/capture/overlay 语义完整。
  2. 逐个检查 NativeEffectBackendFactory 的 legacy/U8 branch,确认 HDR off 完全回到线上 0.6.5 处理。
  3. 检查 DLSSNR 的实际 color/depth/motion/exposure descriptor、inputRevision 和 bounded inverse。
  4. 检查 DLSSFG、XeSSFG、PassThrough 和 shared publication 的 terminal/alpha/color-space contract。
  5. 用 HDR off + external display HDR on 和 HDR on 两组配置,记录 route、descriptor、尺寸、dispatch、readback、pixel statistics、image hash 和 presenter descriptor。

本 PR 提交源码、资源和已构建版本相关变更;详细交接稿留在本地工作树,作为本 PR 描述和后续上游审阅的依据,文件本身保持未加入本次推送。

… shoulder, NaN guard

Fixes three live-verified color faults on the DLSSNR HDR routes:

1. Yellow highlight leak on the SDR R8 route: MapSdrToHdr multiplied the
   SDR white point twice when restoring saturated whites, pushing them to
   (peak/80)*(sdrWhite/80)=20.25 canonical (1620 nit on a 360-nit display).
   Restore now maps saturated whites to peak/sdrWhite in the normalized
   domain before the single white-point scale.

2. NaN speckles on the bounded FP16 route: BuildShoulder divided by
   (peak-1)==0 when the monitor reports MaxLuminance below the SDR white
   (observed 80 nit vs 360 nit). The curve now degrades to the plain
   identity; FrameSourceBase raises the reported peak to the SDR white
   with a visible warning.

3. Residual tint with non-default controls: the PreserveHdrRange branch
   re-derived luma after applying the directional multiplier, leaking
   lightness into chroma when saturation/shadow/reflection controls were
   combined. Rewritten as a strict luma/chroma decomposition that stays
   linear in the FP16 domain.

The SDR-compatible routes now use a replicate contract (identity below
the SDR white point, saturate above) so captured SDR frames reach the
backend bit-exact; the bounded FP16 route uses an anchored Reinhard
shoulder with linear tail (target 2.5) and an algebraically exact inverse.
mode 2 clamps out-of-gamut negatives before the model; mode 3 keeps the
full range. DLSSNR resolution scaling and residual reconstruction are
re-enabled on the HDR path with PreserveHdrRange.

Also: SDR-white measurement failure logging, DLSSNR boundary log carries
curve parameters, DLSS SR IsHDR creation flag, XeSSFG canonical-FP16
terminal marker, FG terminal selection, signed-snippet strength ranges,
mechanical tests for the curve family and degenerate cases, fxc-validated
HLSL, and the design/upstream-handoff documents.
…ale selector

The DLSSNR model's training contract is sRGB-encoded input (what the U8
route has always fed it). Feeding linear scRGB left mid-tones squeezed
into the bottom of the model's input distribution, observed live as a
washed-out, hazy image. The bounded FP16 route now encodes the normalized
color with an extended sRGB OETF: identical to the standard curve on
[0,1] (bit-exact match with the U8 path for SDR content) and the same
power law continued above 1 for HDR headroom - monotone, exactly
invertible, no gamut clipping. Verified there is no public community
alternative; this is the most lossless encoding available for a model
whose contract is sRGB.

The experimentalHdrScale parameter and its 1/2/4.5 selector tiers are
removed everywhere (effect source, settings parsing, protocol struct,
routes, renderer wiring, status log): the normalization is now fully
derived from frame metadata. The DLSSNR route is a single fixed
experimental-fp16 BoundedHDR route.

HDR-off isolation re-audited: every boundary (capture processor, effect
drawer adapters, route selection, native factory, XeSS/NVOF/RTX-Video
branches, presenter formats, compiler macros) is gated on
IsHdrCompatibilityEnabled and returns the stock 0.6.6 behavior when the
switch is off.
The local build machine had hardened E:/D: SDK paths directly into
Magpie.vcxproj, Magpie.Core.vcxproj and WinUI.targets (CppWinRT union
include, CppWinRTPath, MagpieWindowsKitsPath SDK import, WinUI SDK bin
lookup). These are machine-specific and do not belong in the PR; the same
overrides live in the untracked BuildOptions.props.user on the build
machine. All three files are restored to the upstream experimental
versions so the PR diff contains functional changes only.
@konodiodaaaaa1

Copy link
Copy Markdown
Author

@SAOG0721 R2 状态更新,说明一下 DLSSNR 的回退结论。

经过实机日志驱动的多轮修复(黄色高光泄露、NaN 斑点、残差参数偏色均已修复),最终确认社区 DLSSNR DLL 的 Feature 18 模型输入契约是 sRGB 编码,与 U8 路径一致;线性 scRGB 直入会导致模型分布在中间调失配(画面灰蒙蒙)。目前 DLSSNR 在 HDR 模式下已回退为"扩展 sRGB 编码的 SDR 域处理"([0,1] 与 U8 路径逐位一致,>1 延拓幂律),experimentalHdrScale 实验选择器已移除,SDR 模式完全回到线上行为。结论:DLSSNR 模型不支持直接 HDR 值域,HDR 模式下本质是带编码的 SDR 处理。

其余 HDR 兼容能力不受影响并已实机验证:DLSS SR、DLSSFG、XeSSFG 原生无损直通,FSR/XeSS SR/RTX Video/光流的 HDR 分支保留;HDR 开关关闭时已逐边界复查与官方 0.6.6 完全等效(capture、effect、native、presenter、compiler 宏全部 gate,无任何残留 HDR 处理)。

另外把之前混入的构建机本地 SDK 路径(vcxproj/WinUI.targets)还原成了上游原版,现在 PR diff 只含功能性变更,无文件删除。测试构建在 fork 的 v0.6.6-hdr-r1 release,欢迎实机验证。

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