Merge pull request #41 from LaunchDoesntCode/codex/proton-warp-safety
GPU: reject non-software WARP adapters under Proton
This commit is contained in:
1 file changed
+51
-2
@@ -177,8 +177,7 @@ fn create() -> windows::core::Result<Host> {
|
|||||||
// is an access violation in this process (a crash report with the
|
// is an access violation in this process (a crash report with the
|
||||||
// address and instruction) instead of a GPU fault and driver reset.
|
// address and instruction) instead of a GPU fault and driver reset.
|
||||||
if cfg!(feature = "diagnostics") && std::env::var_os("VICTORY_D3D12_WARP").is_some() {
|
if cfg!(feature = "diagnostics") && std::env::var_os("VICTORY_D3D12_WARP").is_some() {
|
||||||
let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0))?;
|
let adapter = warp_adapter()?;
|
||||||
let adapter: IDXGIAdapter = factory.EnumWarpAdapter()?;
|
|
||||||
D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?;
|
D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?;
|
||||||
tracing::info!("host device on the software adapter (WARP)");
|
tracing::info!("host device on the software adapter (WARP)");
|
||||||
} else {
|
} else {
|
||||||
@@ -227,6 +226,56 @@ fn create() -> windows::core::Result<Host> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// DXGI may return hardware for `EnumWarpAdapter` (notably under Proton).
|
||||||
|
/// Reject it before creating a device in diagnostics' software-only mode.
|
||||||
|
fn warp_adapter() -> windows::core::Result<IDXGIAdapter> {
|
||||||
|
// SAFETY: plain DXGI adapter queries.
|
||||||
|
unsafe {
|
||||||
|
let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0))?;
|
||||||
|
let adapter: IDXGIAdapter = factory.EnumWarpAdapter()?;
|
||||||
|
let desc = adapter.cast::<IDXGIAdapter1>()?.GetDesc1()?;
|
||||||
|
if desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 == 0 {
|
||||||
|
tracing::warn!(
|
||||||
|
vendor = format_args!("{:#x}", desc.VendorId),
|
||||||
|
flags = format_args!("{:#x}", desc.Flags),
|
||||||
|
"DXGI did not identify the WARP adapter as software; refusing device"
|
||||||
|
);
|
||||||
|
return Err(windows::core::Error::from_hresult(
|
||||||
|
windows::Win32::Foundation::E_FAIL,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(adapter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn warp_adapter_accepts_only_software() {
|
||||||
|
// This probes DXGI without creating a D3D12 device or running a title.
|
||||||
|
// SAFETY: plain DXGI adapter queries.
|
||||||
|
let raw = unsafe {
|
||||||
|
let Ok(factory) = CreateDXGIFactory2::<IDXGIFactory4>(DXGI_CREATE_FACTORY_FLAGS(0))
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
factory.EnumWarpAdapter::<IDXGIAdapter>()
|
||||||
|
};
|
||||||
|
let Ok(raw) = raw else { return };
|
||||||
|
let desc = unsafe { raw.cast::<IDXGIAdapter1>().unwrap().GetDesc1().unwrap() };
|
||||||
|
eprintln!(
|
||||||
|
"EnumWarpAdapter: vendor={:#x}, flags={:#x}",
|
||||||
|
desc.VendorId, desc.Flags
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
warp_adapter().is_ok(),
|
||||||
|
desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A host command list and its allocator, always used together.
|
/// A host command list and its allocator, always used together.
|
||||||
pub(crate) struct HostList {
|
pub(crate) struct HostList {
|
||||||
allocator: ID3D12CommandAllocator,
|
allocator: ID3D12CommandAllocator,
|
||||||
|
|||||||
Reference in new issue
Block a user