Tech Notes: Device Enumeration for PC

Matt ConteBlog Hero Image
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;
        Adapter->GetDesc(&adapterDesc);
        if (memcmp(&adapterDesc.AdapterLuid, &luid, sizeof(LUID)) == 0)
            break;
        Release(Adapter);
    }

    ID3D11Device           * Device;
    ID3D11DeviceContext    * Context;
    auto DriverType = Adapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE;
    hr = D3D11CreateDevice(Adapter, DriverType, 0, 0, 0, 0, D3D11_SDK_VERSION, &Device, 0, &Context);
    Release(Adapter);
    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.
Rift
Unity
Unreal
Did you find this page helpful?
Explore more
Introducing Meta XR Operator: Close the Build-Test-Verify Loop for VR
Meta XR Operator lets any MCP-compatible AI agent see, navigate, and interact with your running VR app in Meta XR Simulator, closing the build-test-verify loop.
Optimization, Quest, Unity
What Unity Developers Learned About Building for Meta Quest at Unite Seoul 2026
New AI tools make building for Meta Quest in Unity faster than ever. See what we shared at Unite Seoul 2026.
Design, Hand tracking, Optimization, Quest, Unity
Build Faster, Earn More: Accelerating Your Unity VR Workflow
Accelerate your Unity development for Meta Quest with agentic AI tools that handle setup, prototyping, performance analysis, and iteration.
All, Optimization, Quest, Unity

Get the latest updates from Meta VR.

Get access to highlights and announcements delivered to your inbox.