mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 17:30:20 +01:00
rusticl: Wrap pipe query reads
Take a query we previously created and read it's result. The type of the result is usually implicitly known; for now just handle the query we use in 64 bit. This is safe because the trait bindings ensure that when we create a query with PipeQueryGen we embed the type of the result in the PipeQuery, and that produces the correct result type. Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24101>
This commit is contained in:
parent
52e53938c3
commit
4a44dd1654
2 changed files with 34 additions and 0 deletions
|
|
@ -529,6 +529,15 @@ impl PipeContext {
|
|||
unsafe { self.pipe.as_ref().end_query.unwrap()(self.pipe.as_ptr(), pq) }
|
||||
}
|
||||
|
||||
pub fn get_query_result(
|
||||
&self,
|
||||
pq: *mut pipe_query,
|
||||
wait: bool,
|
||||
pqr: *mut pipe_query_result,
|
||||
) -> bool {
|
||||
unsafe { self.pipe.as_ref().get_query_result.unwrap()(self.pipe.as_ptr(), pq, wait, pqr) }
|
||||
}
|
||||
|
||||
pub fn destroy_query(&self, pq: *mut pipe_query) {
|
||||
unsafe { self.pipe.as_ref().destroy_query.unwrap()(self.pipe.as_ptr(), pq) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,3 +63,28 @@ impl<'a, R> Drop for PipeQuery<'a, R> {
|
|||
self.ctx.destroy_query(self.query);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait QueryReadTrait {
|
||||
type ResType;
|
||||
fn read(&mut self, wait: bool) -> Option<Self::ResType>;
|
||||
|
||||
fn read_blocked(&mut self) -> Self::ResType {
|
||||
self.read(true).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl QueryReadTrait for PipeQuery<'_, u64> {
|
||||
type ResType = u64;
|
||||
|
||||
fn read(&mut self, wait: bool) -> Option<u64> {
|
||||
let mut raw_result = pipe_query_result::default();
|
||||
if self.ctx.get_query_result(self.query, wait, &mut raw_result) {
|
||||
// SAFETY: We know this is the right type
|
||||
// because of the trait bound on PipeQueryGen binds the
|
||||
// query type with the result type.
|
||||
Some(unsafe { raw_result.u64_ })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue