mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 20:51:29 +11:00
75c4b62730
The hub does a little better lifetime tracking of resources (so Rust-side references can be dropped), and in the future will be used for dynamic selection of backend. The migration is still a bit half-baked, as there are a bunch of Vulkan-specific types in the signatures, but it shouldn't be too much work to sort that out. Perhaps it can wait until there is a second backend though. The main motivation for this is to create image objects with lifetime tracking, one of the things required for #38.
41 lines
1.6 KiB
Rust
41 lines
1.6 KiB
Rust
use piet_gpu_hal::hub;
|
|
use piet_gpu_hal::vulkan::VkInstance;
|
|
use piet_gpu_hal::{CmdBuf, MemFlags};
|
|
|
|
fn main() {
|
|
let (instance, _) = VkInstance::new(None).unwrap();
|
|
unsafe {
|
|
let device = instance.device(None).unwrap();
|
|
let session = hub::Session::new(device);
|
|
let mem_flags = MemFlags::host_coherent();
|
|
let src = (0..256).map(|x| x + 1).collect::<Vec<u32>>();
|
|
let mut buffer = session
|
|
.create_buffer(std::mem::size_of_val(&src[..]) as u64, mem_flags)
|
|
.unwrap();
|
|
buffer.write(&src).unwrap();
|
|
let code = include_bytes!("./shader/collatz.spv");
|
|
let pipeline = session.create_simple_compute_pipeline(code, 1, 0).unwrap();
|
|
let descriptor_set = session
|
|
.create_descriptor_set(&pipeline, &[buffer.vk_buffer()], &[])
|
|
.unwrap();
|
|
let query_pool = session.create_query_pool(2).unwrap();
|
|
let mut cmd_buf = session.cmd_buf().unwrap();
|
|
cmd_buf.begin();
|
|
cmd_buf.reset_query_pool(&query_pool);
|
|
cmd_buf.write_timestamp(&query_pool, 0);
|
|
cmd_buf.dispatch(&pipeline, &descriptor_set, (256, 1, 1));
|
|
cmd_buf.write_timestamp(&query_pool, 1);
|
|
cmd_buf.host_barrier();
|
|
cmd_buf.finish();
|
|
let submitted = session.run_cmd_buf(cmd_buf, &[], &[]).unwrap();
|
|
submitted.wait().unwrap();
|
|
let timestamps = session.fetch_query_pool(&query_pool);
|
|
let mut dst: Vec<u32> = Default::default();
|
|
buffer.read(&mut dst).unwrap();
|
|
for (i, val) in dst.iter().enumerate().take(16) {
|
|
println!("{}: {}", i, val);
|
|
}
|
|
println!("{:?}", timestamps);
|
|
}
|
|
}
|