diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs b/src/gallium/frontends/rusticl/mesa/pipe/context.rs index 404bf210de7..c3ddf7653af 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs @@ -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) } } diff --git a/src/gallium/frontends/rusticl/mesa/pipe/query.rs b/src/gallium/frontends/rusticl/mesa/pipe/query.rs index f58c43fc9c1..603f47e5a09 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/query.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/query.rs @@ -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; + + 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 { + 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 + } + } +}