DirectX Graphics Infrastructure (DXGI)

Overview

The DirectX Graphics Infrastructure (DXGI) is a low‑level API that handles enumerating graphics adapters, managing swap chains, and handling full‑screen transitions. DXGI works as the bridge between the graphics driver and higher‑level APIs such as Direct3D 12, Direct3D 11, and Direct2D.

Key responsibilities include:

  • Adapter and output enumeration
  • Swap chain creation and presentation
  • Fullscreen mode management
  • Resource sharing between processes

Quick Start

#include <dxgi1_6.h>
#include <d3d12.h>

IDXGIFactory6* factory = nullptr;
CreateDXGIFactory2(0, IID_PPV_ARGS(&factory));

IDXGIAdapter1* adapter = nullptr;
for (UINT i = 0;
     factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND;
     ++i) {
    DXGI_ADAPTER_DESC1 desc;
    adapter->GetDesc1(&desc);
    if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) continue;
    // Choose first hardware adapter
    break;
}

ID3D12Device* device = nullptr;
D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0,
                  IID_PPV_ARGS(&device));

Key Interfaces

InterfaceDescription
IDXGIFactoryCreates adapters, swap chains, and enumerates outputs.
IDXGIAdapterRepresents a GPU or software rendering device.
IDXGISwapChainManages buffers that are presented to the screen.
IDXGIOutputRepresents a display monitor (output).
IDXGISurfaceBase interface for DXGI surfaces.

Important Enums

enum DXGI_FORMAT {
    DXGI_FORMAT_UNKNOWN = 0,
    DXGI_FORMAT_R8G8B8A8_UNORM = 28,
    DXGI_FORMAT_B8G8R8A8_UNORM = 87,
    // ... more formats
};

enum DXGI_SWAP_EFFECT {
    DXGI_SWAP_EFFECT_DISCARD = 0,
    DXGI_SWAP_EFFECT_SEQUENTIAL = 1,
    DXGI_SWAP_EFFECT_FLIP_DISCARD = 3,
    DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL = 4,
};

Common Structures

typedef struct DXGI_MODE_DESC {
    UINT Width;
    UINT Height;
    DXGI_RATIONAL RefreshRate;
    DXGI_FORMAT Format;
    DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
    DXGI_MODE_SCALING Scaling;
} DXGI_MODE_DESC;

typedef struct DXGI_SWAP_CHAIN_DESC {
    DXGI_MODE_DESC BufferDesc;
    DXGI_SAMPLE_DESC SampleDesc;
    DXGI_USAGE BufferUsage;
    UINT BufferCount;
    HWND OutputWindow;
    BOOL Windowed;
    DXGI_SWAP_EFFECT SwapEffect;
    UINT Flags;
} DXGI_SWAP_CHAIN_DESC;

Samples

Explore the official DirectX Graphics Samples repository for a complete set of DXGI examples, including swap chain management, multi‑adapter rendering, and resource sharing.