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