-
-
Save qryxip/be52a959cfb8559e41adfa1bd7445823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ffi::OsString, ptr}; | |
use eyre::ensure; | |
#[cfg(windows)] | |
fn main() -> eyre::Result<()> { | |
use std::os::windows::ffi::OsStringExt as _; | |
use winapi::{ | |
ctypes::c_void, | |
shared::{ | |
dxgi::{CreateDXGIFactory, IDXGIAdapter, IDXGIFactory, DXGI_ADAPTER_DESC}, | |
winerror::DXGI_ERROR_NOT_FOUND, | |
}, | |
Interface as _, | |
}; | |
macro_rules! try_hresult { | |
($result:expr) => {{ | |
let result = $result; | |
ensure!(result == 0, "result={result}"); | |
}}; | |
} | |
unsafe { | |
let mut factory = ptr::null_mut::<IDXGIFactory>(); | |
let uuid = IDXGIFactory::uuidof(); | |
try_hresult!(CreateDXGIFactory( | |
ptr::addr_of!(uuid), | |
ptr::addr_of_mut!(factory) as *mut *mut c_void, | |
)); | |
let factory = &mut *factory; | |
let mut i = 0; | |
loop { | |
let mut adapter = ptr::null_mut::<IDXGIAdapter>(); | |
let result = factory.EnumAdapters(i, ptr::addr_of_mut!(adapter)); | |
if result == DXGI_ERROR_NOT_FOUND { | |
break Ok(()); | |
} | |
try_hresult!(result); | |
let adapter = &mut *adapter; | |
let mut desc = DXGI_ADAPTER_DESC::default(); | |
try_hresult!(adapter.GetDesc(ptr::addr_of_mut!(desc))); | |
eprintln!("===================="); | |
dbg!(i); | |
dbg!(OsString::from_wide(&desc.Description)); | |
dbg!(desc.VendorId); | |
dbg!(desc.DeviceId); | |
dbg!(desc.SubSysId); | |
dbg!(desc.Revision); | |
dbg!(desc.DedicatedVideoMemory); | |
dbg!(desc.DedicatedSystemMemory); | |
dbg!(desc.SharedSystemMemory); | |
dbg!(desc.AdapterLuid.LowPart); | |
dbg!(desc.AdapterLuid.HighPart); | |
i += 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Optimusを切った場合、GeForceとMicrosoft Basic Render Driverしか見えなくなる。