2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3 Copyright (C) 2006 - 2011 Sony Computer Entertainment Inc.
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 //original author: Roman Ponomarev
17 //cleanup by Erwin Coumans
19 #ifndef B3_OPENCL_UTILS_H
20 #define B3_OPENCL_UTILS_H
22 #include "b3OpenCLInclude.h"
29 ///C API for OpenCL utilities: convenience functions, see below for C++ API
31 /// CL Context optionally takes a GL context. This is a generic type because we don't really want this code
32 /// to have to understand GL types. It is a HGLRC in _WIN32 or a GLXContext otherwise.
33 cl_context b3OpenCLUtils_createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx, void* pGLDC, int preferredDeviceIndex, int preferredPlatformIndex, cl_platform_id* platformId);
35 int b3OpenCLUtils_getNumDevices(cl_context cxMainContext);
37 cl_device_id b3OpenCLUtils_getDevice(cl_context cxMainContext, int nr);
39 void b3OpenCLUtils_printDeviceInfo(cl_device_id device);
41 cl_kernel b3OpenCLUtils_compileCLKernelFromString(cl_context clContext, cl_device_id device, const char* kernelSource, const char* kernelName, cl_int* pErrNum, cl_program prog, const char* additionalMacros);
44 cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_device_id device, const char* kernelSource, cl_int* pErrNum, const char* additionalMacros, const char* srcFileNameForCaching, bool disableBinaryCaching);
46 //the following optional APIs provide access using specific platform information
47 int b3OpenCLUtils_getNumPlatforms(cl_int* pErrNum);
49 ///get the nr'th platform, where nr is in the range [0..getNumPlatforms)
50 cl_platform_id b3OpenCLUtils_getPlatform(int nr, cl_int* pErrNum);
52 void b3OpenCLUtils_printPlatformInfo(cl_platform_id platform);
54 const char* b3OpenCLUtils_getSdkVendorName();
56 ///set the path (directory/folder) where the compiled OpenCL kernel are stored
57 void b3OpenCLUtils_setCachePath(const char* path);
59 cl_context b3OpenCLUtils_createContextFromPlatform(cl_platform_id platform, cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx, void* pGLDC, int preferredDeviceIndex, int preferredPlatformIndex);
64 #define B3_MAX_STRING_LENGTH 1024
68 char m_deviceName[B3_MAX_STRING_LENGTH];
69 char m_deviceVendor[B3_MAX_STRING_LENGTH];
70 char m_driverVersion[B3_MAX_STRING_LENGTH];
71 char m_deviceExtensions[B3_MAX_STRING_LENGTH];
73 cl_device_type m_deviceType;
74 cl_uint m_computeUnits;
75 size_t m_workitemDims;
76 size_t m_workItemSize[3];
77 size_t m_image2dMaxWidth;
78 size_t m_image2dMaxHeight;
79 size_t m_image3dMaxWidth;
80 size_t m_image3dMaxHeight;
81 size_t m_image3dMaxDepth;
82 size_t m_workgroupSize;
83 cl_uint m_clockFrequency;
84 cl_ulong m_constantBufferSize;
85 cl_ulong m_localMemSize;
86 cl_ulong m_globalMemSize;
87 cl_bool m_errorCorrectionSupport;
88 cl_device_local_mem_type m_localMemType;
89 cl_uint m_maxReadImageArgs;
90 cl_uint m_maxWriteImageArgs;
92 cl_uint m_addressBits;
93 cl_ulong m_maxMemAllocSize;
94 cl_command_queue_properties m_queueProperties;
95 cl_bool m_imageSupport;
96 cl_uint m_vecWidthChar;
97 cl_uint m_vecWidthShort;
98 cl_uint m_vecWidthInt;
99 cl_uint m_vecWidthLong;
100 cl_uint m_vecWidthFloat;
101 cl_uint m_vecWidthDouble;
103 } b3OpenCLDeviceInfo;
105 struct b3OpenCLPlatformInfo
107 char m_platformVendor[B3_MAX_STRING_LENGTH];
108 char m_platformName[B3_MAX_STRING_LENGTH];
109 char m_platformVersion[B3_MAX_STRING_LENGTH];
111 b3OpenCLPlatformInfo()
113 m_platformVendor[0] = 0;
114 m_platformName[0] = 0;
115 m_platformVersion[0] = 0;
119 ///C++ API for OpenCL utilities: convenience functions
122 /// CL Context optionally takes a GL context. This is a generic type because we don't really want this code
123 /// to have to understand GL types. It is a HGLRC in _WIN32 or a GLXContext otherwise.
124 static inline cl_context createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0, int preferredDeviceIndex = -1, int preferredPlatformIndex = -1, cl_platform_id* platformId = 0)
126 return b3OpenCLUtils_createContextFromType(deviceType, pErrNum, pGLCtx, pGLDC, preferredDeviceIndex, preferredPlatformIndex, platformId);
129 static inline int getNumDevices(cl_context cxMainContext)
131 return b3OpenCLUtils_getNumDevices(cxMainContext);
133 static inline cl_device_id getDevice(cl_context cxMainContext, int nr)
135 return b3OpenCLUtils_getDevice(cxMainContext, nr);
138 static void getDeviceInfo(cl_device_id device, b3OpenCLDeviceInfo* info);
140 static inline void printDeviceInfo(cl_device_id device)
142 b3OpenCLUtils_printDeviceInfo(device);
145 static inline cl_kernel compileCLKernelFromString(cl_context clContext, cl_device_id device, const char* kernelSource, const char* kernelName, cl_int* pErrNum = 0, cl_program prog = 0, const char* additionalMacros = "")
147 return b3OpenCLUtils_compileCLKernelFromString(clContext, device, kernelSource, kernelName, pErrNum, prog, additionalMacros);
151 static inline cl_program compileCLProgramFromString(cl_context clContext, cl_device_id device, const char* kernelSource, cl_int* pErrNum = 0, const char* additionalMacros = "", const char* srcFileNameForCaching = 0, bool disableBinaryCaching = false)
153 return b3OpenCLUtils_compileCLProgramFromString(clContext, device, kernelSource, pErrNum, additionalMacros, srcFileNameForCaching, disableBinaryCaching);
156 //the following optional APIs provide access using specific platform information
157 static inline int getNumPlatforms(cl_int* pErrNum = 0)
159 return b3OpenCLUtils_getNumPlatforms(pErrNum);
161 ///get the nr'th platform, where nr is in the range [0..getNumPlatforms)
162 static inline cl_platform_id getPlatform(int nr, cl_int* pErrNum = 0)
164 return b3OpenCLUtils_getPlatform(nr, pErrNum);
167 static void getPlatformInfo(cl_platform_id platform, b3OpenCLPlatformInfo* platformInfo);
169 static inline void printPlatformInfo(cl_platform_id platform)
171 b3OpenCLUtils_printPlatformInfo(platform);
174 static inline const char* getSdkVendorName()
176 return b3OpenCLUtils_getSdkVendorName();
178 static inline cl_context createContextFromPlatform(cl_platform_id platform, cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0, int preferredDeviceIndex = -1, int preferredPlatformIndex = -1)
180 return b3OpenCLUtils_createContextFromPlatform(platform, deviceType, pErrNum, pGLCtx, pGLDC, preferredDeviceIndex, preferredPlatformIndex);
182 static void setCachePath(const char* path)
184 b3OpenCLUtils_setCachePath(path);
190 #endif // B3_OPENCL_UTILS_H