This commit is contained in:
tsuki 2024-10-04 19:13:45 +08:00
parent ea48d236c2
commit 38060a2eaa
5 changed files with 162 additions and 1 deletions

68
Cargo.lock generated
View File

@ -272,6 +272,15 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "ash"
version = "0.37.3+1.3.251"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a"
dependencies = [
"libloading 0.7.4",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.81" version = "0.1.81"
@ -2254,6 +2263,7 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888"
dependencies = [ dependencies = [
"bytemuck",
"cfg-if", "cfg-if",
"crunchy", "crunchy",
] ]
@ -4304,6 +4314,13 @@ dependencies = [
"syn 2.0.75", "syn 2.0.75",
] ]
[[package]]
name = "renderer"
version = "0.1.0"
dependencies = [
"vulkano",
]
[[package]] [[package]]
name = "repr_offset" name = "repr_offset"
version = "0.2.2" version = "0.2.2"
@ -5568,6 +5585,57 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "vk-parse"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81086c28be67a8759cd80cbb3c8f7b520e0874605fc5eb74d5a1c9c2d1878e79"
dependencies = [
"xml-rs 0.8.21",
]
[[package]]
name = "vulkano"
version = "0.34.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70f4278f76307b3c388679234b397b4f90de29cdba53873c26b624ed82653d75"
dependencies = [
"ahash",
"ash",
"bytemuck",
"core-graphics-types",
"crossbeam-queue",
"half",
"heck 0.4.1",
"indexmap",
"libloading 0.8.5",
"objc",
"once_cell",
"parking_lot",
"proc-macro2 1.0.86",
"quote 1.0.37",
"raw-window-handle",
"regex",
"serde",
"serde_json",
"smallvec",
"thread_local",
"vk-parse",
"vulkano-macros",
]
[[package]]
name = "vulkano-macros"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52be622d364272fd77e298e7f68e8547ae66e7687cb86eb85335412cee7e3965"
dependencies = [
"proc-macro-crate 1.3.1",
"proc-macro2 1.0.86",
"quote 1.0.37",
"syn 1.0.109",
]
[[package]] [[package]]
name = "walkdir" name = "walkdir"
version = "2.5.0" version = "2.5.0"

View File

@ -5,5 +5,5 @@ members = [
"geo-macros", "geo-macros",
"radar-g", "radar-g",
"gi", "gi",
"radarg_core", "radarg_core", "renderer",
] ]

11
renderer/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "renderer"
version = "0.1.0"
edition = "2021"
[dependencies]
vulkano = "0.34.1"
[lib]
name = "renderer"

6
renderer/src/lib.rs Normal file
View File

@ -0,0 +1,6 @@
pub mod vulkan;
pub trait Renderer {
}

76
renderer/src/vulkan.rs Normal file
View File

@ -0,0 +1,76 @@
use std::sync::Arc;
use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType};
use vulkano::device::{Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, QueueFlags};
use vulkano::instance::{Instance, InstanceCreateInfo};
use vulkano::VulkanLibrary;
pub struct VulkanRenderer {}
impl VulkanRenderer {
pub fn new() {
let library = VulkanLibrary::new().expect("No Dll");
let instance = Instance::new(library, InstanceCreateInfo::default()).unwrap();
let device_extension = DeviceExtensions {
khr_external_memory: true,
..Default::default()
};
let (device, queue_family_index) =
Self::select_physical_device(&instance, &device_extension);
let (device, mut queues) = Device::new(
device,
DeviceCreateInfo {
queue_create_infos: vec![QueueCreateInfo {
queue_family_index,
..Default::default()
}],
enabled_extensions: device_extension,
..Default::default()
},
).expect("Can not create device");
}
fn select_physical_device(
instance: &Arc<Instance>,
device_extensions: &DeviceExtensions,
) -> (Arc<PhysicalDevice>, u32) {
instance
.enumerate_physical_devices()
.expect("could not enumerate devices")
.filter(|p| p.supported_extensions().contains(&device_extensions))
.filter_map(|p| {
p.queue_family_properties()
.iter()
.enumerate()
// Find the first first queue family that is suitable.
// If none is found, `None` is returned to `filter_map`,
// which disqualifies this physical device.
.position(|(i, q)| q.queue_flags.contains(QueueFlags::GRAPHICS))
.map(|q| (p, q as u32))
})
.min_by_key(|(p, _)| match p.properties().device_type {
PhysicalDeviceType::DiscreteGpu => 0,
PhysicalDeviceType::IntegratedGpu => 1,
PhysicalDeviceType::VirtualGpu => 2,
PhysicalDeviceType::Cpu => 3,
// Note that there exists `PhysicalDeviceType::Other`, however,
// `PhysicalDeviceType` is a non-exhaustive enum. Thus, one should
// match wildcard `_` to catch all unknown device types.
_ => 4,
})
.expect("no device available")
}
}
mod test {
use super::VulkanRenderer;
#[test]
pub fn test() {
VulkanRenderer::new();
}
}