Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContextDesc::device_id to force adapter selection #210

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
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
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 @@
timing: false,
capture: false,
overlay: true,
device_id: 0,
})
.unwrap()
};
Expand Down Expand Up @@ -365,7 +366,7 @@
let window_attributes =
winit::window::Window::default_attributes().with_title("blade-bunnymark");

let window = event_loop.create_window(window_attributes).unwrap();

Check warning on line 369 in examples/bunnymark/main.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

use of deprecated method `winit::event_loop::EventLoop::<T>::create_window`: use `ActiveEventLoop::create_window` instead

#[cfg(target_arch = "wasm32")]
{
Expand Down Expand Up @@ -394,7 +395,7 @@
let mut frame_count = 0;

event_loop
.run(|event, target| {

Check warning on line 398 in examples/bunnymark/main.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

use of deprecated method `winit::event_loop::EventLoop::<T>::run`: use `EventLoop::run_app` instead
target.set_control_flow(winit::event_loop::ControlFlow::Poll);
match event {
winit::event::Event::AboutToWait => {
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 @@
validation: cfg!(debug_assertions),
timing: true,
capture: true,
overlay: false,
..Default::default()
})
.unwrap()
};
Expand Down Expand Up @@ -141,7 +141,7 @@
let window_attributes =
winit::window::Window::default_attributes().with_title("blade-particle");

let window = event_loop.create_window(window_attributes).unwrap();

Check warning on line 144 in examples/particle/main.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

use of deprecated method `winit::event_loop::EventLoop::<T>::create_window`: use `ActiveEventLoop::create_window` instead

Check warning on line 144 in examples/particle/main.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

use of deprecated method `winit::event_loop::EventLoop::<T>::create_window`: use `ActiveEventLoop::create_window` instead

let egui_ctx = egui::Context::default();
let viewport_id = egui_ctx.viewport_id();
Expand All @@ -150,7 +150,7 @@
let mut example = Example::new(&window);

event_loop
.run(|event, target| {

Check warning on line 153 in examples/particle/main.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

use of deprecated method `winit::event_loop::EventLoop::<T>::run`: use `EventLoop::run_app` instead

Check warning on line 153 in examples/particle/main.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

use of deprecated method `winit::event_loop::EventLoop::<T>::run`: use `EventLoop::run_app` instead
target.set_control_flow(winit::event_loop::ControlFlow::Poll);
match event {
winit::event::Event::AboutToWait => {
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
Loading