renderer
This commit is contained in:
parent
ea48d236c2
commit
38060a2eaa
68
Cargo.lock
generated
68
Cargo.lock
generated
@ -272,6 +272,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "async-trait"
|
||||
version = "0.1.81"
|
||||
@ -2254,6 +2263,7 @@ version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"cfg-if",
|
||||
"crunchy",
|
||||
]
|
||||
@ -4304,6 +4314,13 @@ dependencies = [
|
||||
"syn 2.0.75",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "renderer"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"vulkano",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "repr_offset"
|
||||
version = "0.2.2"
|
||||
@ -5568,6 +5585,57 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
|
||||
@ -5,5 +5,5 @@ members = [
|
||||
"geo-macros",
|
||||
"radar-g",
|
||||
"gi",
|
||||
"radarg_core",
|
||||
"radarg_core", "renderer",
|
||||
]
|
||||
|
||||
11
renderer/Cargo.toml
Normal file
11
renderer/Cargo.toml
Normal 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
6
renderer/src/lib.rs
Normal file
@ -0,0 +1,6 @@
|
||||
pub mod vulkan;
|
||||
|
||||
|
||||
pub trait Renderer {
|
||||
|
||||
}
|
||||
76
renderer/src/vulkan.rs
Normal file
76
renderer/src/vulkan.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user