public static int GetIndex(this IDXGIAdapter adapter) { if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } using (var fac = DXGIFunctions.CreateDXGIFactory1()) { var desc = adapter.GetDesc(); int i = 0; do { if (fac.Object.EnumAdapters((uint)i, out var a).IsError) #if DEBUG { throw new InvalidOperationException(); } #else { return(-1); // wot? } #endif var desca = a.GetDesc(); if (desca.AdapterLuid.luid == desc.AdapterLuid.luid) { return(i); } i++; }while (true); } }
static void Main(string[] args) { using var factory = new IDXGIFactory(); var hr = dxgi.CreateDXGIFactory(ref factory.GetIID(), ref factory.NewPtr); if (hr != 0) { throw new System.Runtime.InteropServices.COMException("CreateDXGIFactory", hr); } for (uint i = 0; ; ++i) { using var adapter = new IDXGIAdapter(); hr = factory.EnumAdapters(i, ref adapter.NewPtr); if (hr != 0) { break; } DXGI_ADAPTER_DESC desc = default; adapter.GetDesc(ref desc); Console.WriteLine(desc.Description); } }
public static DXGI_ADAPTER_DESC GetDesc(this IDXGIAdapter adapter) { if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } var desc = new DXGI_ADAPTER_DESC(); adapter.GetDesc(out desc).ThrowOnError(); return(desc); }