Search code examples
dxgi

DXGI 1.5 DuplicateOutput1 fails with DXGI_ERROR_UNSUPPORTED (0x887a0004)


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.


Solution

  • 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 :)