DXGI Device (dxgidevice)

Overview

The IDxgiDevice interface represents a virtual representation of a physical GPU and provides methods for creating other DXGI objects, such as adapters and swap chains.

Syntax
Methods
Example
interface IDxgiDevice : IUnknown {
    HRESULT CreateSurface(
        const DXGI_SURFACE_DESC* pDesc,
        UINT NumSurfaces,
        DXGI_USAGE Usage,
        const DXGI_SHARED_RESOURCE* pSharedResource,
        IDXGISurface** ppSurface
    );

    HRESULT QueryResourceResidency(
        IUnknown* const* ppResources,
        DXGI_RESIDENCY* pResidency,
        UINT NumResources
    );

    HRESULT SetGPUThreadPriority(
        INT Priority
    );

    HRESULT GetGPUThreadPriority(
        INT* pPriority
    );
};

CreateSurface

Creates a DXGI surface that can be used for rendering or presentation.

HRESULT CreateSurface(
    const DXGI_SURFACE_DESC* pDesc,
    UINT NumSurfaces,
    DXGI_USAGE Usage,
    const DXGI_SHARED_RESOURCE* pSharedResource,
    IDXGISurface** ppSurface
);

QueryResourceResidency

Determines the residency status of one or more resources.

HRESULT QueryResourceResidency(
    IUnknown* const* ppResources,
    DXGI_RESIDENCY* pResidency,
    UINT NumResources
);

SetGPUThreadPriority / GetGPUThreadPriority

Controls the priority of the GPU thread associated with the device.

HRESULT SetGPUThreadPriority(INT Priority);
HRESULT GetGPUThreadPriority(INT* pPriority);

Sample Code

#include <dxgi.h>
#include <d3d11.h>
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")

int main() {
    IDXGIFactory* pFactory = nullptr;
    CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&pFactory);

    IDXGIAdapter* pAdapter = nullptr;
    pFactory->EnumAdapters(0, &pAdapter);

    ID3D11Device* pDevice = nullptr;
    ID3D11DeviceContext* pContext = nullptr;
    D3D_FEATURE_LEVEL level;
    D3D11CreateDevice(pAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0,
                      nullptr, 0, D3D11_SDK_VERSION,
                      &pDevice, &level, &pContext);

    IDXGIDevice* pDXGIDevice = nullptr;
    pDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&pDXGIDevice);

    // Set high GPU thread priority
    pDXGIDevice->SetGPUThreadPriority(7);

    // Clean up
    pDXGIDevice->Release();
    pContext->Release();
    pDevice->Release();
    pAdapter->Release();
    pFactory->Release();
    return 0;
}

See Also