Skip to content

Commit

Permalink
Add ContextDesc::device_id to force adapter selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Nov 30, 2024
1 parent 4ddcef9 commit edef58c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
5 changes: 5 additions & 0 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl Example {
timing: false,
capture: false,
overlay: true,
device_id: 0,
})
.unwrap()
};
Expand Down
2 changes: 1 addition & 1 deletion examples/particle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Example {
validation: cfg!(debug_assertions),
timing: true,
capture: true,
overlay: false,
.. Default::default()
})
.unwrap()
};
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ impl Engine {
timing: true,
capture: false,
overlay: false,
device_id: 0,
})
.unwrap()
});
Expand Down

0 comments on commit edef58c

Please sign in to comment.