mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 20:51:29 +11:00
74f2b4fd1c
Use an array of bindtypes rather than the previous situation, which was a choice of buffer counts, or a heavier builder pattern. The main thing this unlocks is distinguishing between readonly and read/write buffers, which is important for DX12. This is WIP, the Metal part hasn't been done, and the old stuff not deleted. Part of #125
38 lines
1.7 KiB
Rust
38 lines
1.7 KiB
Rust
use piet_gpu_hal::{BindType, include_shader};
|
|
use piet_gpu_hal::{BufferUsage, Instance, InstanceFlags, Session};
|
|
|
|
fn main() {
|
|
let (instance, _) = Instance::new(None, InstanceFlags::empty()).unwrap();
|
|
unsafe {
|
|
let device = instance.device(None).unwrap();
|
|
let session = Session::new(device);
|
|
let usage = BufferUsage::MAP_READ | BufferUsage::STORAGE;
|
|
let src = (0..256).map(|x| x + 1).collect::<Vec<u32>>();
|
|
let buffer = session.create_buffer_init(&src, usage).unwrap();
|
|
let code = include_shader!(&session, "./shader/gen/collatz");
|
|
let pipeline = session.create_compute_pipeline(code, &[BindType::Buffer]).unwrap();
|
|
let descriptor_set = session
|
|
.create_simple_descriptor_set(&pipeline, &[&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), (1, 1, 1));
|
|
cmd_buf.write_timestamp(&query_pool, 1);
|
|
cmd_buf.finish_timestamps(&query_pool);
|
|
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);
|
|
}
|
|
}
|