diff --git a/blade-graphics/src/lib.rs b/blade-graphics/src/lib.rs index d8470a1..b85baf6 100644 --- a/blade-graphics/src/lib.rs +++ b/blade-graphics/src/lib.rs @@ -104,6 +104,8 @@ pub struct ContextDesc { pub capture: bool, /// Enable GAPI overlay. pub overlay: bool, + /// Force selection of a specific Device ID, unless 0. + pub device_id: u32, } #[derive(Debug)] diff --git a/blade-graphics/src/metal/mod.rs b/blade-graphics/src/metal/mod.rs index f14df22..94dc58e 100644 --- a/blade-graphics/src/metal/mod.rs +++ b/blade-graphics/src/metal/mod.rs @@ -418,6 +418,9 @@ impl Context { if desc.overlay { std::env::set_var("MTL_HUD_ENABLED", "1"); } + if desc.device_id != 0 { + log::warn!("Unable to filter devices by ID"); + } let device = metal::Device::system_default() .ok_or(super::NotSupportedError::NoSupportedDeviceFound)?; diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 95d564e..442af24 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -89,6 +89,11 @@ unsafe fn inspect_adapter( let name = ffi::CStr::from_ptr(properties.device_name.as_ptr()); log::info!("Adapter: {:?}", name); + if desc.device_id != 0 && desc.device_id != properties.device_id { + log::info!("Rejected device ID 0x{:X}", properties.device_id); + return None; + } + let api_version = properties.api_version.min(driver_api_version); if api_version < vk::API_VERSION_1_1 { log::warn!("\tRejected for API version {}", api_version); diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f295d16..d1e6aa3 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,7 @@ Changelog for Blade - every pass now takes a label - automatic GPU pass markers - ability to capture pass GPU timings + - ability to force the use of a specific GPU - Metal: - support for workgroup memory - concurrent compute dispatches diff --git a/examples/bunnymark/main.rs b/examples/bunnymark/main.rs index b14c2fe..b9e8d32 100644 --- a/examples/bunnymark/main.rs +++ b/examples/bunnymark/main.rs @@ -83,6 +83,7 @@ impl Example { timing: false, capture: false, overlay: true, + device_id: 0, }) .unwrap() }; diff --git a/examples/particle/main.rs b/examples/particle/main.rs index e836f82..e6a24c7 100644 --- a/examples/particle/main.rs +++ b/examples/particle/main.rs @@ -22,7 +22,7 @@ impl Example { validation: cfg!(debug_assertions), timing: true, capture: true, - overlay: false, + ..Default::default() }) .unwrap() }; diff --git a/src/lib.rs b/src/lib.rs index 3ae92c3..2f754a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -418,6 +418,7 @@ impl Engine { timing: true, capture: false, overlay: false, + device_id: 0, }) .unwrap() });