diff --git a/Cargo.lock b/Cargo.lock index f19cf3c..5f9b877 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,6 +114,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "once_cell" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" + [[package]] name = "piet" version = "0.0.12" @@ -149,6 +155,7 @@ name = "piet-gpu-hal" version = "0.1.0" dependencies = [ "ash", + "once_cell", ] [[package]] diff --git a/piet-gpu-hal/examples/collatz.rs b/piet-gpu-hal/examples/collatz.rs index 7195891..a4777b4 100644 --- a/piet-gpu-hal/examples/collatz.rs +++ b/piet-gpu-hal/examples/collatz.rs @@ -17,6 +17,7 @@ fn main() { let query_pool = device.create_query_pool(2).unwrap(); let mut cmd_buf = device.create_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); diff --git a/piet-gpu-hal/src/lib.rs b/piet-gpu-hal/src/lib.rs index 77170c0..d215490 100644 --- a/piet-gpu-hal/src/lib.rs +++ b/piet-gpu-hal/src/lib.rs @@ -80,6 +80,13 @@ pub trait CmdBuf { unsafe fn copy_buffer(&self, src: &D::Buffer, dst: &D::Buffer); + /// Reset the query pool. + /// + /// The query pool must be reset before each use, to avoid validation errors. + /// This is annoying, and we could tweak the API to make it implicit, doing + /// the reset before the first timestamp write. + unsafe fn reset_query_pool(&mut self, pool: &D::QueryPool); + unsafe fn write_timestamp(&mut self, pool: &D::QueryPool, query: u32); } diff --git a/piet-gpu-hal/src/vulkan.rs b/piet-gpu-hal/src/vulkan.rs index 587f0a6..f5d8c19 100644 --- a/piet-gpu-hal/src/vulkan.rs +++ b/piet-gpu-hal/src/vulkan.rs @@ -573,6 +573,16 @@ impl crate::CmdBuf for CmdBuf { ); } + unsafe fn reset_query_pool(&mut self, pool: &QueryPool) { + let device = &self.device.device; + device.cmd_reset_query_pool( + self.cmd_buf, + pool.pool, + 0, + pool.n_queries, + ); + } + unsafe fn write_timestamp(&mut self, pool: &QueryPool, query: u32) { let device = &self.device.device; device.cmd_write_timestamp( diff --git a/piet-gpu/src/main.rs b/piet-gpu/src/main.rs index 949ccc2..9f4f25f 100644 --- a/piet-gpu/src/main.rs +++ b/piet-gpu/src/main.rs @@ -181,6 +181,7 @@ fn main() { cmd_buf.clear_buffer(&tilegroup_buf); cmd_buf.clear_buffer(&ptcl_buf); cmd_buf.memory_barrier(); + cmd_buf.reset_query_pool(&query_pool); cmd_buf.write_timestamp(&query_pool, 0); cmd_buf.dispatch( &k1_pipeline,