diff options
author | Francisco Jerez <[email protected]> | 2013-09-16 21:13:47 -0700 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2013-10-21 10:47:03 -0700 |
commit | e5fc61fa3f4ef7e00d66003b7f0298f7e20b2cc3 (patch) | |
tree | 68c8a777b0e8ca499306ee76a333e553ef34764e /src/gallium/state_trackers/clover/core | |
parent | 04d0ab9f6456229df1a83b0b1c133e1c458aedd2 (diff) |
clover: Add property list helpers with a syntax consistent with other API objects.
Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/core')
-rw-r--r-- | src/gallium/state_trackers/clover/core/context.cpp | 7 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/context.hpp | 15 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/property.hpp | 68 |
3 files changed, 83 insertions, 7 deletions
diff --git a/src/gallium/state_trackers/clover/core/context.cpp b/src/gallium/state_trackers/clover/core/context.cpp index 7293f9406f2..7b79f82547e 100644 --- a/src/gallium/state_trackers/clover/core/context.cpp +++ b/src/gallium/state_trackers/clover/core/context.cpp @@ -26,7 +26,7 @@ using namespace clover; -context::context(const std::vector<cl_context_properties> &props, +context::context(const property_list &props, const ref_vector<device> &devs) : devs(map(addresses(), devs)), _props(props) { } @@ -35,3 +35,8 @@ bool context::has_device(device &dev) const { return std::count(devs.begin(), devs.end(), &dev); } + +const context::property_list & +context::props() const { + return _props; +} diff --git a/src/gallium/state_trackers/clover/core/context.hpp b/src/gallium/state_trackers/clover/core/context.hpp index 7ef3db9b9d3..6fda06155ea 100644 --- a/src/gallium/state_trackers/clover/core/context.hpp +++ b/src/gallium/state_trackers/clover/core/context.hpp @@ -25,24 +25,27 @@ #include "core/object.hpp" #include "core/device.hpp" +#include "core/property.hpp" namespace clover { class context : public ref_counter, public _cl_context { + private: + typedef clover::property_list<cl_context_properties> property_list; + public: - context(const std::vector<cl_context_properties> &props, - const ref_vector<device> &devs); + context(const property_list &props, const ref_vector<device> &devs); + context(const context &ctx) = delete; bool has_device(device &dev) const; - const std::vector<cl_context_properties> &props() const { - return _props; - } + const property_list & + props() const; const std::vector<device *> devs; private: - std::vector<cl_context_properties> _props; + property_list _props; }; } diff --git a/src/gallium/state_trackers/clover/core/property.hpp b/src/gallium/state_trackers/clover/core/property.hpp index f2e5f2bcd6d..7f8e17684d9 100644 --- a/src/gallium/state_trackers/clover/core/property.hpp +++ b/src/gallium/state_trackers/clover/core/property.hpp @@ -188,6 +188,74 @@ namespace clover { return *this; } }; + + template<typename T> + class property_element { + public: + property_element() : x() { + } + + property_element(T x) : x(x) { + } + + template<typename S> + S + as() const { + assert(sizeof(S) <= sizeof(T)); + return reinterpret_cast<S>(x); + } + + private: + T x; + }; + + template<typename D> + using property_list = std::map<D, property_element<D>>; + + struct property_list_tag; + + /// + /// Create a clover::property_list object from a zero-terminated + /// CL property list. + /// + template<typename T, typename D, + typename = typename std::enable_if< + std::is_same<T, property_list_tag>::value>::type> + property_list<D> + obj(const D *d_props) { + property_list<D> props; + + while (d_props && *d_props) { + auto key = *d_props++; + auto value = *d_props++; + + if (props.count(key)) + throw error(CL_INVALID_PROPERTY); + + props.insert({ key, value }); + } + + return props; + } + + /// + /// Create a zero-terminated CL property list from a + /// clover::property_list object. + /// + template<typename D> + std::vector<D> + desc(const property_list<D> &props) { + std::vector<D> d_props; + + for (auto &prop : props) { + d_props.push_back(prop.first); + d_props.push_back(prop.second.template as<D>()); + } + + d_props.push_back(0); + + return d_props; + } } #endif |