From 6706cc1671bfd8e6c021db8b68815959fa7fceba Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Fri, 30 Oct 2015 23:25:59 -0400 Subject: [PATCH] st/clover: provide a path for drivers to call through to pfn_notify Signed-off-by: Ilia Mirkin [ Francisco Jerez: Clean up clover::context interface by passing around a function object. ] --- .../state_trackers/clover/api/context.cpp | 7 ++++++- .../state_trackers/clover/core/context.cpp | 5 +++-- .../state_trackers/clover/core/context.hpp | 7 ++++++- .../state_trackers/clover/core/queue.cpp | 21 +++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp index 021eea36f6e..c0cd2d32b95 100644 --- a/src/gallium/state_trackers/clover/api/context.cpp +++ b/src/gallium/state_trackers/clover/api/context.cpp @@ -45,8 +45,13 @@ clCreateContext(const cl_context_properties *d_props, cl_uint num_devs, throw error(CL_INVALID_PROPERTY); } + const auto notify = (!pfn_notify ? context::notify_action() : + [=](const char *s) { + pfn_notify(s, NULL, 0, user_data); + }); + ret_error(r_errcode, CL_SUCCESS); - return desc(new context(props, devs)); + return desc(new context(props, devs, notify)); } 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 bf4df39dc2a..c3e20829384 100644 --- a/src/gallium/state_trackers/clover/core/context.cpp +++ b/src/gallium/state_trackers/clover/core/context.cpp @@ -25,8 +25,9 @@ using namespace clover; context::context(const property_list &props, - const ref_vector &devs) : - props(props), devs(devs) { + const ref_vector &devs, + const notify_action ¬ify) : + notify(notify), props(props), devs(devs) { } bool diff --git a/src/gallium/state_trackers/clover/core/context.hpp b/src/gallium/state_trackers/clover/core/context.hpp index 0ec4ff4a231..7b22ccae78f 100644 --- a/src/gallium/state_trackers/clover/core/context.hpp +++ b/src/gallium/state_trackers/clover/core/context.hpp @@ -36,7 +36,10 @@ namespace clover { typedef clover::property_list property_list; public: - context(const property_list &props, const ref_vector &devs); + typedef std::function notify_action; + + context(const property_list &props, const ref_vector &devs, + const notify_action ¬ify); context(const context &ctx) = delete; context & @@ -53,6 +56,8 @@ namespace clover { device_range devices() const; + const notify_action notify; + private: property_list props; const std::vector> devs; diff --git a/src/gallium/state_trackers/clover/core/queue.cpp b/src/gallium/state_trackers/clover/core/queue.cpp index 4aaf67de241..24d71f186e0 100644 --- a/src/gallium/state_trackers/clover/core/queue.cpp +++ b/src/gallium/state_trackers/clover/core/queue.cpp @@ -24,15 +24,36 @@ #include "core/event.hpp" #include "pipe/p_screen.h" #include "pipe/p_context.h" +#include "pipe/p_state.h" using namespace clover; +namespace { + void + debug_notify_callback(void *data, + unsigned *id, + enum pipe_debug_type type, + 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().notify(buffer); + } +} + 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.notify) { + struct pipe_debug_callback cb = { &debug_notify_callback, this }; + if (pipe->set_debug_callback) + pipe->set_debug_callback(pipe, &cb); + } } command_queue::~command_queue() { -- 2.30.2