Skip to content

Instantly share code, notes, and snippets.

@smourier
Created September 17, 2024 16:34
Show Gist options
  • Save smourier/b688215471199e2305bf3b80845f5a5c to your computer and use it in GitHub Desktop.
Save smourier/b688215471199e2305bf3b80845f5a5c to your computer and use it in GitHub Desktop.
dump DXGI & NVML PCI bus information
#include <windows.h>
#include <dxgi.h>
#include <D3dkmthk.h>
#include <stdio.h>
#include "nvml\include\nvml.h"
#pragma comment(lib, "nvml\\lib\\nvml.lib")
#pragma comment(lib, "dxgi.lib")
int main()
{
IDXGIFactory* factory;
CreateDXGIFactory(IID_PPV_ARGS(&factory));
UINT i = 0;
do
{
IDXGIAdapter* adapter;
factory->EnumAdapters(i++, &adapter);
if (!adapter)
break;
DXGI_ADAPTER_DESC desc;
adapter->GetDesc(&desc);
adapter->Release();
wprintf(L"adapter #%u LUID 0x%08X.0x%08X: %s\n", i, desc.AdapterLuid.HighPart, desc.AdapterLuid.HighPart, desc.Description);
D3DKMT_OPENADAPTERFROMLUID luid{};
luid.AdapterLuid = desc.AdapterLuid;
D3DKMTOpenAdapterFromLuid(&luid);
wprintf(L" D3D handle 0x%08X\n", luid.hAdapter);
D3DKMT_ADAPTERADDRESS address{};
D3DKMT_QUERYADAPTERINFO info{};
info.hAdapter = luid.hAdapter;
info.Type = KMTQAITYPE_ADAPTERADDRESS;
info.PrivateDriverDataSize = sizeof(address);
info.pPrivateDriverData = &address;
D3DKMTQueryAdapterInfo(&info);
wprintf(L" D3D bus 0x%08X device 0x%08X function 0x%08X\n", address.BusNumber, address.DeviceNumber, address.FunctionNumber);
D3DKMT_ADAPTERTYPE rinfo{};
info.Type = KMTQAITYPE_ADAPTERTYPE;
info.PrivateDriverDataSize = sizeof(rinfo);
info.pPrivateDriverData = &rinfo;
D3DKMTQueryAdapterInfo(&info);
wprintf(L"\n");
} while (true);
factory->Release();
nvmlInit_v2();
UINT count = 0;
nvmlDeviceGetCount_v2(&count);
for (UINT i = 0; i < count; i++)
{
nvmlDevice_t device;
nvmlDeviceGetHandleByIndex(i, &device);
char name[NVML_DEVICE_NAME_BUFFER_SIZE];
nvmlDeviceGetName(device, name, NVML_DEVICE_NAME_BUFFER_SIZE);
nvmlPciInfo_t pci;
nvmlDeviceGetPciInfo(device, &pci);
printf("NVML device %u domain.bus.device.function %s 0x%08X subSystem 0x%08X %s\n", i, pci.busId, pci.pciDeviceId, pci.pciSubSystemId, name);
}
nvmlShutdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment