From 3a07502ebe834c8ef63736f0457d891905f7d3e6 Mon Sep 17 00:00:00 2001 From: Dmitry Zolotukhin Date: Sun, 28 Jan 2024 20:46:01 +0100 Subject: [PATCH] Debug device name checks. --- src/correlation/vk.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/correlation/vk.rs b/src/correlation/vk.rs index ed81ce7..e3ffc7c 100644 --- a/src/correlation/vk.rs +++ b/src/correlation/vk.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, error, ffi::CStr, fmt, slice, time::SystemTime}; +use std::{cmp::Ordering, collections::HashMap, error, ffi::CStr, fmt, slice, time::SystemTime}; use ash::{prelude::VkResult, vk}; use nalgebra::Matrix3; @@ -906,7 +906,7 @@ impl Device { unsafe fn find_device( instance: &ash::Instance, max_buffer_size: usize, - ) -> Result<(vk::PhysicalDevice, &'static str, u32), Box> { + ) -> Result<(vk::PhysicalDevice, String, u32), Box> { let devices = instance.enumerate_physical_devices()?; let device = devices .iter() @@ -922,8 +922,8 @@ impl Device { } let queue_index = Device::find_compute_queue(instance, device)?; - let device_name = CStr::from_ptr(props.device_name.as_ptr()); - let device_name = device_name.to_str().unwrap(); + let device_name = CStr::from_ptr(props.device_name.as_ptr()).to_str().unwrap(); + let device_name = String::from(device_name); println!( "Device {} type {} {}-{}-{}-{}", device_name, @@ -941,24 +941,28 @@ impl Device { _ => 0, }; // Prefer real devices instead of dzn emulation. - let dzn_multiplier = if device_name + let is_dzn = device_name .to_lowercase() - .starts_with("microsoft direct3d12") - { - 1 - } else { - 10 - }; - Some((device, device_name, queue_index, score * dzn_multiplier)) + .starts_with("microsoft direct3d12"); + println!("Device score is {} {}", score, is_dzn); + let score = (score, is_dzn); + Some((device, device_name, queue_index, score)) }) - .max_by_key(|(_device, _name, _queue_index, score)| *score); - let (device, name, queue_index) = if let Some((device, name, queue_index, _score)) = device - { + .max_by(|(_, _, _, a), (_, _, _, b)| { + if a.1 && !b.1 { + return Ordering::Less; + } else if !a.1 && b.1 { + return Ordering::Greater; + } + return a.0.cmp(&b.0); + }); + let (device, name, queue_index) = if let Some((device, name, queue_index, score)) = device { + println!("Score= {:?}, {};", score, name); (device, name, queue_index) } else { return Err(GpuError::new("Device not found").into()); }; - println!("selected device {}", name); + println!("selected device {} -", name); Ok((device, name, queue_index)) }