Module: Mesa
Branch: main
Commit: 4a44dd1654cfcc8a2ef8cd27ac091021f78e3e89
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4a44dd1654cfcc8a2ef8cd27ac091021f78e3e89

Author: Dr. David Alan Gilbert <[email protected]>
Date:   Tue Jul 11 21:34:04 2023 +0100

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 <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24101>

---

 src/gallium/frontends/rusticl/mesa/pipe/context.rs |  9 ++++++++
 src/gallium/frontends/rusticl/mesa/pipe/query.rs   | 25 ++++++++++++++++++++++
 2 files changed, 34 insertions(+)

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<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
+        }
+    }
+}

Reply via email to