> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DirectCapture 概述

> DirectCapture 通过在软件中捕获兼容帧而非经由显示硬件，将 XBOX 游戏串流服务器延迟最多降低 72 毫秒。

## DirectCapture

DirectCapture 是一项 XBOX 游戏串流平台功能，可自动为兼容帧最小化服务器延迟。[XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails) API 允许您查询兼容帧的要求，以便确保您的游戏能够利用 DirectCapture。兼容帧的要求解释如下。

XBOX 游戏串流通过捕获（复制）呈现的帧然后为串流编码帧来串流游戏。没有 DirectCapture 时，帧使用显示硬件从输入呈现参数转换为编码格式。帧在 Present Queue 中有 0-66ms 的延迟，然后帧经过 Display Writeback (DWB) 又增加 8.3ms 的延迟以进行帧捕获。在 Present Queue 中的时间取决于诸如游戏帧率以及是否使用双缓冲或三缓冲等因素。8.3ms 的 Display Writeback 时间固定为 8.3ms，因为它绑定到 HDMI 时钟。

然而，XBOX 游戏串流服务器上没有连接 HDMI 显示器，因此 DirectCapture 通过软件实现绕过该时间，而不是使用显示硬件。DirectCapture 通过消除等待 VSync 以及等待双缓冲或三缓冲翻转的时间，在大约 2-12ms 内为编码捕获帧。这可将延迟最多减少 72ms。

为了获得更低的延迟，游戏必须使用与 DirectCapture 兼容的参数进行呈现。

* 支持的主机模式
  * Lockhart Profiling Mode
* 支持的游戏渲染分辨率
  * 任何，包括[自定义分辨率](/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview)
* 支持的交换链格式
  * DXGI\_FORMAT\_R8G8B8A8\_UNORM
  * DXGI\_FORMAT\_B8G8R8A8\_UNORM
  * DXGI\_FORMAT\_R8G8B8A8\_UNORM\_SRGB
  * DXGI\_FORMAT\_B8G8R8A8\_UNORM\_SRGB
  * DXGI\_FORMAT\_R10G10B10A2\_UNORM
  * DXGI\_FORMAT\_R9G9B9E5\_SHAREDEXP
* 支持的颜色空间
  * DXGI\_COLOR\_SPACE\_RGB\_FULL\_G22\_NONE\_P709

DirectCapture 目前不支持未在上面列出的呈现参数。例如，以下情况不受支持：

* 游戏渲染分辨率：XDK 游戏使用的 3840x2160
* HDR
* 多个呈现平面

[XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails) 可帮助确定要呈现的内容以与 DirectCapture 兼容，并计划将来发布 PIX 支持。

## 验证您的游戏正在使用 DirectCapture 串流

您可以通过检查串流日志文件来验证您的游戏是否使用 DirectCapture 运行。

### 收集日志文件

要收集串流日志文件：

1. 开始运行游戏
2. 开始串流并使用其中一个内容测试应用 (CTA) 连接
3. 玩您游戏的一小段
4. 终止游戏
5. 断开 CTA
6. 等待 30 秒以完成日志写入
7. 将日志复制到本地目录，如 C:\temp
   1. `xbcp xt:\XStreamLogs\XStreamManagementService.etl c:\temp`
   2. `xbcp xt:\XStreamLogs\nanotrace.etl c:\temp`

### 查看转换消息

1. 使用 [Windows Performance Analyzer](https://apps.microsoft.com/store/detail/windows-performance-analyzer/9N0W1B2BXGNZ) 打开 XStreamManagementService.etl
2. 右键点击左侧窗格中的 System Activity 并选择 “Add graph to Analysis View”
3. 在下窗格中展开 Microsoft.Xbox.StreamManagementService
4. 查找 Microsoft.Xbox.HostStreamingAgent 提供程序并根据需要展开它。如果缺少，请重复上述收集日志文件的步骤。
5. 选择 DirectCaptureLog 任务，如有必要，展开 Unknown Process
6. 向右滚动并查找名为 0\_Message、1\_Message 等的列。每一列都是来自 DirectCapture 的一个连续消息。如果有多行，它们按时间排序。
7. 请参见下表了解每条消息的含义。这些消息将为您提供 DirectCapture 转换的顺序，并说明 DirectCapture 被禁用的原因。

| 消息 ID | 消息                                                                        |
| ----- | ------------------------------------------------------------------------- |
| 1     | 切换到 DirectCapture                                                         |
| 2     | 切换到 DWB（DirectCapture 已禁用）                                                |
| 3     | 不支持的渲染平面配置。这可能是由于游戏内渲染平面，或系统在标题上渲染叠加层（例如系统通知）                             |
| 4     | 不支持的像素格式。请参阅相关的 PixelFormat 了解当时游戏的像素格式                                   |
| 5     | 不支持的平铺模式。请参阅相关的 TileMode 了解当时游戏的平铺模式                                      |
| 6     | 不支持的游戏分辨率。请参阅相关的 GameResolutionWidth 和 GameResolutionHeight 查看当时游戏的渲染分辨率。 |
| 8     | 屏幕上显示非游戏帧                                                                 |
| 12    | 未启用 DirectCapture（可能是由于不受支持的主机模式）                                         |
| 18    | 不支持的源矩形大小                                                                 |
| 19    | 不支持的 Present 参数标志                                                         |
| 21    | 不支持的目标矩形大小                                                                |

### 详细帧信息

1. 使用 Windows Performance Analyzer 打开 nanotrace.etl
2. 导航到 “Microsoft.Xbox.CloudStreaming” 提供程序并选择 “VideoFrameCaptureSourceChanged” 任务，然后展开进程 “ApplicationClipService.exe” 以查看所有 “VideoFrameCaptureSourceChanged” 事件。
3. 检查 “NewCaptureSource” 字段
   * 当值为 “DCap” 时，您的游戏开始使用 DirectCapture 的更低延迟进行串流
   * 值为 “DWB” 表示不使用 DirectCapture，而使用默认的捕获机制。这会在以下情况下发生：
     * 游戏输出与 DirectCapture 不兼容的帧
     * 系统在游戏上渲染叠加层（例如系统通知）

## 注意事项

* nanotrace.etl 具有有限的历史记录，因此如果您没有看到 “VideoFrameCaptureSourceChanged”，则可能是您的会话过长。为了验证，请运行较短的会话并检查 ETL。
* 开发套件上对 DirectCapture 的支持仅限于 XBOX Series X 开发套件
* 有关更多信息，请观看 [XBOX 游戏串流：降低延迟并为最佳移动体验进行优化](https://www.youtube.com/watch?v=-WIXftoHCl4)。

## 另请参阅

[自定义分辨率概述](/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview)


## Related topics

- [游戏串流自定义分辨率最佳实践](/zh-CN/build/core-features/common/game-streaming/game-streaming-custom-resolution-best-practices.md)
- [针对 XBOX 游戏串流优化您的游戏](/zh-CN/build/core-features/common/game-streaming/game-streaming-optimizing-your-game.md)
- [自定义分辨率概述](/zh-CN/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview.md)
- [XGameStreamingGetDisplayDetails](/zh-CN/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails.md)
- [DirectStorage 概述](/zh-CN/build/console-features/storage/directstorage/directstorage-overview.md)
