Skip to content

Commit 760c794

Browse files
committed
fix writing
1 parent 1db3644 commit 760c794

File tree

5 files changed

+89
-67
lines changed

5 files changed

+89
-67
lines changed

README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,73 @@
11
# vkfetch
22

33
this is a rewrite of https://github.com/Wunkolo/vkfetch \
4-
I referenced the code and took some of the ASCII art from it \
4+
I referenced the code and copied the ASCII art from it \
55
thanks to wunkolo for writing the original \
6-
I rewrote it because I wanted to have vkfetch on an easy to access package manager \
7-
I believe we now have feature parity with the original vkfetch
6+
I rewrote it because I wanted to have vkfetch on an easy to access package manager and wanted to extend it \
7+
I believe we now have feature parity with the original vkfetch + some extra info not present in the original
88

9-
# vkfetch-rs
9+
# installation
1010

11-
you need to have vulkanloader installed
12-
on nix that's the `vulkanloader` package
13-
on ubuntu it looks like this:
11+
## dependencies
1412

13+
### nix
14+
15+
```nix
16+
environment.systemPackages = [
17+
pkgs.vulkan-loader
18+
];
19+
```
20+
21+
```sh
22+
nix-shell -p vulkan-loader
23+
```
24+
25+
```sh
26+
nix-env -iA nixos.vulkan-loader
27+
```
28+
29+
### ubuntu
1530

1631
```sh
1732
wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
1833
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-noble.list http://packages.lunarg.com/vulkan/lunarg-vulkan-noble.list
1934
sudo apt update
2035
sudo apt install vulkan-sdk
2136
```
37+
or
38+
```sh
39+
sudo apt update
40+
sudo apt install vulkan-sdk
41+
```
42+
43+
### brew
44+
45+
```sh
46+
brew install vulkan-loader
47+
```
48+
49+
### other distributions
50+
51+
check your own package managers or
52+
53+
https://vulkan.lunarg.com/sdk/home#linux
54+
55+
56+
### windows and mac
57+
58+
https://vulkan.lunarg.com/sdk/home#linux
59+
60+
## vkfetch-rs
61+
2262

2363
```sh
2464
cargo install vkfetch-rs
2565
```
2666

2767
## build it from source
2868

69+
if you use nix then you can use my flake `nix develop`
70+
2971
```sh
3072
git clone https://github.com/float3/vkfetch-rs
3173
cd vkfetch-rs

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
llvmPackages.bintools
2727
rustup
2828
git
29+
rustfmt
2930
vulkan-loader
3031
];
3132

src/device.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::vendor::Vendor;
1010

1111
/// Represents a physical GPU device.
1212
#[derive(Debug)]
13-
pub struct PhysicalDevice {
13+
pub struct Device {
1414
pub vendor: Vendor,
1515
pub device_name: String,
1616
pub device_type: DeviceType,
@@ -53,7 +53,7 @@ pub struct GPUCharacteristics {
5353
pub supports_ray_tracing: bool,
5454
}
5555

56-
impl PhysicalDevice {
56+
impl Device {
5757
/// Constructs a new `PhysicalDevice` by querying Vulkan properties.
5858
pub fn new(instance: &Instance, physical_device: vk::PhysicalDevice) -> Self {
5959
// Get the core properties and limits.
@@ -214,7 +214,7 @@ impl PhysicalDevice {
214214
}
215215
};
216216

217-
PhysicalDevice {
217+
Device {
218218
vendor,
219219
device_name,
220220
device_type,

src/lib.rs

Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod device;
33
pub mod vendor;
44

55
use ash::{self, vk, Entry, Instance};
6-
use device::PhysicalDevice;
6+
use device::Device;
77
use std::error::Error;
88
use vendor::Vendor;
99

@@ -27,14 +27,14 @@ pub fn fetch_device(
2727
.unwrap_or_else(|| panic!("unknown vendor: {}", properties.vendor_id));
2828
let art = vendor.get_ascii_art();
2929

30-
let device = PhysicalDevice::new(instance, device_handle);
30+
let device = Device::new(instance, device_handle);
3131
let info = get_device_info(&device, vendor.get_styles()[0]);
3232

33-
let x = art.get(0).unwrap().len();
34-
let empty = " ".repeat(x);
35-
3633
for i in 0..art.len().max(info.len()) {
37-
let art_line = art.get(i).map(String::as_str).unwrap_or(&empty);
34+
let art_line = art
35+
.get(i)
36+
.map(String::as_str)
37+
.unwrap_or(r#" "#);
3838
let info_line = info.get(i).map(String::as_str).unwrap_or(EMPTY);
3939
println!(" {} {}", art_line, info_line);
4040
}
@@ -46,7 +46,7 @@ pub fn fetch_device(
4646
/// Returns a vector of formatted strings representing the device info,
4747
/// including extra vendor-specific and general device limits.
4848
/// Lines for optional fields are only included if available.
49-
fn get_device_info(device: &PhysicalDevice, color: &str) -> Vec<String> {
49+
fn get_device_info(device: &Device, color: &str) -> Vec<String> {
5050
let mut lines = Vec::new();
5151

5252
let title = format!(
@@ -188,39 +188,18 @@ fn get_device_info(device: &PhysicalDevice, color: &str) -> Vec<String> {
188188
.into()
189189
)
190190
));
191+
192+
let checkbox = |b: bool| if b { "[x]" } else { "[ ]" };
193+
let x = checkbox(device.characteristics.supports_ray_tracing);
194+
let y = checkbox(device.characteristics.dedicated_transfer_queue);
195+
let z = checkbox(device.characteristics.dedicated_async_compute_queue);
196+
191197
lines.push(format!(
192-
"{} | {} | {}",
193-
format!(
194-
"{}{}Raytracing{}: {}",
195-
ALIGNMENT,
196-
color,
197-
RESET,
198-
if device.characteristics.supports_ray_tracing {
199-
"[x]"
200-
} else {
201-
"[ ]"
202-
},
203-
),
204-
format!(
205-
"{}Dedicated Transfer Queue{}: {}",
206-
color,
207-
RESET,
208-
if device.characteristics.supports_ray_tracing {
209-
"[x]"
210-
} else {
211-
"[ ]"
212-
},
213-
),
214-
format!(
215-
"{}Dedicated Async Compute Queue{}: {}",
216-
color,
217-
RESET,
218-
if device.characteristics.supports_ray_tracing {
219-
"[x]"
220-
} else {
221-
"[ ]"
222-
},
223-
),
198+
"{}{}Raytracing{}: {} | {}Dedicated Transfer Queue{}: {} | {}Dedicated Async Compute Queue{}: {}",
199+
ALIGNMENT,
200+
color, RESET, x,
201+
color, RESET, y,
202+
color, RESET, z,
224203
));
225204

226205
lines
@@ -247,7 +226,7 @@ fn format_bytes(bytes: u64) -> String {
247226
}
248227

249228
/// Iterates through API versions and prints info for every physical device
250-
pub fn iterate_devices() {
229+
pub fn iterate_devices() -> Result<(), Box<dyn Error>> {
251230
let entry = {
252231
#[cfg(not(feature = "loaded"))]
253232
{
@@ -259,7 +238,7 @@ pub fn iterate_devices() {
259238
Ok(entry) => entry,
260239
Err(e) => {
261240
eprintln!("Failed to load entry: {:?}", e);
262-
return;
241+
return Ok(());
263242
}
264243
}
265244
}
@@ -277,32 +256,32 @@ pub fn iterate_devices() {
277256
};
278257
let create_info = vk::InstanceCreateInfo::default().application_info(&app_info);
279258

280-
let instance = match unsafe { entry.create_instance(&create_info, None) } {
281-
Ok(instance) => instance,
259+
match unsafe { entry.create_instance(&create_info, None) } {
260+
Ok(instance) => match unsafe { instance.enumerate_physical_devices() } {
261+
Ok(devices) => {
262+
for device in devices {
263+
fetch_device(&instance, device)?;
264+
}
265+
}
266+
Err(e) => {
267+
eprintln!("Failed to enumerate physical devices: {:?}", e);
268+
}
269+
},
282270
Err(e) => {
283271
eprintln!("Failed to create instance: {:?}", e);
284272
continue;
285273
}
286274
};
287275

288-
match unsafe { instance.enumerate_physical_devices() } {
289-
Ok(devices) => {
290-
for device in devices {
291-
fetch_device(&instance, device);
292-
}
293-
}
294-
Err(e) => {
295-
eprintln!("Failed to enumerate physical devices: {:?}", e);
296-
}
297-
}
298276
break;
299277
}
278+
Ok(())
300279
}
301280

302281
#[cfg(test)]
303282
mod tests {
304283
use super::*;
305-
use crate::device::{GPUCharacteristics, PhysicalDevice};
284+
use crate::device::{Device, GPUCharacteristics};
306285
use crate::vendor::Vendor;
307286

308287
/// For testing purposes we use the Unknown vendor variant.
@@ -313,8 +292,8 @@ mod tests {
313292
}
314293

315294
/// Creates a dummy PhysicalDevice instance for tests.
316-
fn dummy_physical_device() -> PhysicalDevice {
317-
PhysicalDevice {
295+
fn dummy_physical_device() -> Device {
296+
Device {
318297
vendor: Vendor::dummy(),
319298
device_name: "TestDevice".to_string(),
320299
device_type: crate::device::DeviceType::DiscreteGPU,

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
// let vendor = vkfetch_rs::vendor::Vendor::AMD;
1414
// debug(vendor.get_ascii_art());
1515

16-
iterate_devices()
16+
iterate_devices().unwrap()
1717
}
1818

1919
// fn debug(x: Vec<String>) {

0 commit comments

Comments
 (0)