feat: proper feature and extension list

This commit is contained in:
Ilya Zlobintsev
2022-11-18 21:16:35 +02:00
parent 37cdb8160a
commit 2f626c5b4c
4 changed files with 18 additions and 48 deletions

5
Cargo.lock generated
View File

@@ -1262,9 +1262,8 @@ dependencies = [
[[package]]
name = "vulkano"
version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eecedd057ea4cd85c0e43ba2ad30e599954bd958c50d0f7849439548cfa573ce"
version = "0.32.0"
source = "git+https://github.com/ilya-zlobintsev/vulkano?branch=arr_features#0c1f4f3bfcc94748ffe25512665f796e4bb6302f"
dependencies = [
"ahash",
"ash",

View File

@@ -27,5 +27,5 @@ tokio = { version = "1.21.2", features = [
] }
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
vulkano = "0.32.1"
vulkano = { git = "https://github.com/ilya-zlobintsev/vulkano", branch = "arr_features" }
lact-schema = { path = "../lact-schema" }

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use crate::fork::run_forked;
use lact_schema::VulkanInfo;
use vulkano::{
@@ -5,7 +7,7 @@ use vulkano::{
VulkanLibrary,
};
pub fn get_vulkan_info(vendor_id: &str, device_id: &str) -> anyhow::Result<VulkanInfo> {
pub fn get_vulkan_info<'a>(vendor_id: &'a str, device_id: &'a str) -> anyhow::Result<VulkanInfo> {
let vendor_id = u32::from_str_radix(vendor_id, 16)?;
let device_id = u32::from_str_radix(device_id, 16)?;
@@ -26,8 +28,16 @@ pub fn get_vulkan_info(vendor_id: &str, device_id: &str) -> anyhow::Result<Vulka
device_name: properties.device_name.clone(),
api_version: device.api_version().to_string(),
driver_name: properties.driver_name.clone(),
supported_features: vulkano_struct_to_vec(device.supported_features()),
supported_extensions: vulkano_struct_to_vec(device.supported_extensions()),
supported_features: device
.supported_features()
.as_arr()
.map(|(name, enabled)| (Cow::Borrowed(name), enabled))
.into(),
supported_extensions: device
.supported_extensions()
.as_arr()
.map(|(name, enabled)| (Cow::Borrowed(name), enabled))
.into(),
};
return Ok(info);
}
@@ -37,42 +47,3 @@ pub fn get_vulkan_info(vendor_id: &str, device_id: &str) -> anyhow::Result<Vulka
})
}
}
fn vulkano_struct_to_vec<D: std::fmt::Debug>(data: D) -> Vec<String> {
let output = format!("{data:?}");
let trimmed_output = output.trim_start_matches('[').trim_end_matches(']');
trimmed_output
.split(',')
.map(|s| s.trim().to_owned())
.collect()
}
#[cfg(test)]
mod tests {
use super::vulkano_struct_to_vec;
use vulkano::device::{DeviceExtensions, Features};
#[test]
fn features_to_vec() {
let features = Features {
geometry_shader: true,
tessellation_shader: true,
..Features::empty()
};
let vec = vulkano_struct_to_vec(features);
assert_eq!(vec, vec!["geometryShader", "tessellationShader"]);
}
#[test]
fn extensions_to_vec() {
let extensions = DeviceExtensions {
khr_external_fence: true,
khr_video_queue: true,
..DeviceExtensions::empty()
};
let vec = vulkano_struct_to_vec(extensions);
assert_eq!(vec, vec!["VK_KHR_external_fence", "VK_KHR_video_queue"]);
}
}

View File

@@ -42,8 +42,8 @@ pub struct VulkanInfo {
pub device_name: String,
pub api_version: String,
pub driver_name: Option<String>,
pub supported_features: Vec<String>,
pub supported_extensions: Vec<String>,
pub supported_features: HashMap<Cow<'static, str>, bool>,
pub supported_extensions: HashMap<Cow<'static, str>, bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]