Tizen 2.1 base
[platform/upstream/libbullet.git] / Demos / SharedOpenCL / btOpenCLUtils.h
1 /*\r
2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org\r
3 Copyright (C) 2006 - 2011 Sony Computer Entertainment Inc. \r
4 \r
5 This software is provided 'as-is', without any express or implied warranty.\r
6 In no event will the authors be held liable for any damages arising from the use of this software.\r
7 Permission is granted to anyone to use this software for any purpose, \r
8 including commercial applications, and to alter it and redistribute it freely, \r
9 subject to the following restrictions:\r
10 \r
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.\r
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\r
13 3. This notice may not be removed or altered from any source distribution.\r
14 */\r
15 \r
16 //original author: Roman Ponomarev\r
17 //cleanup by Erwin Coumans\r
18 \r
19 #ifndef BT_OPENCL_UTILS_H\r
20 #define BT_OPENCL_UTILS_H\r
21 \r
22 #include "btOpenCLInclude.h"\r
23 \r
24 \r
25 #define BT_MAX_STRING_LENGTH 1024\r
26 \r
27 struct btOpenCLDeviceInfo\r
28 {\r
29         char m_deviceName[BT_MAX_STRING_LENGTH];\r
30         char m_deviceVendor[BT_MAX_STRING_LENGTH];\r
31         char m_driverVersion[BT_MAX_STRING_LENGTH];\r
32         char m_deviceExtensions[BT_MAX_STRING_LENGTH];\r
33 \r
34         cl_device_type          m_deviceType;\r
35         cl_uint                                 m_computeUnits;\r
36         size_t                                  m_workitemDims;\r
37         size_t                                  m_workItemSize[3];\r
38         size_t                                  m_image2dMaxWidth;\r
39         size_t                                  m_image2dMaxHeight;\r
40         size_t                                  m_image3dMaxWidth;\r
41         size_t                                  m_image3dMaxHeight;\r
42         size_t                                  m_image3dMaxDepth;\r
43         size_t                                  m_workgroupSize;\r
44         cl_uint                                 m_clockFrequency;\r
45         cl_ulong                                m_constantBufferSize;\r
46         cl_ulong                                m_localMemSize;\r
47         cl_ulong                                m_globalMemSize;\r
48     cl_bool                                     m_errorCorrectionSupport;\r
49         cl_device_local_mem_type m_localMemType;\r
50         cl_uint                                 m_maxReadImageArgs;\r
51         cl_uint                                 m_maxWriteImageArgs;\r
52 \r
53 \r
54 \r
55         cl_uint                                 m_addressBits;\r
56         cl_ulong                                m_maxMemAllocSize;\r
57         cl_command_queue_properties m_queueProperties;\r
58         cl_bool                                 m_imageSupport;\r
59         cl_uint                                 m_vecWidthChar;\r
60         cl_uint                                 m_vecWidthShort;\r
61         cl_uint                                 m_vecWidthInt;\r
62         cl_uint                                 m_vecWidthLong;\r
63         cl_uint                                 m_vecWidthFloat;\r
64         cl_uint                                 m_vecWidthDouble;\r
65 \r
66 };\r
67 \r
68 struct btOpenCLPlatformInfo\r
69 {\r
70         char m_platformVendor[BT_MAX_STRING_LENGTH];\r
71         char m_platformName[BT_MAX_STRING_LENGTH];\r
72         char m_platformVersion[BT_MAX_STRING_LENGTH];\r
73 };\r
74 \r
75 class btOpenCLUtils\r
76 {\r
77 public:\r
78 \r
79         /// CL Context optionally takes a GL context. This is a generic type because we don't really want this code\r
80         /// to have to understand GL types. It is a HGLRC in _WIN32 or a GLXContext otherwise.\r
81         static cl_context       createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0, int preferredDeviceIndex = -1, int preferredPlatformIndex= - 1);\r
82         \r
83         static int getNumDevices(cl_context cxMainContext);\r
84         static cl_device_id getDevice(cl_context cxMainContext, int nr);\r
85         static void getDeviceInfo(cl_device_id device, btOpenCLDeviceInfo& info);\r
86         static void printDeviceInfo(cl_device_id device);\r
87 \r
88         static 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 = "" );\r
89 \r
90         //optional\r
91         static cl_program compileCLProgramFromString( cl_context clContext,cl_device_id device, const char* kernelSource, cl_int* pErrNum=0,const char* additionalMacros = "");\r
92         ///compileCLProgramFromFile will attempt to save/load the binary precompiled program\r
93         static cl_program compileCLProgramFromFile( cl_context clContext,cl_device_id device, cl_int* pErrNum=0,const char* additionalMacros = "" , const char* srcFileNameForCaching=0);\r
94         \r
95 \r
96         //the following optional APIs provide access using specific platform information\r
97         static int getNumPlatforms(cl_int* pErrNum=0);\r
98         ///get the nr'th platform, where nr is in the range [0..getNumPlatforms)\r
99         static cl_platform_id getPlatform(int nr, cl_int* pErrNum=0);\r
100         static void getPlatformInfo(cl_platform_id platform, btOpenCLPlatformInfo& platformInfo);\r
101         static const char* getSdkVendorName();\r
102         static 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);\r
103 };\r
104 \r
105 \r
106 \r
107 #endif // BT_OPENCL_UTILS_H\r