首页 > 解决方案 > 尝试在英特尔 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。

标签: c#sharpdxdxgidesktop-duplication

解决方案


首先,要从 API 获取有关无效参数的提示(这正是您所拥有的),您需要启用 Direct3D 调试层。这篇文章为 C++ 解释了它,也可以用 C# 做一个类似的技巧。

其次,重要的是失败调用中的有效参数,而不仅仅是代码。

代码是正确的,但如果坐标mOutputDescription为零或无效,则上述 API 调用也会失败。您需要设置断点并检查变量。


推荐阅读