Path: blob/21.2-virgl/src/gallium/frontends/clover/api/util.hpp
4572 views
//1// Copyright 2012 Francisco Jerez2//3// Permission is hereby granted, free of charge, to any person obtaining a4// copy of this software and associated documentation files (the "Software"),5// to deal in the Software without restriction, including without limitation6// the rights to use, copy, modify, merge, publish, distribute, sublicense,7// and/or sell copies of the Software, and to permit persons to whom the8// Software is furnished to do so, subject to the following conditions:9//10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19// OTHER DEALINGS IN THE SOFTWARE.20//2122#ifndef CLOVER_API_UTIL_HPP23#define CLOVER_API_UTIL_HPP2425#include <cassert>26#include <iostream>2728#include "core/error.hpp"29#include "core/property.hpp"30#include "util/algorithm.hpp"31#include "util/detect_os.h"3233#if DETECT_OS_WINDOWS34#define CLOVER_API35#define CLOVER_ICD_API36#elif HAVE_CLOVER_ICD37#define CLOVER_API38#define CLOVER_ICD_API PUBLIC39#else40#define CLOVER_API PUBLIC41#define CLOVER_ICD_API PUBLIC42#endif4344#define CLOVER_NOT_SUPPORTED_UNTIL(version) \45do { \46std::cerr << "CL user error: " << __func__ \47<< "() requires OpenCL version " << (version) \48<< " or greater." << std::endl; \49} while (0)5051namespace clover {52///53/// Return an error code in \a p if non-zero.54///55inline void56ret_error(cl_int *p, const clover::error &e) {57if (p)58*p = e.get();59}6061///62/// Return a clover object in \a p if non-zero incrementing the63/// reference count of the object.64///65template<typename T>66void67ret_object(typename T::descriptor_type **p,68const intrusive_ref<T> &v) {69if (p) {70v().retain();71*p = desc(v());72}73}7475///76/// Return an API object from an intrusive reference to a Clover object,77/// incrementing the reference count of the object.78///79template<typename T>80typename T::descriptor_type *81ret_object(const intrusive_ref<T> &v) {82v().retain();83return desc(v());84}85}8687#endif888990