Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions crates/victory-shader/src/emit/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ fn err(e: windows::core::Error) -> String {
e.message().to_string()
}

/// The first adapter that is a GPU: not flagged software, and with video
/// memory of its own. A machine without one (GitHub's Windows runner has only
/// `Microsoft Basic Render Driver`) has nothing to run the hardware-only
/// checks on, and CI proved that the flag of adapter 0 alone is not enough:
/// the runner's default adapter is not flagged software and its device still
/// refuses a wave of 32
/// (`permutes_read_the_lane_named_and_zero_from_lanes_left_out`). WARP and the
/// basic render driver report no dedicated video memory, which is what this
/// asks for as well.
fn hardware_adapter(factory: &IDXGIFactory4) -> windows::core::Result<IDXGIAdapter1> {
// SAFETY: plain DXGI adapter enumeration.
unsafe {
for index in 0.. {
let Ok(adapter) = factory.EnumAdapters1(index) else {
break;
};
let desc = adapter.GetDesc1()?;
let software = desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0;
if !software && desc.DedicatedVideoMemory > 0 {
return Ok(adapter);
}
}
}
Err(windows::core::Error::new(
windows::Win32::Foundation::E_FAIL,
"no hardware adapter",
))
}

impl Host {
/// The default adapter, or WARP with `warp` (or `VICTORY_WARP=1`).
/// A software default adapter (a machine without a GPU, as CI) is
Expand All @@ -76,12 +105,7 @@ impl Host {
let adapter: IDXGIAdapter1 = if warp {
factory.EnumWarpAdapter().map_err(err)?
} else {
let adapter = factory.EnumAdapters1(0).map_err(err)?;
if adapter.GetDesc1().map_err(err)?.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0
{
return Err("no hardware adapter".into());
}
adapter
hardware_adapter(&factory).map_err(err)?
};
D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device).map_err(err)?;
let device = device.ok_or("no device")?;
Expand Down