Skip to content

Instantly share code, notes, and snippets.

@v0lt
Created September 24, 2023 16:32
Show Gist options
  • Save v0lt/61f9f518a6b34972e3347cf9acd31c2a to your computer and use it in GitHub Desktop.
Save v0lt/61f9f518a6b34972e3347cf9acd31c2a to your computer and use it in GitHub Desktop.
DXGIAdapters
#include <stdio.h>
#include <dxgi.h>
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "dxguid.lib")
int main()
{
wprintf(L"Available DXGI adapters and outputs:\n");
IDXGIFactory1* pFactory = nullptr;
HRESULT hr = CreateDXGIFactory1(IID_IDXGIFactory1, (void**)(&pFactory));
if (SUCCEEDED(hr)) {
IDXGIAdapter1* pAdapter = nullptr;
UINT adapter = 0;
while (SUCCEEDED(pFactory->EnumAdapters1(adapter, &pAdapter))) {
DXGI_ADAPTER_DESC1 adapterDesc = {};
hr = pAdapter->GetDesc1(&adapterDesc);
if (SUCCEEDED(hr)) {
wprintf(L"\n");
wprintf(L"Graphics adapter[%u]: %s (%04X:%04X) %zu MiB",
adapter,
adapterDesc.Description,
adapterDesc.VendorId,
adapterDesc.DeviceId,
adapterDesc.DedicatedVideoMemory / (1024 * 1024)
);
if (adapterDesc.Flags == DXGI_ADAPTER_FLAG_SOFTWARE) {
wprintf(L" software");
}
wprintf(L"\n");
}
UINT output = 0;
IDXGIOutput* pDXGIOutput = nullptr;
while (SUCCEEDED(pAdapter->EnumOutputs(output, &pDXGIOutput))) {
DXGI_OUTPUT_DESC outputDesc = {};
hr = pDXGIOutput->GetDesc(&outputDesc);
if (SUCCEEDED(hr)) {
wprintf(L" Output device[%u]: %s %dx%d\n",
output,
outputDesc.DeviceName,
outputDesc.DesktopCoordinates.right - outputDesc.DesktopCoordinates.left,
outputDesc.DesktopCoordinates.bottom - outputDesc.DesktopCoordinates.top);
}
output++;
}
++adapter;
}
}
wprintf(L"\n");
wprintf(L"\nPress any key to quit... ");
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment