Eulerian Smoke Simulation on the GPU
include/ComputeEngine.h
Go to the documentation of this file.
00001 #ifndef __COMPUTE_ENGINE_H__
00002 #define __COMPUTE_ENGINE_H__
00003 
00004 //---------------------------------------------------------------------
00012 //---------------------------------------------------------------------
00013 
00014 #ifdef DARWIN
00015   #include <OpenCL/opencl.h>
00016   #include <OpenGL/openGL.h>
00017 #else
00018   #include <CL/opencl.h>
00019   #include <GL/gl.h>
00020 #endif
00021 
00022 #include <map>
00023 #include <stdarg.h>
00024 
00032 class ComputeEngine
00033 {
00034 public:
00036   enum DeviceType
00037   {
00038     DEVICE_TYPE_CPU     = CL_DEVICE_TYPE_CPU,
00039     DEVICE_TYPE_GPU     = CL_DEVICE_TYPE_GPU,
00040     DEVICE_TYPE_DEFAULT = CL_DEVICE_TYPE_DEFAULT,
00041     DEVICE_TYPE_ALL     = CL_DEVICE_TYPE_ALL
00042   };
00043 
00045   ComputeEngine();
00046 
00048   ~ComputeEngine();
00049 
00054   bool connect(
00055                 DeviceType     _deviceType = DEVICE_TYPE_ALL,
00056                 unsigned int   _count = 1,
00057                 bool           _useOpenGLContext = false
00058               );
00059 
00061   bool disconnect();
00062 
00066   bool createProgram(
00067                       const char* _programName,
00068                       const char* _fileName
00069                     );
00070 
00074   bool createKernel(
00075                     const char* _programName,
00076                     const char* _kernelName
00077                    );
00078 
00084   bool setKernelArg(
00085                     const char* _kernelName,
00086                     cl_uint     _index,
00087                     void*       _argsValue,
00088                     size_t      _argsSize
00089                    );
00090 
00095   bool setKernelArg(
00096                     const char* _kernelName,
00097                     cl_uint     _index,
00098                     const char* _memObjName
00099                    );
00100 
00104   bool setKernelArgs(
00105                       const char* _kernelName,
00106                       ...
00107                     );
00108 
00115   bool executeKernel(
00116                       const char* _kernelName,
00117                       cl_uint     _deviceId,
00118                       size_t*     _globalDim,
00119                       size_t*     _localDim,
00120                       cl_uint     _dimCount
00121                     );
00122 
00125   cl_kernel getKernelObject(
00126                             const char* _kernelName
00127                            );
00128 
00131   cl_mem getMemObject(
00132                       const char* _memObjName
00133                      );
00134 
00140   bool createBuffer(
00141                     const char*  _memObjName,
00142                     cl_mem_flags _memFlags,
00143                     size_t       _bytes,
00144                     void*        _data
00145                    );
00146 
00153   bool readBuffer(
00154                   const char* _memObjName,
00155                   cl_uint     _deviceIndex,
00156                   cl_uint     _start,
00157                   size_t      _bytes,
00158                   void*       _data
00159                  );
00160 
00167   bool writeBuffer(
00168                     const char* _memObjName,
00169                     cl_uint     _deviceIndex,
00170                     cl_uint     _start,
00171                     size_t      _bytes,
00172                     void*       _data
00173                   );
00174 
00184   bool createImage2D(
00185                       const char*      _memObjName,
00186                       cl_mem_flags     _memFlags,
00187                       cl_channel_order _channelOrder,
00188                       cl_channel_type  _channelType,
00189                       cl_uint          _width,
00190                       cl_uint          _height,
00191                       cl_uint          _rowPitch = 0,
00192                       void*            _data = NULL
00193                     );
00194 
00206   bool createImage3D(
00207                       const char*      _memObjName,
00208                       cl_mem_flags     _memFlags,
00209                       cl_channel_order _channelOrder,
00210                       cl_channel_type  _channelType,
00211                       cl_uint          _width,
00212                       cl_uint          _height,
00213                       cl_uint          _depth,
00214                       cl_uint          _rowPitch = 0,
00215                       cl_uint          _slicePitch = 0,
00216                       void*            _data = NULL
00217                     );
00218 
00231   bool readImage(
00232                   const char* _memObjName,
00233                   cl_uint     _deviceIndex,
00234                   cl_uint     _x,
00235                   cl_uint     _y,
00236                   cl_uint     _z,
00237                   cl_uint     _width,
00238                   cl_uint     _height,
00239                   cl_uint     _depth,
00240                   cl_uint     _rowPitch,
00241                   cl_uint     _slicePitch,
00242                   void*       _data
00243                 );
00244 
00257   bool writeImage(
00258                   const char* _memObjName,
00259                   cl_uint     _deviceIndex,
00260                   cl_uint     _x,
00261                   cl_uint     _y,
00262                   cl_uint     _z,
00263                   cl_uint     _width,
00264                   cl_uint     _height,
00265                   cl_uint     _depth,
00266                   cl_uint     _rowPitch,
00267                   cl_uint     _slicePitch,
00268                   void*       _data
00269                  );
00270 
00278   bool copyBufferToBuffer(
00279                           const char* _sourceBufferName,
00280                           const char* _destinationBufferName,
00281                           cl_uint     _deviceIndex,
00282                           size_t      _sourceOffset,
00283                           size_t      _destinationOffset,
00284                           size_t      _bytes
00285                         );
00286 
00294   bool copyBufferToBuffer(
00295                           cl_mem  _sourceBuffer,
00296                           cl_mem  _destinationBuffer,
00297                           cl_uint _deviceIndex,
00298                           size_t  _sourceOffset,
00299                           size_t  _destinationOffset,
00300                           size_t  _bytes
00301                         );
00302 
00314   bool copyBufferToImage(
00315                           const char*  _bufferName,
00316                           const char*  _imageName,
00317                           cl_uint      _deviceIndex,
00318                           size_t       _bufferOffset,
00319                           cl_uint      _x,
00320                           cl_uint      _y,
00321                           cl_uint      _z,
00322                           cl_uint      _width,
00323                           cl_uint      _height,
00324                           cl_uint      _depth
00325                         );
00326 
00338   bool copyBufferToImage(
00339                           cl_mem       _buffer,
00340                           cl_mem       _image,
00341                           cl_uint      _deviceIndex,
00342                           size_t       _bufferOffset,
00343                           cl_uint      _x,
00344                           cl_uint      _y,
00345                           cl_uint      _z,
00346                           cl_uint      _width,
00347                           cl_uint      _height,
00348                           cl_uint      _depth
00349                         );
00350 
00362   bool copyImageToBuffer(
00363                           const char*  _bufferName,
00364                           const char*  _imageName,
00365                           cl_uint      _deviceIndex,
00366                           cl_uint      _x,
00367                           cl_uint      _y,
00368                           cl_uint      _z,
00369                           cl_uint      _width,
00370                           cl_uint      _height,
00371                           cl_uint      _depth,
00372                           size_t       _bufferOffset
00373                         );
00374 
00386   bool copyImageToBuffer(
00387                           cl_mem       _buffer,
00388                           cl_mem       _image,
00389                           cl_uint      _deviceIndex,
00390                           cl_uint      _x,
00391                           cl_uint      _y,
00392                           cl_uint      _z,
00393                           cl_uint      _width,
00394                           cl_uint      _height,
00395                           cl_uint      _depth,
00396                           size_t       _bufferOffset
00397                         );
00398 
00403   bool createGLBufferReference(
00404                                 const char*  _memObjName,
00405                                 cl_mem_flags _memFlags,
00406                                 cl_uint      _bufferId
00407                               );
00408 
00415   bool createGLTexture2DReference(
00416                                   const char*  _memObjName,
00417                                   cl_mem_flags _memFlags,
00418                                   GLenum       _target,
00419                                   GLint        _mipLevel,
00420                                   GLuint       _textureId
00421                                  );
00422 
00429   bool createGLTexture3DReference(
00430                                   const char*  _memObjName,
00431                                   cl_mem_flags _memFlags,
00432                                   GLenum       _target,
00433                                   GLint        _mipLevel,
00434                                   GLuint       _textureId
00435                                  );
00436 
00441   bool createGLRenderBufferReference(
00442                                       const char*  _memObjName,
00443                                       cl_mem_flags _memFlags,
00444                                       GLuint       _rboId
00445                                     );
00446 
00447 
00451   bool acquireGLObject(
00452                         const char* _memObjName,
00453                         cl_uint     _deviceIndex = 0
00454                       );
00455 
00459   bool releaseGLObject(
00460                         const char* _memObjName,
00461                         cl_uint _deviceIndex = 0
00462                       );
00463 
00467   bool swapMemObjects(
00468                       const char* _memObjNameA,
00469                       const char* _memObjNameB
00470                      );
00471 
00477   bool createImageSampler(
00478                           const char*        _samplerName,
00479                           cl_bool            _normalizedCoords,
00480                           cl_addressing_mode _addressingMode,
00481                           cl_filter_mode     _filterMode
00482                          );
00483 
00486   cl_sampler getSampler(
00487                         const char* _samplerName
00488                        );
00489 
00493   bool flush(
00494               cl_uint _deviceIndex = 0
00495             );
00496 
00500   bool finish(
00501               cl_uint _deviceIndex = 0
00502              );
00503 
00506   bool barrier(
00507                 cl_uint _deviceIndex = 0
00508               );
00509 
00510 
00512   cl_uint getContextDeviceCount();
00513 
00517   cl_uint getEstimatedWorkGroupSize(
00518                                     const char* _kernelName,
00519                                     cl_uint _deviceIndex = 0
00520                                    );  
00521 
00523   void getCLExtensions();
00524 
00525 private:
00527   unsigned int s_maxDeviceCount;
00529   unsigned int m_deviceCount;
00531   cl_context m_context;
00533   cl_device_id* m_deviceIds;
00535   cl_command_queue* m_commandQueues;
00536 
00538   std::map<const char*, cl_program> m_programs;
00540   std::map<const char*, cl_kernel> m_kernels;
00542   std::map<const char*, cl_mem> m_memObjects;
00544   std::map<const char*, cl_sampler> m_samplers;
00545 
00547   typedef std::map<const char*, cl_program>::iterator ProgramMapIter;
00549   typedef std::map<const char*, cl_kernel>::iterator KernelMapIter;
00551   typedef std::map<const char*, cl_mem>::iterator MemObjectMapIter;
00553   typedef std::map<const char*, cl_sampler>::iterator SamplerMapIter;
00554 };
00555 
00556 #endif // __COMPUTE_ENGINE_H__
 All Classes Files Functions Variables