[Mesa-dev] [PATCH v3 3/6] st/clover: provide a path for drivers to call through to pfn_notify

Ilia Mirkin imirkin at alum.mit.edu
Fri Oct 30 22:15:13 PDT 2015


Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 src/gallium/state_trackers/clover/api/context.cpp  |  2 +-
 src/gallium/state_trackers/clover/core/context.cpp | 18 ++++++++++++++++--
 src/gallium/state_trackers/clover/core/context.hpp | 13 ++++++++++++-
 src/gallium/state_trackers/clover/core/queue.cpp   | 20 ++++++++++++++++++++
 4 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp
index 021eea3..d9cbc16 100644
--- a/src/gallium/state_trackers/clover/api/context.cpp
+++ b/src/gallium/state_trackers/clover/api/context.cpp
@@ -46,7 +46,7 @@ clCreateContext(const cl_context_properties *d_props, cl_uint num_devs,
    }
 
    ret_error(r_errcode, CL_SUCCESS);
-   return desc(new context(props, devs));
+   return desc(new context(props, devs, pfn_notify, user_data));
 
 } catch (error &e) {
    ret_error(r_errcode, e);
diff --git a/src/gallium/state_trackers/clover/core/context.cpp b/src/gallium/state_trackers/clover/core/context.cpp
index bf4df39..6e1399b 100644
--- a/src/gallium/state_trackers/clover/core/context.cpp
+++ b/src/gallium/state_trackers/clover/core/context.cpp
@@ -25,8 +25,11 @@
 using namespace clover;
 
 context::context(const property_list &props,
-                 const ref_vector<device> &devs) :
-   props(props), devs(devs) {
+                 const ref_vector<device> &devs,
+                 notify_fn callback_fn,
+                 void *callback_data) :
+   props(props), devs(devs),
+   callback_fn(callback_fn), callback_data(callback_data) {
 }
 
 bool
@@ -48,3 +51,14 @@ context::device_range
 context::devices() const {
    return map(evals(), devs);
 }
+
+void
+context::callback(const char *errinfo, const void *private_info,
+                  size_t cb) const {
+   callback_fn(errinfo, private_info, cb, callback_data);
+}
+
+bool
+context::callback() const {
+   return callback_fn != NULL;
+}
diff --git a/src/gallium/state_trackers/clover/core/context.hpp b/src/gallium/state_trackers/clover/core/context.hpp
index 0ec4ff4..e2903da 100644
--- a/src/gallium/state_trackers/clover/core/context.hpp
+++ b/src/gallium/state_trackers/clover/core/context.hpp
@@ -34,9 +34,12 @@ namespace clover {
             evals, const std::vector<intrusive_ref<device>> &
          > device_range;
       typedef clover::property_list<cl_context_properties> property_list;
+      typedef void (CL_CALLBACK *notify_fn)(const char *, const void *,
+                                            size_t, void *);
 
    public:
-      context(const property_list &props, const ref_vector<device> &devs);
+      context(const property_list &props, const ref_vector<device> &devs,
+              notify_fn callback_fn, void *callback_data);
 
       context(const context &ctx) = delete;
       context &
@@ -53,9 +56,17 @@ namespace clover {
       device_range
       devices() const;
 
+      void
+      callback(const char *, const void *, size_t) const;
+
+      bool
+      callback() const;
+
    private:
       property_list props;
       const std::vector<intrusive_ref<device>> devs;
+      const notify_fn callback_fn;
+      void *callback_data;
    };
 }
 
diff --git a/src/gallium/state_trackers/clover/core/queue.cpp b/src/gallium/state_trackers/clover/core/queue.cpp
index 4aaf67d..2e2da6d 100644
--- a/src/gallium/state_trackers/clover/core/queue.cpp
+++ b/src/gallium/state_trackers/clover/core/queue.cpp
@@ -24,15 +24,35 @@
 #include "core/event.hpp"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
+#include "pipe/p_state.h"
 
 using namespace clover;
 
+void notify_callback(void *data,
+                     unsigned *id,
+                     enum pipe_debug_source source,
+                     enum pipe_debug_type type,
+                     enum pipe_debug_severity severity,
+                     const char *fmt,
+                     va_list args)
+{
+   const command_queue *queue = (const command_queue *)data;
+   char buffer[1024];
+   vsnprintf(buffer, sizeof(buffer), fmt, args);
+   queue->context().callback(buffer, NULL, 0);
+}
+
 command_queue::command_queue(clover::context &ctx, clover::device &dev,
                              cl_command_queue_properties props) :
    context(ctx), device(dev), props(props) {
    pipe = dev.pipe->context_create(dev.pipe, NULL, PIPE_CONTEXT_COMPUTE_ONLY);
    if (!pipe)
       throw error(CL_INVALID_DEVICE);
+   if (ctx.callback()) {
+      struct pipe_debug_info info = { notify_callback, this };
+      if (pipe->set_debug_info)
+         pipe->set_debug_info(pipe, &info);
+   }
 }
 
 command_queue::~command_queue() {
-- 
2.4.10



More information about the mesa-dev mailing list