c# - 尝试在英特尔 630 HD 上使用 DXGI 和 DirectX11 捕获桌面时出错
问题描述
尝试使用 DXGI 捕获运行在 Intel 630 HD 上且具有最新驱动程序的笔记本电脑上的内置屏幕时,出现以下错误。当我捕获在我的 GTX 1070 上运行的外部屏幕时,该代码有效。
SharpDX.SharpDXException
HResult=0x80070057
Message=HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.
我的表格中的代码:
desktopDuplicator = new DesktopDuplicatorD11(1,0, DesktopDuplicatorD11.VSyncLevel.None);
出错的代码部分:
private bool RetrieveFrame()
{
if (desktopImageTexture == null)
desktopImageTexture = new Texture2D(mDevice, mTextureDescription);
frameInfo = new OutputDuplicateFrameInformation();
try
{
mDeskDuplication.AcquireNextFrame(500, out frameInfo, out desktopResource);
}
catch (SharpDXException ex)
{
if (ex.ResultCode.Code == SharpDX.DXGI.ResultCode.WaitTimeout.Result.Code)
{
return true;
}
if (ex.ResultCode.Failure)
{
throw new DesktopDuplicationException("Failed to acquire next frame.");
}
}
using (var tempTexture = desktopResource.QueryInterface<Texture2D>())
{
mDevice.ImmediateContext.CopyResource(tempTexture, desktopImageTexture);
}
return false;
}
它特别在线错误:
desktopImageTexture = new Texture2D(mDevice, mTextureDescription);
使用内部显示器和intel 630时出现错误的原因是什么?
编辑#1:mTextureDescription 创建:
this.mTextureDescription = new Texture2DDescription()
{
CpuAccessFlags = CpuAccessFlags.Read,
BindFlags = BindFlags.None,
Format = Format.B8G8R8A8_UNorm,
Width = this.mOutputDescription.DesktopBounds.Right,
Height = this.mOutputDescription.DesktopBounds.Bottom,
OptionFlags = ResourceOptionFlags.None,
MipLevels = 1,
ArraySize = 1,
SampleDescription = { Count = 1, Quality = 0 },
Usage = ResourceUsage.Staging
};
整个桌面复制过程在同一个线程上完成。
更新 #2:在英特尔 630Width = this.mOutputDescription.DesktopBounds.Right,
上返回 0,而在我的 1070 上返回 1920。
解决方案
首先,要从 API 获取有关无效参数的提示(这正是您所拥有的),您需要启用 Direct3D 调试层。这篇文章为 C++ 解释了它,也可以用 C# 做一个类似的技巧。
其次,重要的是失败调用中的有效参数,而不仅仅是代码。
代码是正确的,但如果坐标mOutputDescription
为零或无效,则上述 API 调用也会失败。您需要设置断点并检查变量。
推荐阅读
- mysql - 如何使用 pymysql 修复“在查询期间丢失与 MySQL 服务器的连接”
- scheduling - 如何定义具有索引的决策变量取决于同一决策变量的其他索引?
- php - php 网站可以连接到在不同服务器上运行的现有 Parse 服务器吗?
- nativescript - SearchBar 组件borderRadius 不起作用
- python - 如何使用python和beautifulsoup4对网站中的多个页面进行网页抓取?
- php - pdo SET 变量上的 SQLSTATE[HY000]
- perl - while 循环没有循环过去 1
- python - 正则表达式用键/值对解析分隔字符串(python)
- angular - 如何在不使用单元格渲染器的情况下在 ag-grid 中的单元格中制作返回线?
- r - 如何将 R 矩阵转换为 Excel,以便 R 矩阵中的所有值都位于 Excel 中的单独单元格中?