Tech Notes: Device Enumeration for PC
Oculus Developer Blog
Posted by Matt Conte
February 10, 2017

Welcome to another installation of the Oculus tech note series. This week's note focuses on the PC graphics device enumeration procedure required for native code.

For Unity and Unreal titles, the PC graphics device enumeration procedure is handled within the integration. If you are using native code however, you will need to use the LUID filled in by the second parameter to ovr_Create() to compare against the DXGI adapter LUID during enumeration. (Note that this example is for DX11, but the process is similar for DX12.) This implementation will allow systems that have multiple GPUs (such as laptops with switching GPU graphics or desktops with SLI) to properly target the Rift HMD. Essentially if you don't do this, your title won't work for these systems.

We have provided snippets below as an example.:

// return true to retry later (e.g. after display lost)
static bool MainLoop(bool retryCreate)
    // During initialization 
    ovrSession session;
    ovrGraphicsLuid luid;
    ovrResult result = ovr_Create(&session, &luid);
    if (!OVR_SUCCESS(result))
        return retryCreate;

    ovrHmdDesc hmdDesc = ovr_GetHmdDesc(session);

    // Setup Device and Graphics
    IDXGIFactory4 * DXGIFactory = nullptr;
    HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory));
    VALIDATE((hr == ERROR_SUCCESS), "CreateDXGIFactory1 failed");

    IDXGIAdapter * Adapter = nullptr;
    for (UINT iAdapter = 0; DXGIFactory->EnumAdapters(iAdapter, &Adapter) != DXGI_ERROR_NOT_FOUND; ++iAdapter)
        DXGI_ADAPTER_DESC adapterDesc;
        if (memcmp(&adapterDesc.AdapterLuid, &luid, sizeof(LUID)) == 0)

    ID3D11Device           * Device;
    ID3D11DeviceContext    * Context;
    hr = D3D11CreateDevice(Adapter, DriverType, 0, 0, 0, 0, D3D11_SDK_VERSION, &Device, 0, &Context);
    VALIDATE((hr == ERROR_SUCCESS), "D3D11CreateDevice failed");

That’s all you need to properly target the Rift HMD in a native engine.

Drop us a comment in this post with topics you would like the team to consider for future tech notes.