Skip to content

feat(video): add experimental D3D12 HDR analysis pipeline - #872

Draft
qiin2333 wants to merge 3 commits into
masterfrom
codex/windows-d3d12-video-pipeline
Draft

feat(video): add experimental D3D12 HDR analysis pipeline#872
qiin2333 wants to merge 3 commits into
masterfrom
codex/windows-d3d12-video-pipeline

Conversation

@qiin2333

Copy link
Copy Markdown
Collaborator

改了啥呀

  • 加入 Windows 视频管线 M0 可观测性:异步 GPU timing、路径计数器、机器可读日志和 benchmark 脚本。
  • 增加 windows_video_backendauto / d3d11 / d3d12 选择、结构化诊断及严格模式。
  • 建立独立 D3D12 device、compute queue、共享 fence 和三槽资源 ring;忙碌时跳过,不会为了旧分析帧阻塞编码路径。
  • 等价移植两阶段 HDR luminance analysis,保持现有 min/max/average 和 PQ 直方图百分位语义。
  • 使用 DXC 离线生成并嵌入 SM6 DXIL,同时用 FXC 编译 SM5 版本校验 D3D11/D3D12 shader 源一致性。
  • 接入异步 readback、generation 防迟到发布、设备移除检测和 D3D11 会话级回退。
  • 补充实施方案、基准说明、20 项单元测试及真实 D3D12 硬件探针。

为啥要改

当前 Windows 捕获和编码交接仍以 D3D11 为主,HDR 分析又很容易掉进同步等待和重复复制这两个小杂鱼坑里。这次先把测量、资源所有权、显式同步和统计等价性打牢,为后续 fused conversion 与原生 D3D12 encoder surface 提供可验证的基础。

auto 目前仍选择 D3D11;只有显式请求 d3d12 且 compute snapshot 可用时才启用 hybrid HDR analysis。初始化、提交或设备状态异常都会回退 D3D11,不扩大默认用户风险。

验证

  • 受影响的 D3D12、backend、display_vram.cppvideo.cpp 翻译单元使用 GCC 15.2、-Wall -Werror 定向编译通过。
  • DXC cs_6_0 analysis/reduce 编译通过;FXC cs_5_0 analysis/reduce 校验通过。
  • windows_video_pipeline_unit_tests.verify.exe:20/20 通过。
  • AMD D3D12 硬件探针在三个适配器枚举上通过共享 fence、NV12/P010/RGBA16F 能力和 HDR golden result:
    • pixels=4096
    • min=100
    • max=400
    • sum=819200
  • PowerShell benchmark 脚本语法检查通过。
  • git diff --check 通过。

还需要关注

  • 这是草稿 PR;完整 CMake configure 在本机依赖配置阶段超时,因此当前验证采用定向编译和独立链接。
  • G1 前仍需 NVIDIA / Intel 矩阵、Windows 版本矩阵、debug layer 检查和 24 小时稳定性测试。
  • SM6 wave reduction、fused conversion 和原生 D3D12 编码输入不包含在本 PR。

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e141bc56-df5d-4c6c-b943-ed266501ed03

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 and others added 2 commits August 6, 2026 16:27
Conflicts resolved in display.h and display_vram.cpp, plus the semantic
fallout master introduced after this branch forked:

- master added `float maxAnalysisNits` to the AnalysisParams / snapshot
  cbuffers, replacing one pad word. Thread `max_analysis_nits` through
  d3d12::hdr_analysis_t::initialize() and display_vram_t::make_d3d12_hdr_analysis()
  so the D3D12 constant buffer matches the shader layout; otherwise the
  D3D12 analysis path would upload 0 and clamp every luminance to 0.
- master's readback now publishes analysis_max_nits and sample_sequence.
  read_d3d12_hdr_analysis_results() sets both so downstream HDR metadata
  treats D3D12 samples the same as D3D11 samples.
- master's scene_metadata_active runtime-status transition now fires for
  both the D3D11 and D3D12 readback paths.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The hybrid D3D12 analysis path previously copied the snapshot texture into
the shared resource every analysed frame, so it could only ever be slower
than plain D3D11. The P010 converter now writes its cell statistics straight
into a D3D11 UAV over the shared D3D12 texture, leaving the fence signal as
the only extra work.

Also stop the feature from taking anything else down with it:

- A build without DXC emits zero-sized DXIL blobs instead of failing, and
  the analysis backend reports `hdr_shader_unavailable` at pipeline
  creation. FXC is now a cross-validation guard rail, not a requirement.
- SUNSHINE_WINDOWS_VIDEO_BACKEND_STRICT=1 no longer bricks every encoder
  on a build where the D3D12 stage is not wired up. Only a real, failed
  initialization can mark the selection unavailable, which is what the
  design doc already described.
- A successful D3D12 base initialization clears the build_stage_unavailable
  fallback, so the warning-level fallback log means an actual failure.
- The full-resolution analysis fallback no longer dispatches while a D3D11
  readback is still outstanding, and both readbacks are now drained every
  frame so an unread staging buffer cannot stay pending forever.
- windows_video_backend is exposed in the Web UI (Advanced -> experimental
  features) with en/zh strings.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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