Error when trying to capture desktop using DXGI and DirectX11 on intel 630 HD

0

I get the below error when trying to use DXGI to capture the builtin screen on my laptop that runs on an Intel 630 HD with the latest driver. The code works when I capture the external screen running on my GTX 1070.

SharpDX.SharpDXException
  HResult=0x80070057
  Message=HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

The code in my form:

desktopDuplicator = new DesktopDuplicatorD11(1,0, DesktopDuplicatorD11.VSyncLevel.None);

The section of the code that errors:

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;
        }

It errors specifically on the line:

desktopImageTexture = new Texture2D(mDevice, mTextureDescription);

What is causing the error when using the internal display and the intel 630?

Edit #1: mTextureDescription creation:

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
            };

The whole Desktop Duplication process is done on the same thread.

Update #2: On the intel 630 Width = this.mOutputDescription.DesktopBounds.Right, returns 0 where as on my 1070 it returns 1920.

c#
sharpdx
dxgi
desktop-duplication
asked on Stack Overflow Apr 14, 2020 by Jacob Harrand • edited Apr 14, 2020 by Jacob Harrand

1 Answer

0

First, to get hints from API about invalid argument (this is exactly what you have) you need to enable Direct3D Debug Layer. The article explains it for C++ and it is possible to do a similar trick with C# as well.

Second, important is what are effectively the arguments in the failing call, not just the code.

The code is about right but if coordinates in mOutputDescription are zero or invalid, the mentioned API call is going to fail as well. You need to set a break point and inspect the variable.

answered on Stack Overflow Apr 14, 2020 by Roman R.

User contributions licensed under CC BY-SA 3.0