WIP Initializing Vulkan
This commit is contained in:
parent
c54de32d30
commit
8ef0c4ce59
|
|
@ -32,6 +32,15 @@ version = "1.0.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a99269dff3bc004caa411f38845c20303f1e393ca2bd6581576fa3a7f59577d"
|
checksum = "7a99269dff3bc004caa411f38845c20303f1e393ca2bd6581576fa3a7f59577d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ash"
|
||||||
|
version = "0.36.0+1.3.206"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ceea9c64653169f33f946debf0a41568afc4e23a4c37d29004a23b2ffbfb4034"
|
||||||
|
dependencies = [
|
||||||
|
"libloading",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
|
|
@ -974,6 +983,7 @@ name = "pteropus"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"ash",
|
||||||
"bytes",
|
"bytes",
|
||||||
"clap 3.1.0",
|
"clap 3.1.0",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,4 @@ anyhow = "~1.0"
|
||||||
futures = "~0.3"
|
futures = "~0.3"
|
||||||
bytes = "~1.1"
|
bytes = "~1.1"
|
||||||
las = {version="~0.7", features=["laz"]}
|
las = {version="~0.7", features=["laz"]}
|
||||||
|
ash = {version="~0.36", features=["linked"]}
|
||||||
141
src/main.rs
141
src/main.rs
|
|
@ -1,4 +1,11 @@
|
||||||
use {clap::Parser, geo_types::Point, las::Read as LasRead, proj::Proj, tokio::io::AsyncReadExt};
|
use {
|
||||||
|
ash::{vk, Entry},
|
||||||
|
clap::Parser,
|
||||||
|
geo_types::Point,
|
||||||
|
las::Read as LasRead,
|
||||||
|
proj::Proj,
|
||||||
|
tokio::io::AsyncReadExt,
|
||||||
|
};
|
||||||
|
|
||||||
mod geonb;
|
mod geonb;
|
||||||
|
|
||||||
|
|
@ -7,41 +14,123 @@ mod geonb;
|
||||||
struct Args {
|
struct Args {
|
||||||
// Latitude to fetch LIDAR tile at
|
// Latitude to fetch LIDAR tile at
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
latitude: f64,
|
latitude: Option<f64>,
|
||||||
|
|
||||||
// Longitude to fetch LIDAR tile at
|
// Longitude to fetch LIDAR tile at
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
longitude: f64,
|
longitude: Option<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pretty_print_memory_size(x: u64) -> String {
|
||||||
|
if x > 1_000_000_000 {
|
||||||
|
format!("{:.1}G", x / 1_000_000_000)
|
||||||
|
} else if x > 1_000_000 {
|
||||||
|
format!("{:.0}M", x / 1_000_000)
|
||||||
|
} else if x > 1000 {
|
||||||
|
format!("{:.0}K", x / 1000)
|
||||||
|
} else {
|
||||||
|
format!("{}", x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_vulkan() {
|
||||||
|
let instance = {
|
||||||
|
let entry = Entry::linked();
|
||||||
|
let app_info = vk::ApplicationInfo {
|
||||||
|
api_version: vk::make_api_version(0, 1, 0, 0),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let create_info = vk::InstanceCreateInfo {
|
||||||
|
p_application_info: &app_info,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
unsafe {
|
||||||
|
entry
|
||||||
|
.create_instance(&create_info, None)
|
||||||
|
.expect("vulkan instance")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
instance
|
||||||
|
.enumerate_physical_devices()
|
||||||
|
.expect("vulkan physical devices")
|
||||||
|
.iter()
|
||||||
|
.for_each(|&device| {
|
||||||
|
let device_properties = instance.get_physical_device_properties(device);
|
||||||
|
let api_version = device_properties.api_version;
|
||||||
|
let api_major_version = (api_version >> 22) & 0x7f;
|
||||||
|
let api_minor_version = (api_version >> 12) & 0x3ff;
|
||||||
|
println!(
|
||||||
|
"{}:\n\tAPI Version{}.{}\n\t{:?}",
|
||||||
|
std::ffi::CStr::from_ptr(&device_properties.device_name[0])
|
||||||
|
.to_str()
|
||||||
|
.expect("device name string"),
|
||||||
|
api_major_version,
|
||||||
|
api_minor_version,
|
||||||
|
device_properties.device_type
|
||||||
|
);
|
||||||
|
println!("\tMemory:");
|
||||||
|
let memory_properties = instance.get_physical_device_memory_properties(device);
|
||||||
|
for i in 0..memory_properties.memory_type_count as usize {
|
||||||
|
let memory_type = memory_properties.memory_types[i];
|
||||||
|
println!("\t\t{:?}", memory_type.property_flags);
|
||||||
|
let heap_index = memory_type.heap_index as usize;
|
||||||
|
let heap = memory_properties.memory_heaps[heap_index];
|
||||||
|
println!(
|
||||||
|
"\t\t\t{}: {}\t{:?}",
|
||||||
|
heap_index,
|
||||||
|
pretty_print_memory_size(heap.size),
|
||||||
|
heap.flags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
println!("\tQueues:");
|
||||||
|
instance
|
||||||
|
.get_physical_device_queue_family_properties(device)
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, queue_info)| {
|
||||||
|
println!(
|
||||||
|
"\t\t{}: {:?} ({})",
|
||||||
|
i, queue_info.queue_flags, queue_info.queue_count
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), anyhow::Error> {
|
async fn main() -> Result<(), anyhow::Error> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let location = Proj::new_known_crs("+proj=longlat +datum=WGS84", "EPSG:2953", None)
|
init_vulkan();
|
||||||
.unwrap()
|
|
||||||
.convert(Point::new(args.longitude, args.latitude))
|
if let (Some(latitude), Some(longitude)) = (args.latitude, args.longitude) {
|
||||||
.unwrap();
|
let location = Proj::new_known_crs("+proj=longlat +datum=WGS84", "EPSG:2953", None)
|
||||||
println!("{:?}", location);
|
.unwrap()
|
||||||
let mut las_reader =
|
.convert(Point::new(longitude, latitude))
|
||||||
tokio::io::BufReader::new(geonb::get_lidar_tile_around_point(location).await?);
|
.unwrap();
|
||||||
let mut las_bytes = Vec::new();
|
println!("{:?}", location);
|
||||||
let mut buffer = [0_u8; 4096];
|
let mut las_reader =
|
||||||
let mut byte_count = 0;
|
tokio::io::BufReader::new(geonb::get_lidar_tile_around_point(location).await?);
|
||||||
loop {
|
let mut las_bytes = Vec::new();
|
||||||
let num_bytes = las_reader.read(&mut buffer).await?;
|
let mut buffer = [0_u8; 4096];
|
||||||
if num_bytes == 0 {
|
let mut byte_count = 0;
|
||||||
break;
|
loop {
|
||||||
|
let num_bytes = las_reader.read(&mut buffer).await?;
|
||||||
|
if num_bytes == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
byte_count += num_bytes;
|
||||||
|
print!("{} bytes read\r", byte_count);
|
||||||
|
las_bytes.extend_from_slice(&buffer[0..num_bytes]);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
let mut las_reader = las::Reader::new(std::io::Cursor::new(las_bytes))?;
|
||||||
|
for wrapped_point in las_reader.points().take(10) {
|
||||||
|
let point = wrapped_point.unwrap();
|
||||||
|
println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z);
|
||||||
}
|
}
|
||||||
byte_count += num_bytes;
|
|
||||||
print!("{} bytes read\r", byte_count);
|
|
||||||
las_bytes.extend_from_slice(&buffer[0..num_bytes]);
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
let mut las_reader = las::Reader::new(std::io::Cursor::new(las_bytes))?;
|
|
||||||
for wrapped_point in las_reader.points().take(10) {
|
|
||||||
let point = wrapped_point.unwrap();
|
|
||||||
println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue