Skip to content

feat(dovi): libplacebo-style Dolby Vision RPU mapping and HDR tone/gamut pipeline - #136

Open
1824239290 wants to merge 1 commit into
AimesSoft:mainfrom
1824239290:agent/dolby-vision-mapping
Open

1824239290 wants to merge 1 commit into
AimesSoft:mainfrom
1824239290:agent/dolby-vision-mapping

Conversation

@1824239290

Copy link
Copy Markdown
Contributor

概要

libplacebo 实现 Dolby Vision RPU 映射与 HDR tone/gamut 管线:读取 FFmpeg AV_FRAME_DATA_DOVI_METADATA,完成 polynomial/MMR reshape → 非线性矩阵 → PQ 线性化 → HPE-LMS → IPT tone map(默认 BT.2390)→ 感知色域 LUT → SDR/EDR 输出。

取代已关闭的 #130(历史已 squash 为单 commit,并按该 PR review 修正后重新提交)。#133 / #134 的改动已包含在本 PR 内,无需再单独合入。

相对 #130 review 的回应

[P1] Profile 5 不应一律切软解 — 已改

dolby_vision_decode_fallback 仅在 MediaCodec / generic AvCodec 上对 Profile 5 回退软件解码;VideoToolbox 与 D3D11VA 保留硬解(FFmpeg CPU 解析 RPU 并 attach 到硬件 AVFrame 的路径与 review 实验一致)。

[P2] coef_log2_denom 31/32 被误拒 — 已改

接受 FFmpeg 的 13..=32 范围(coef_denom > 32 才拒绝)。系数用 powi 浮点缩放,不再因 31/32 拒绝合法元数据。

文档与范围 — 已改

  • 新增 docs/dolby-vision.md;删除 DOLBY_VISION_IMPROVEMENTS.md
  • Profile 8 按单层描述(8.1 HDR10 / 8.4 HLG 兼容 base)。
  • 感知色域 LUT 文档标明为 simplified dead-zone,不声称完整 pl_gamut_map_perceptual
  • CHANGELOG Unreleased 覆盖主功能。

图像验证 — 已补

真实样片 + mpv v0.41.0 / libplacebo v7.360.1(--vo=gpu-next --tone-mapping=bt.2390)同帧对比:

样片 PSNR SSIM 说明
Profile 5 frame 30 35.95 dB 0.9952 L1 驱动 peak=1811 nits
Profile 8.1 frame 30 35.36 dB 0.9950 同上
Profile 7 FEL frame 300 33.25 dB 0.9616 基层映射生效;增强层不合成
Profile 7 FEL frame 60(暗场) 30.37 dB 0.7192 黑位略抬,已知差异

FEL 策略调整

不再整帧丢弃 FEL RPU;基层曲线/矩阵/L1 照常映射,不可合成的 residual 通过 Frame::dovi_el_status()dovi_el_not_composed 诊断上报(对齐 libplacebo 对 nlq_active 的切分)。

主要改动

  1. RPU 解析ffmpeg.rs):bounds/alignment 校验、pivot/系数缩放、L1 提取、结构化 DoviRejectReason、单次 parse probe。
  2. Uniform / shaderpipeline.rs + WGSL/MSL/HLSL):reshape、IPT tone map(BT.2390 默认 + spline/BT.2446a/ST 2094-10/Mobius/Reinhard/clip)、感知色域 3D LUT(48×32×256,RGBA16F,后台生成)。
  3. HDR10 场景自适应luma_stats.rs):CPU luma 测量,区分 yuv420p10le / P010,honor limited range。
  4. 平台:Metal 按 presenting screen 协商 EDR/Auto HDR;LUT 生成期间不绑定占位纹理(Metal/D3D11);D3D11 软件 NV12/P010 上传;P010 UNORM 预缩放(三端)。
  5. 解码回退:仅移动端 P5 回退软解;诊断节流上报。

已知限制(合并不阻塞)

  • FEL/MEL residual 不合成(按设计;有诊断)。
  • 感知色域为简化 dead-zone,高饱和 BT.2020→709 可能与 mpv 略有差异;暗部相对 mpv 约 +6 L(p05)。
  • Auto HDR / presenting-screen 协商目前仅 Metal 对齐。
  • Metal embedder 需设置 CAMetalLayer.delegate(示例已改)。
  • 无 golden-pixel 参考帧 CI;样片对比为本地验收。

验证

  • cargo test -p erika --lib583 passed(本机)
  • cargo fmt --check 干净
  • 样片:P5 / P8.1 / FEL(wgpu_decode_pngERIKA_TEST_RENDER_PASSES=4)vs mpv,见上表
  • 基线:main @ 905d5fc,单 commit 9f7870f,28 files / +7686 −226

验证边界

CI 全绿仍不覆盖真实 DV 片源的跨后端像素一致性;上表样片对比为 macOS Metal wgpu 离屏路径。Windows D3D11 真机与移动端 MediaCodec 待后续真机验收。

cc #130(原 review:P5 硬解、coef_denom、图像验证)

…mut pipeline

Implements end-to-end Dolby Vision and HDR color mapping aligned with
libplacebo/mpv gpu-next.

RPU path
- Parse AV_FRAME_DATA_DOVI_METADATA with bounds/alignment checks; scale
  pivots by base-layer bit depth and coefficients by 2^-coef_log2_denom.
- Piecewise polynomial + MMR reshaping, nonlinear ycc_to_rgb, PQ
  linearization, and HPE-LMS composite (forced BT.2020/PQ for P5/P8).
- Per-frame L1 drives the tone-map peak/scene average; static L0 still
  decides output-mode negotiation and tone-map/LUT enablement.
- Profile 5 falls back to software decode on MediaCodec/AvCodec; desktop
  VideoToolbox/D3D11VA keep hardware decode.
- Profile 7 FEL residual is reported (DoviElStatus) rather than dropping
  the whole RPU; base-layer mapping still applies.
- Structured reject reasons + throttled diagnostics.

Tone and gamut mapping
- IPT-domain single-pass tone map with BT.2390 default, plus spline,
  BT.2446 method A, ST 2094-10, Mobius, Reinhard, clip. Black-point
  compensation via contrast_ratio (auto 1000:1 for SDR).
- ST 2094-10 knee picked in the PQ domain; degenerate anchors fall back
  to Clip instead of a black frame.
- Perceptual gamut mapping via a CPU-generated 48x32x256 IPT 3D LUT
  (RGBA16F) shared by Metal/wgpu/D3D11, generated off-thread, cached by
  (source, target, target black, target peak). Chroma rolloff is a
  simplified dead-zone blend rather than libplacebo's full boundary
  search (documented).
- HDR10 scene-adaptive pivot via CPU luma measurement (luma_stats),
  honoring limited range and yuv420p10le vs P010 packing.

Platform
- Metal: negotiate EDR/Auto HDR from the presenting screen; linearize
  subtitles/danmaku into EDR drawables; do not bind the placeholder LUT
  while it regenerates.
- D3D11: upload the LUT as true RGBA16F Texture3D; mask
  gamut_lut_enabled while generation is pending (constants are passed
  into draw_video, not a discarded local).
- CI: build/upload wgpu_decode_png and erika-capi bundle on macOS arm64.

Docs
- New docs/dolby-vision.md; CHANGELOG Unreleased covers the feature set;
  architecture.md default operator corrected to BT.2390.

Tests: cargo test -p erika --lib (583) pass locally; fmt clean.
1824239290 pushed a commit to 1824239290/Erika that referenced this pull request Sep 10, 2026
Based on upstream v0.1.9. Squashed Dolby Vision RPU mapping + HDR
tone/gamut pipeline (see AimesSoft#136).
@1824239290
1824239290 force-pushed the agent/dolby-vision-mapping branch from 9f7870f to 8d55281 Compare September 10, 2026 05:10
1824239290 pushed a commit to 1824239290/Erika that referenced this pull request Sep 10, 2026
Based on upstream v0.1.9. Squashed Dolby Vision RPU mapping + HDR
tone/gamut pipeline (see AimesSoft#136).
@1824239290
1824239290 force-pushed the agent/dolby-vision-mapping branch 2 times, most recently from 7de7210 to 1694e55 Compare September 10, 2026 05:21
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