Vulkan WIP
This commit is contained in:
parent
8ef0c4ce59
commit
5e34c37848
|
|
@ -1,3 +1,4 @@
|
|||
/target
|
||||
*~
|
||||
\#*#
|
||||
.#*
|
||||
25
src/geonb.rs
25
src/geonb.rs
|
|
@ -19,7 +19,7 @@ impl std::fmt::Display for Error {
|
|||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
fn convert_err(err: reqwest::Error) -> std::io::Error {
|
||||
fn convert_err(_err: reqwest::Error) -> std::io::Error {
|
||||
todo!()
|
||||
}
|
||||
pub async fn get_lidar_tile_around_point(
|
||||
|
|
@ -86,26 +86,3 @@ pub async fn get_lidar_tile_around_point(
|
|||
.map_err(convert_err),
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn test() -> Result<(), reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
print!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&client
|
||||
.get("https://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_LidarIndex/MapServer/1/query")
|
||||
.query(&[("f", "json"),("geometryType","esriGeometryPoint"),("geometry","2470000,7443000"),("returnIdsOnly","true")])
|
||||
.send()
|
||||
.await?
|
||||
.json::<serde_json::Value>().await?).expect("JSON")
|
||||
);
|
||||
print!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&client
|
||||
.get("https://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_LidarIndex/MapServer/1/14601")
|
||||
.query(&[("f", "json")])
|
||||
.send()
|
||||
.await?
|
||||
.json::<serde_json::Value>().await?).expect("JSON")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
96
src/main.rs
96
src/main.rs
|
|
@ -1,13 +1,7 @@
|
|||
use {
|
||||
ash::{vk, Entry},
|
||||
clap::Parser,
|
||||
geo_types::Point,
|
||||
las::Read as LasRead,
|
||||
proj::Proj,
|
||||
tokio::io::AsyncReadExt,
|
||||
};
|
||||
use {clap::Parser, geo_types::Point, las::Read as LasRead, proj::Proj, tokio::io::AsyncReadExt};
|
||||
|
||||
mod geonb;
|
||||
mod vulkan;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about=None)]
|
||||
|
|
@ -19,91 +13,21 @@ struct Args {
|
|||
// Longitude to fetch LIDAR tile at
|
||||
#[clap(long)]
|
||||
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
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
// Print extra debug info when initializing Vulkan
|
||||
#[clap(long)]
|
||||
debug_init: bool,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), anyhow::Error> {
|
||||
let args = Args::parse();
|
||||
|
||||
init_vulkan();
|
||||
vulkan::init(vulkan::InitOptions {
|
||||
debug_init: args.debug_init,
|
||||
window_width: 1600,
|
||||
window_height: 1200
|
||||
});
|
||||
|
||||
if let (Some(latitude), Some(longitude)) = (args.latitude, args.longitude) {
|
||||
let location = Proj::new_known_crs("+proj=longlat +datum=WGS84", "EPSG:2953", None)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
use ash::{vk, Entry};
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InitOptions {
|
||||
pub window_width: u32,
|
||||
pub window_height: u32,
|
||||
pub debug_init: bool,
|
||||
}
|
||||
|
||||
pub struct Window {}
|
||||
|
||||
fn describe_devices(instance: &ash::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];
|
||||
let heap_index = memory_type.heap_index as usize;
|
||||
let heap = memory_properties.memory_heaps[heap_index];
|
||||
println!("\t\t{:?}", memory_type.property_flags);
|
||||
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
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn create_logical_device(instance: &ash::Instance) {
|
||||
unsafe {
|
||||
instance
|
||||
.enumerate_physical_devices()
|
||||
.expect("vulkan physical devices")
|
||||
.iter().find(|&device|{
|
||||
let device_properties = instance.get_physical_device_properties(device);
|
||||
device_properties.device_type == DISCRETE_GPU
|
||||
}).map(|&device| {
|
||||
vk::DeviceCreateInfo{
|
||||
}
|
||||
|
||||
pub fn init(options: InitOptions) -> Window {
|
||||
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")
|
||||
}
|
||||
};
|
||||
|
||||
if options.debug_init {
|
||||
describe_devices(&instance);
|
||||
}
|
||||
|
||||
Window {}
|
||||
}
|
||||
Loading…
Reference in New Issue