@@ -3,7 +3,7 @@ pub mod device;
33pub mod vendor;
44
55use ash:: { self , vk, Entry , Instance } ;
6- use device:: PhysicalDevice ;
6+ use device:: Device ;
77use std:: error:: Error ;
88use 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) ]
303282mod 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 ,
0 commit comments