Skip to content

Instantly share code, notes, and snippets.

@qryxip
Last active November 1, 2022 14:00
Show Gist options
  • Save qryxip/be52a959cfb8559e41adfa1bd7445823 to your computer and use it in GitHub Desktop.
Save qryxip/be52a959cfb8559e41adfa1bd7445823 to your computer and use it in GitHub Desktop.
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;
}
}
}
@qryxip
Copy link
Author

qryxip commented Nov 1, 2022

Optimusを切った場合、GeForceとMicrosoft Basic Render Driverしか見えなくなる。

@qryxip
Copy link
Author

qryxip commented Nov 1, 2022

NvOptimusEnablementを宣言したバイナリに対しては、NVIDIA Control Panelで"Integrated graphics"を指示してもGeForceが一番上に来る。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment