fix: revert the modification of vulkan
This commit is contained in:
parent
c53d8c09c4
commit
43d20e2a32
@ -17,7 +17,7 @@ pub fn get_system_info() -> SystemInfo {
|
||||
gpu_map.insert(gpu.uuid.clone(), gpu);
|
||||
}
|
||||
|
||||
let vulkan_gpus = vulkan::get_vulkan_gpus("");
|
||||
let vulkan_gpus = vulkan::get_vulkan_gpus();
|
||||
|
||||
for gpu in vulkan_gpus {
|
||||
match gpu_map.get_mut(&gpu.uuid) {
|
||||
|
||||
@ -23,7 +23,7 @@ fn test_get_vulkan_gpus() {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
#[test]
|
||||
fn test_get_vulkan_gpus_on_desktop() {
|
||||
let gpus = vulkan::get_vulkan_gpus("");
|
||||
let gpus = vulkan::get_vulkan_gpus();
|
||||
|
||||
// Test that function returns without panicking on desktop platforms
|
||||
assert!(gpus.len() >= 0);
|
||||
@ -54,7 +54,7 @@ fn test_get_vulkan_gpus_on_desktop() {
|
||||
#[cfg(target_os = "android")]
|
||||
#[test]
|
||||
fn test_get_vulkan_gpus_on_android() {
|
||||
let gpus = vulkan::get_vulkan_gpus("");
|
||||
let gpus = vulkan::get_vulkan_gpus();
|
||||
|
||||
// Test that function returns without panicking on Android
|
||||
assert!(gpus.len() >= 0);
|
||||
@ -94,7 +94,7 @@ fn test_get_vulkan_gpus_on_android() {
|
||||
#[cfg(target_os = "ios")]
|
||||
#[test]
|
||||
fn test_get_vulkan_gpus_on_ios() {
|
||||
let gpus = vulkan::get_vulkan_gpus("");
|
||||
let gpus = vulkan::get_vulkan_gpus();
|
||||
|
||||
// Note: iOS doesn't support Vulkan natively, so this might return empty
|
||||
// But the function should still work without crashing
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
use crate::types::GpuInfo;
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::types::Vendor;
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use ash::{vk, Entry};
|
||||
use {
|
||||
crate::types::Vendor,
|
||||
vulkano::device::physical::PhysicalDeviceType,
|
||||
vulkano::instance::{Instance, InstanceCreateInfo},
|
||||
vulkano::memory::MemoryHeapFlags,
|
||||
vulkano::VulkanLibrary,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct VulkanInfo {
|
||||
@ -41,17 +44,16 @@ fn parse_uuid(bytes: &[u8; 16]) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_vulkan_gpus(_lib_path: &str) -> Vec<GpuInfo> {
|
||||
pub fn get_vulkan_gpus() -> Vec<GpuInfo> {
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
// On mobile platforms, Vulkan GPU detection is not supported
|
||||
log::info!("Vulkan GPU detection is not supported on mobile platforms");
|
||||
vec![]
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
match get_vulkan_gpus_internal(_lib_path) {
|
||||
match get_vulkan_gpus_internal() {
|
||||
Ok(gpus) => gpus,
|
||||
Err(e) => {
|
||||
log::error!("Failed to get Vulkan GPUs: {:?}", e);
|
||||
@ -62,87 +64,59 @@ pub fn get_vulkan_gpus(_lib_path: &str) -> Vec<GpuInfo> {
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
fn parse_c_string(buf: &[std::ffi::c_char]) -> String {
|
||||
unsafe { std::ffi::CStr::from_ptr(buf.as_ptr()) }
|
||||
.to_str()
|
||||
.unwrap_or_default()
|
||||
.to_string()
|
||||
}
|
||||
fn get_vulkan_gpus_internal() -> Result<Vec<GpuInfo>, Box<dyn std::error::Error>> {
|
||||
let library = VulkanLibrary::new()?;
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
fn get_vulkan_gpus_internal(lib_path: &str) -> Result<Vec<GpuInfo>, Box<dyn std::error::Error>> {
|
||||
let entry = if lib_path.is_empty() {
|
||||
unsafe { Entry::load()? }
|
||||
} else {
|
||||
unsafe { Entry::load_from(lib_path)? }
|
||||
};
|
||||
let app_info = vk::ApplicationInfo {
|
||||
api_version: vk::make_api_version(0, 1, 1, 0),
|
||||
..Default::default()
|
||||
};
|
||||
let create_info = vk::InstanceCreateInfo {
|
||||
p_application_info: &app_info,
|
||||
..Default::default()
|
||||
};
|
||||
let instance = unsafe { entry.create_instance(&create_info, None)? };
|
||||
let instance = Instance::new(
|
||||
library,
|
||||
InstanceCreateInfo {
|
||||
application_name: Some("Jan GPU Detection".into()),
|
||||
application_version: vulkano::Version::V1_1,
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
let mut device_info_list = vec![];
|
||||
|
||||
for (i, device) in unsafe { instance.enumerate_physical_devices()? }
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
// create a chain of properties struct for VkPhysicalDeviceProperties2(3)
|
||||
// https://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDeviceProperties2.html
|
||||
// props2 -> driver_props -> id_props
|
||||
let mut id_props = vk::PhysicalDeviceIDProperties::default();
|
||||
let mut driver_props = vk::PhysicalDeviceDriverProperties {
|
||||
p_next: &mut id_props as *mut _ as *mut std::ffi::c_void,
|
||||
..Default::default()
|
||||
};
|
||||
let mut props2 = vk::PhysicalDeviceProperties2 {
|
||||
p_next: &mut driver_props as *mut _ as *mut std::ffi::c_void,
|
||||
..Default::default()
|
||||
};
|
||||
unsafe {
|
||||
instance.get_physical_device_properties2(*device, &mut props2);
|
||||
}
|
||||
for (i, physical_device) in instance.enumerate_physical_devices()?.enumerate() {
|
||||
let properties = physical_device.properties();
|
||||
|
||||
let props = props2.properties;
|
||||
if props.device_type == vk::PhysicalDeviceType::CPU {
|
||||
if properties.device_type == PhysicalDeviceType::Cpu {
|
||||
continue;
|
||||
}
|
||||
|
||||
let memory_properties = physical_device.memory_properties();
|
||||
let total_memory: u64 = memory_properties
|
||||
.memory_heaps
|
||||
.iter()
|
||||
.filter(|heap| heap.flags.intersects(MemoryHeapFlags::DEVICE_LOCAL))
|
||||
.map(|heap| heap.size / (1024 * 1024))
|
||||
.sum();
|
||||
|
||||
let device_uuid = physical_device.properties().device_uuid.unwrap_or([0; 16]);
|
||||
let driver_version = format!("{}", properties.driver_version);
|
||||
|
||||
let device_info = GpuInfo {
|
||||
name: parse_c_string(&props.device_name),
|
||||
total_memory: unsafe { instance.get_physical_device_memory_properties(*device) }
|
||||
.memory_heaps
|
||||
.iter()
|
||||
.filter(|heap| heap.flags.contains(vk::MemoryHeapFlags::DEVICE_LOCAL))
|
||||
.map(|heap| heap.size / (1024 * 1024))
|
||||
.sum(),
|
||||
vendor: Vendor::from_vendor_id(props.vendor_id),
|
||||
uuid: parse_uuid(&id_props.device_uuid),
|
||||
driver_version: parse_c_string(&driver_props.driver_info),
|
||||
name: properties.device_name.clone(),
|
||||
total_memory,
|
||||
vendor: Vendor::from_vendor_id(properties.vendor_id),
|
||||
uuid: parse_uuid(&device_uuid),
|
||||
driver_version,
|
||||
nvidia_info: None,
|
||||
vulkan_info: Some(VulkanInfo {
|
||||
index: i as u64,
|
||||
device_type: format!("{:?}", props.device_type),
|
||||
device_type: format!("{:?}", properties.device_type),
|
||||
api_version: format!(
|
||||
"{}.{}.{}",
|
||||
vk::api_version_major(props.api_version),
|
||||
vk::api_version_minor(props.api_version),
|
||||
vk::api_version_patch(props.api_version)
|
||||
properties.api_version.major,
|
||||
properties.api_version.minor,
|
||||
properties.api_version.patch
|
||||
),
|
||||
device_id: props.device_id,
|
||||
device_id: properties.device_id,
|
||||
}),
|
||||
};
|
||||
device_info_list.push(device_info);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
instance.destroy_instance(None);
|
||||
}
|
||||
|
||||
Ok(device_info_list)
|
||||
}
|
||||
|
||||
18
yarn.lock
18
yarn.lock
@ -3460,13 +3460,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@jan/extensions-web@link:../extensions-web::locator=%40janhq%2Fweb-app%40workspace%3Aweb-app":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@jan/extensions-web@link:../extensions-web::locator=%40janhq%2Fweb-app%40workspace%3Aweb-app"
|
||||
languageName: node
|
||||
linkType: soft
|
||||
|
||||
"@jan/extensions-web@workspace:extensions-web":
|
||||
"@jan/extensions-web@workspace:*, @jan/extensions-web@workspace:extensions-web":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@jan/extensions-web@workspace:extensions-web"
|
||||
dependencies:
|
||||
@ -3482,12 +3476,6 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@janhq/core@link:../core::locator=%40janhq%2Fweb-app%40workspace%3Aweb-app":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@janhq/core@link:../core::locator=%40janhq%2Fweb-app%40workspace%3Aweb-app"
|
||||
languageName: node
|
||||
linkType: soft
|
||||
|
||||
"@janhq/core@workspace:*, @janhq/core@workspace:core":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@janhq/core@workspace:core"
|
||||
@ -3519,8 +3507,8 @@ __metadata:
|
||||
"@dnd-kit/modifiers": "npm:9.0.0"
|
||||
"@dnd-kit/sortable": "npm:10.0.0"
|
||||
"@eslint/js": "npm:8.57.0"
|
||||
"@jan/extensions-web": "link:../extensions-web"
|
||||
"@janhq/core": "link:../core"
|
||||
"@jan/extensions-web": "workspace:*"
|
||||
"@janhq/core": "workspace:*"
|
||||
"@radix-ui/react-accordion": "npm:1.2.11"
|
||||
"@radix-ui/react-avatar": "npm:1.1.10"
|
||||
"@radix-ui/react-dialog": "npm:1.1.15"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user