Skip to content

Commit e56940d

Browse files
committed
better error handling, better VK version handling
1 parent 5e2106d commit e56940d

File tree

6 files changed

+62
-29
lines changed

6 files changed

+62
-29
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
keywords = ["vulkan", "neofetch", "gpu", "fetch"]
66
license = "AGPL-3.0"
77
repository = "https://github.com/float3/vkfetch-rs"
8-
version = "0.0.4"
8+
version = "0.0.5"
99
name = "vkfetch-rs"
1010
categories = ["command-line-utilities"]
1111
readme = "README.md"

lint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env nix-shell
2+
#!nix-shell -i bash -p cargo rustup openimagedenoise
3+
4+
cargo update --workspace
5+
cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features --workspace -- -D warnings
6+
cargo fix --allow-dirty --allow-staged --all-targets --all-features --workspace
7+
cargo fmt --all
8+
cargo check --all-targets --all-features --workspace --release
9+
cargo test --all-targets --all-features --workspace --release
10+
cargo build --all-targets --all-features --workspace --release
11+
cargo run --release

src/device.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ impl PhysicalDevice {
4848

4949
let vendor_id = physical_device_properties.vendor_id;
5050

51-
let vendor = Vendor::from_vendor_id(vendor_id).unwrap();
51+
let vendor = match Vendor::from_vendor_id(vendor_id) {
52+
Some(vendor) => vendor,
53+
None => {
54+
eprintln!("Unknown vendor: {}", vendor_id);
55+
panic!();
56+
}
57+
};
5258

5359
let device_name =
5460
cstring_to_string(physical_device_properties.device_name_as_c_str().unwrap());

src/lib.rs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,47 @@ fn get_device_info(device: PhysicalDevice) -> Vec<String> {
6666
}
6767

6868
pub fn iterate_devices() {
69-
let entry = unsafe { Entry::load().unwrap() };
70-
let appinfo = vk::ApplicationInfo {
71-
api_version: vk::API_VERSION_1_3,
72-
..Default::default()
69+
let entry = match unsafe { Entry::load() } {
70+
Ok(entry) => entry,
71+
Err(e) => {
72+
eprintln!("Failed to load entry: {:?}", e);
73+
return;
74+
}
7375
};
7476

75-
let create_info = vk::InstanceCreateInfo::default().application_info(&appinfo);
76-
let instance = unsafe { entry.create_instance(&create_info, None).unwrap() };
77-
78-
let devices = unsafe { instance.enumerate_physical_devices().unwrap() };
79-
for device in devices {
80-
// let x = unsafe {
81-
// instance
82-
// .enumerate_device_extension_properties(device)
83-
// .unwrap()
84-
// };
85-
// for x in x {
86-
// println!(
87-
// "{:?}",
88-
// x.extension_name_as_c_str()
89-
// .unwrap()
90-
// .to_string_lossy()
91-
// .to_string()
92-
// );
93-
// }
94-
fetch_device(&instance, device);
77+
let versions = [
78+
vk::API_VERSION_1_3,
79+
vk::API_VERSION_1_2,
80+
vk::API_VERSION_1_1,
81+
vk::API_VERSION_1_0,
82+
];
83+
84+
for api_version in versions {
85+
let app_info = vk::ApplicationInfo {
86+
api_version,
87+
..Default::default()
88+
};
89+
let create_info = vk::InstanceCreateInfo::default().application_info(&app_info);
90+
let instance_result = unsafe { entry.create_instance(&create_info, None) };
91+
match instance_result {
92+
Ok(instance) => {
93+
let devices_result = unsafe { instance.enumerate_physical_devices() };
94+
match devices_result {
95+
Ok(devices) => {
96+
devices.into_iter().for_each(|device| {
97+
fetch_device(&instance, device);
98+
});
99+
}
100+
Err(e) => {
101+
eprintln!("Failed to enumerate physical devices: {:?}", e);
102+
}
103+
}
104+
}
105+
Err(e) => {
106+
eprintln!("Failed to create instance: {:?}", e);
107+
continue;
108+
}
109+
}
110+
break;
95111
}
96112
}

src/vendor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Vendor {
2929
Vendor::ARM => ARM,
3030
Vendor::Google => GOOGLE,
3131
Vendor::Intel => INTEL,
32-
Vendor::Mesa => MESA,
32+
Vendor::Mesa => VULKAN,
3333
Vendor::Nvidia => NVIDIA,
3434
Vendor::Unknown => VULKAN,
3535
_ => VULKAN,
@@ -58,7 +58,7 @@ impl Vendor {
5858
Vendor::ARM => ARM_STYLE,
5959
Vendor::Google => GOOGLE_STYLE,
6060
Vendor::Intel => INTEL_STYLE,
61-
Vendor::Mesa => MESA_STYLE,
61+
Vendor::Mesa => VULKAN_STYLE,
6262
Vendor::Nvidia => NVIDIA_STYLE,
6363
Vendor::Unknown => VULKAN_STYLE,
6464
_ => VULKAN_STYLE,

0 commit comments

Comments
 (0)