2

For some reason DuplicateOutput1 fails where DuplicateOutput does not.

#include <D3D11.h>
#include <DXGI1_5.h>

int main() {
    ID3D11Device *device;
    D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_1 };
    D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, levels, ARRAYSIZE(levels), D3D11_SDK_VERSION, &device, NULL, NULL);

    IDXGIDevice *dxDevice;
    device->QueryInterface<IDXGIDevice>(&dxDevice);

    IDXGIAdapter *adapter;
    dxDevice->GetAdapter(&adapter);

    IDXGIOutput *output;
    adapter->EnumOutputs(0, &output);

    IDXGIOutput5 *output5;
    output->QueryInterface<IDXGIOutput5>(&output5);

    IDXGIOutputDuplication *outputDuplication;
    auto hr1 = output5->DuplicateOutput(device, &outputDuplication);

S_OK here

    const DXGI_FORMAT formats[] = { DXGI_FORMAT_B8G8R8A8_UNORM };
    auto hr2 = output5->DuplicateOutput1(device, 0, ARRAYSIZE(formats), formats, &outputDuplication);
}

0x887a0004 : The specified device interface or feature level is not supported on this system.

Dizzy
  • 892
  • 3
  • 12
  • 24
  • Do you happen two have multiple adapters, first enumerated of which is possibly non DXGI 1.5 compliant? Basically you can `adapter->GetDesc` to see what adapter is actually being used. – Roman R. Jan 11 '18 at 14:16
  • I have only one adapter and `adapter->GetDesc` shows `NVIDIA GeForce GTX 960`. – Dizzy Jan 11 '18 at 17:51
  • Also I have same problem on another machine with `Intel(R) HD Graphics 520`. – Dizzy Jan 11 '18 at 20:38
  • I recalled I was unable to use the method earlier. The documentation refers multiple times to "running fullscreen application" and it might so happen that this optimized method is only applicable to such scenario. With regular apps, good old `DuplicateOutput` might be the one to be used. – Roman R. Jan 11 '18 at 22:15
  • 3
    For those that might stumble upon this in the future, calling SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) allows the DuplicateOutput1 to succeed. I have no idea why the DuplicateOutput1 checks the process dpi version, though. – weggo Aug 30 '18 at 11:44
  • @weggo You really should make that comment an answer. It worked for me as well. – ChrisB May 26 '19 at 09:43

2 Answers2

4

I will post here the answer from @weggo, because I almost missed it!

For those that might stumble upon this in the future, calling SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) allows the DuplicateOutput1 to succeed. I have no idea why the DuplicateOutput1 checks the process dpi version, though.

I will just add that you have to set DPI awareness to False in properties of the solution in manifest settings, to get the SetProcessDpiAwarenessContext to work :)

Daniel
  • 58
  • 6
2

This could happen if you run on a system with both an integrated graphics chip and a discrete GPU. See https://support.microsoft.com/en-us/kb/3019314:

unfortunately this issue occurs because the Desktop Duplication API does not support being run against the discrete GPU on a Microsoft Hybrid system. By design, the call fails together with error code DXGI_ERROR_UNSUPPORTED in such a scenario.

To work around this issue, run the application on the integrated GPU instead of on the discrete GPU on a Microsoft Hybrid system.

  • There was only one GPU adapter and I had this error, so it is not the case. – Dizzy Jan 15 '19 at 15:00
  • This happened with me. It's working after I switched to the integrated graphics. Is there any way to detect this before the error happens? – Nicke Manarin Oct 08 '19 at 19:20