Skip to content

Commit 1db3644

Browse files
committed
update
1 parent 3d92c15 commit 1db3644

File tree

5 files changed

+127
-47
lines changed

5 files changed

+127
-47
lines changed

.github/workflows/CI.yaml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,12 @@ jobs:
4848
sudo apt update
4949
sudo apt install vulkan-sdk
5050
51-
- name: Build
52-
run: cargo build --verbose --workspace --all-targets --all-features
53-
54-
- name: Run cargo check
55-
run: cargo check --verbose --workspace --all-targets --all-features
56-
57-
- name: Run Clippy
58-
run: cargo clippy --verbose --workspace --all-targets --all-features -- -D warnings
59-
60-
- name: Check formatting
61-
run: cargo fmt --all -- --check
62-
63-
- name: Run tests
64-
run: cargo test --verbose --workspace --all-targets --all-features --no-fail-fast --lib --bins --examples --tests --benches
65-
66-
- name: Check for uncommitted changes
67-
run: git diff --exit-code
51+
- run: cargo build --verbose --workspace --all-targets --all-features
52+
- run: cargo check --verbose --workspace --all-targets --all-features
53+
- run: cargo clippy --verbose --workspace --all-targets --all-features -- -D warnings
54+
- run: cargo fmt --all -- --check
55+
- run: cargo test --verbose --workspace --all-targets --all-features --no-fail-fast --lib --bins --examples --tests --benches
56+
- run: git diff --exit-code
6857

6958
- name: Generate cargo docs
7059
if: ${{ github.event_name == 'push' && matrix.rust == 'stable' }}

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1+
# vkfetch
2+
13
this is a rewrite of https://github.com/Wunkolo/vkfetch \
24
I referenced the code and took some of the ASCII art from it \
3-
thanks to wunkolo for writing the original, love you buddy \
4-
I rewrote it because I wanted to have vkfetch on an easy to access package manager
5-
6-
# Goals
7-
- [ ] support all the features of the original vkfetch
8-
- [ ] support other gpus/vendors that aren't part of the original vkfetch
9-
- [x] use ANSI escape codes that are compatible with all terminals
10-
- [ ] add as much info as possible
5+
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
118

129
# vkfetch-rs
1310

14-
<!-- you can install this with cargo
11+
you need to have vulkanloader installed
12+
on nix that's the `vulkanloader` package
13+
on ubuntu it looks like this:
14+
15+
16+
```sh
17+
wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
18+
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-noble.list http://packages.lunarg.com/vulkan/lunarg-vulkan-noble.list
19+
sudo apt update
20+
sudo apt install vulkan-sdk
21+
```
1522

1623
```sh
1724
cargo install vkfetch-rs
18-
``` -->
25+
```
1926

20-
## build it from source (you need to have some libraries installed)
27+
## build it from source
2128

2229
```sh
2330
git clone https://github.com/float3/vkfetch-rs
2431
cd vkfetch-rs
2532
cargo build
2633
```
27-
28-
# current progress (comparison with original vkfetch)
29-
30-
![ZO59XD7.png](./Z059XD7.png)

Z059XD7.png

-1.37 MB
Binary file not shown.

src/device.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
use ash::vk;
2+
use ash::vk::PhysicalDeviceProperties2;
3+
use ash::vk::PhysicalDeviceShaderCoreProperties2AMD;
4+
use ash::vk::PhysicalDeviceShaderCorePropertiesAMD;
5+
use ash::vk::PhysicalDeviceShaderSMBuiltinsPropertiesNV;
26
use ash::Instance;
37
use std::ffi::CStr;
48

@@ -39,10 +43,14 @@ pub struct GPUCharacteristics {
3943
// NVIDIA-specific properties.
4044
pub streaming_multiprocessors: Option<u32>,
4145
pub warps_per_sm: Option<u32>,
42-
// General device limits (useful for performance and capability queries).
46+
// General device limits.
4347
pub max_image_dimension_2d: u32,
4448
pub max_compute_shared_memory_size: u32,
4549
pub max_compute_work_group_invocations: u32,
50+
// New feature flags.
51+
pub dedicated_transfer_queue: bool,
52+
pub dedicated_async_compute_queue: bool,
53+
pub supports_ray_tracing: bool,
4654
}
4755

4856
impl PhysicalDevice {
@@ -56,8 +64,8 @@ impl PhysicalDevice {
5664
// Query additional driver properties.
5765
let mut driver_properties: vk::PhysicalDeviceDriverProperties =
5866
vk::PhysicalDeviceDriverProperties::default();
59-
let mut properties2: vk::PhysicalDeviceProperties2 =
60-
vk::PhysicalDeviceProperties2::default().push_next(&mut driver_properties);
67+
let mut properties2: PhysicalDeviceProperties2 =
68+
PhysicalDeviceProperties2::default().push_next(&mut driver_properties);
6169
unsafe {
6270
instance.get_physical_device_properties2(physical_device, &mut properties2);
6371
}
@@ -111,6 +119,37 @@ impl PhysicalDevice {
111119
f32::NAN
112120
};
113121

122+
// Query queue family properties.
123+
let queue_families =
124+
unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
125+
let mut dedicated_transfer_queue = false;
126+
let mut dedicated_async_compute_queue = false;
127+
for qf in queue_families.iter() {
128+
let flags = qf.queue_flags;
129+
if flags.contains(vk::QueueFlags::TRANSFER)
130+
&& !(flags.contains(vk::QueueFlags::GRAPHICS)
131+
|| flags.contains(vk::QueueFlags::COMPUTE))
132+
{
133+
dedicated_transfer_queue = true;
134+
}
135+
if flags.contains(vk::QueueFlags::COMPUTE) && !flags.contains(vk::QueueFlags::GRAPHICS)
136+
{
137+
dedicated_async_compute_queue = true;
138+
}
139+
}
140+
141+
// Check for ray tracing support via device extensions.
142+
let extensions = unsafe {
143+
instance
144+
.enumerate_device_extension_properties(physical_device)
145+
.unwrap_or_default()
146+
};
147+
let supports_ray_tracing = extensions.iter().any(|ext| {
148+
let ext_name = unsafe { CStr::from_ptr(ext.extension_name.as_ptr()) };
149+
ext_name.to_str().unwrap_or("") == "VK_KHR_ray_tracing_pipeline"
150+
|| ext_name.to_str().unwrap_or("") == "VK_NV_ray_tracing"
151+
});
152+
114153
let mut characteristics = GPUCharacteristics {
115154
memory_pressure,
116155
// Vendor-specific fields start as None.
@@ -127,16 +166,18 @@ impl PhysicalDevice {
127166
max_image_dimension_2d: limits.max_image_dimension2_d,
128167
max_compute_shared_memory_size: limits.max_compute_shared_memory_size,
129168
max_compute_work_group_invocations: limits.max_compute_work_group_invocations,
169+
// New features:
170+
dedicated_transfer_queue,
171+
dedicated_async_compute_queue,
172+
supports_ray_tracing,
130173
};
131174

132175
// Query vendor-specific properties.
133176
match vendor {
134177
Vendor::AMD => {
135-
let mut shader_core_properties =
136-
vk::PhysicalDeviceShaderCorePropertiesAMD::default();
137-
let mut shader_core_properties2 =
138-
vk::PhysicalDeviceShaderCoreProperties2AMD::default();
139-
let mut amd_properties2 = vk::PhysicalDeviceProperties2::default()
178+
let mut shader_core_properties = PhysicalDeviceShaderCorePropertiesAMD::default();
179+
let mut shader_core_properties2 = PhysicalDeviceShaderCoreProperties2AMD::default();
180+
let mut amd_properties2 = PhysicalDeviceProperties2::default()
140181
.push_next(&mut shader_core_properties)
141182
.push_next(&mut shader_core_properties2);
142183
unsafe {
@@ -159,9 +200,9 @@ impl PhysicalDevice {
159200
characteristics.wavefront_size = Some(shader_core_properties.wavefront_size);
160201
}
161202
Vendor::Nvidia => {
162-
let mut sm_builtins = vk::PhysicalDeviceShaderSMBuiltinsPropertiesNV::default();
203+
let mut sm_builtins = PhysicalDeviceShaderSMBuiltinsPropertiesNV::default();
163204
let mut nv_properties2 =
164-
vk::PhysicalDeviceProperties2::default().push_next(&mut sm_builtins);
205+
PhysicalDeviceProperties2::default().push_next(&mut sm_builtins);
165206
unsafe {
166207
instance.get_physical_device_properties2(physical_device, &mut nv_properties2);
167208
}
@@ -284,7 +325,6 @@ mod tests {
284325
max_image_dimension2_d: 8192,
285326
max_compute_shared_memory_size: 16384,
286327
max_compute_work_group_invocations: 1024,
287-
// Other fields can use defaults.
288328
..Default::default()
289329
};
290330

@@ -303,6 +343,9 @@ mod tests {
303343
max_image_dimension_2d: limits.max_image_dimension2_d,
304344
max_compute_shared_memory_size: limits.max_compute_shared_memory_size,
305345
max_compute_work_group_invocations: limits.max_compute_work_group_invocations,
346+
dedicated_transfer_queue: false,
347+
dedicated_async_compute_queue: false,
348+
supports_ray_tracing: false,
306349
};
307350

308351
assert_eq!(characteristics.max_image_dimension_2d, 8192);

src/lib.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// lib.rs (or main.rs)
21
pub mod ascii_art;
32
pub mod device;
43
pub mod vendor;
54

65
use ash::{self, vk, Entry, Instance};
76
use device::PhysicalDevice;
7+
use std::error::Error;
88
use vendor::Vendor;
99

1010
const BOLD: &str = "\x1B[1m";
@@ -13,7 +13,10 @@ const ALIGNMENT: &str = " ";
1313
const EMPTY: &str = "";
1414

1515
/// Fetches and prints information for a given physical device.
16-
pub fn fetch_device(instance: &Instance, device_handle: vk::PhysicalDevice) {
16+
pub fn fetch_device(
17+
instance: &Instance,
18+
device_handle: vk::PhysicalDevice,
19+
) -> Result<(), Box<dyn Error>> {
1720
let properties = unsafe { instance.get_physical_device_properties(device_handle) };
1821
let mut properties2 = vk::PhysicalDeviceProperties2::default();
1922
unsafe {
@@ -27,12 +30,17 @@ pub fn fetch_device(instance: &Instance, device_handle: vk::PhysicalDevice) {
2730
let device = PhysicalDevice::new(instance, device_handle);
2831
let info = get_device_info(&device, vendor.get_styles()[0]);
2932

33+
let x = art.get(0).unwrap().len();
34+
let empty = " ".repeat(x);
35+
3036
for i in 0..art.len().max(info.len()) {
31-
let art_line = art.get(i).map(String::as_str).unwrap_or(EMPTY);
37+
let art_line = art.get(i).map(String::as_str).unwrap_or(&empty);
3238
let info_line = info.get(i).map(String::as_str).unwrap_or(EMPTY);
3339
println!(" {} {}", art_line, info_line);
3440
}
41+
3542
println!();
43+
Ok(())
3644
}
3745

3846
/// Returns a vector of formatted strings representing the device info,
@@ -162,7 +170,7 @@ fn get_device_info(device: &PhysicalDevice, color: &str) -> Vec<String> {
162170
// format_bytes(device.characteristics.max_image_dimension_2d.into())
163171
// ));
164172
lines.push(format!(
165-
"{}{}Max Compute Shared Memory Size{}: {} bytes",
173+
"{}{}Max Compute Shared Memory Size{}: {}",
166174
ALIGNMENT,
167175
color,
168176
RESET,
@@ -180,6 +188,40 @@ fn get_device_info(device: &PhysicalDevice, color: &str) -> Vec<String> {
180188
.into()
181189
)
182190
));
191+
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+
),
224+
));
183225

184226
lines
185227
}
@@ -297,6 +339,9 @@ mod tests {
297339
max_image_dimension_2d: 16384,
298340
max_compute_shared_memory_size: 65536,
299341
max_compute_work_group_invocations: 1024,
342+
dedicated_transfer_queue: true,
343+
dedicated_async_compute_queue: true,
344+
supports_ray_tracing: true,
300345
},
301346
}
302347
}

0 commit comments

Comments
 (0)