b3FillCL.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "b3FillCL.h"
  2. #include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
  3. #include "b3BufferInfoCL.h"
  4. #include "b3LauncherCL.h"
  5. #define FILL_CL_PROGRAM_PATH "src/Bullet3OpenCL/ParallelPrimitives/kernels/FillKernels.cl"
  6. #include "kernels/FillKernelsCL.h"
  7. b3FillCL::b3FillCL(cl_context ctx, cl_device_id device, cl_command_queue queue)
  8. :m_commandQueue(queue)
  9. {
  10. const char* kernelSource = fillKernelsCL;
  11. cl_int pErrNum;
  12. const char* additionalMacros = "";
  13. cl_program fillProg = b3OpenCLUtils::compileCLProgramFromString( ctx, device, kernelSource, &pErrNum,additionalMacros, FILL_CL_PROGRAM_PATH);
  14. b3Assert(fillProg);
  15. m_fillIntKernel = b3OpenCLUtils::compileCLKernelFromString( ctx, device, kernelSource, "FillIntKernel", &pErrNum, fillProg,additionalMacros );
  16. b3Assert(m_fillIntKernel);
  17. m_fillUnsignedIntKernel = b3OpenCLUtils::compileCLKernelFromString( ctx, device, kernelSource, "FillUnsignedIntKernel", &pErrNum, fillProg,additionalMacros );
  18. b3Assert(m_fillIntKernel);
  19. m_fillFloatKernel = b3OpenCLUtils::compileCLKernelFromString( ctx, device, kernelSource, "FillFloatKernel", &pErrNum, fillProg,additionalMacros );
  20. b3Assert(m_fillFloatKernel);
  21. m_fillKernelInt2 = b3OpenCLUtils::compileCLKernelFromString( ctx, device, kernelSource, "FillInt2Kernel", &pErrNum, fillProg,additionalMacros );
  22. b3Assert(m_fillKernelInt2);
  23. }
  24. b3FillCL::~b3FillCL()
  25. {
  26. clReleaseKernel(m_fillKernelInt2);
  27. clReleaseKernel(m_fillIntKernel);
  28. clReleaseKernel(m_fillUnsignedIntKernel);
  29. clReleaseKernel(m_fillFloatKernel);
  30. }
  31. void b3FillCL::execute(b3OpenCLArray<float>& src, const float value, int n, int offset)
  32. {
  33. b3Assert( n>0 );
  34. {
  35. b3LauncherCL launcher( m_commandQueue, m_fillFloatKernel,"m_fillFloatKernel" );
  36. launcher.setBuffer( src.getBufferCL());
  37. launcher.setConst( n );
  38. launcher.setConst( value );
  39. launcher.setConst( offset);
  40. launcher.launch1D( n );
  41. }
  42. }
  43. void b3FillCL::execute(b3OpenCLArray<int>& src, const int value, int n, int offset)
  44. {
  45. b3Assert( n>0 );
  46. {
  47. b3LauncherCL launcher( m_commandQueue, m_fillIntKernel ,"m_fillIntKernel");
  48. launcher.setBuffer(src.getBufferCL());
  49. launcher.setConst( n);
  50. launcher.setConst( value);
  51. launcher.setConst( offset);
  52. launcher.launch1D( n );
  53. }
  54. }
  55. void b3FillCL::execute(b3OpenCLArray<unsigned int>& src, const unsigned int value, int n, int offset)
  56. {
  57. b3Assert( n>0 );
  58. {
  59. b3BufferInfoCL bInfo[] = { b3BufferInfoCL( src.getBufferCL() ) };
  60. b3LauncherCL launcher( m_commandQueue, m_fillUnsignedIntKernel,"m_fillUnsignedIntKernel" );
  61. launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) );
  62. launcher.setConst( n );
  63. launcher.setConst(value);
  64. launcher.setConst(offset);
  65. launcher.launch1D( n );
  66. }
  67. }
  68. void b3FillCL::executeHost(b3AlignedObjectArray<b3Int2> &src, const b3Int2 &value, int n, int offset)
  69. {
  70. for (int i=0;i<n;i++)
  71. {
  72. src[i+offset]=value;
  73. }
  74. }
  75. void b3FillCL::executeHost(b3AlignedObjectArray<int> &src, const int value, int n, int offset)
  76. {
  77. for (int i=0;i<n;i++)
  78. {
  79. src[i+offset]=value;
  80. }
  81. }
  82. void b3FillCL::execute(b3OpenCLArray<b3Int2> &src, const b3Int2 &value, int n, int offset)
  83. {
  84. b3Assert( n>0 );
  85. {
  86. b3BufferInfoCL bInfo[] = { b3BufferInfoCL( src.getBufferCL() ) };
  87. b3LauncherCL launcher(m_commandQueue, m_fillKernelInt2,"m_fillKernelInt2");
  88. launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) );
  89. launcher.setConst(n);
  90. launcher.setConst(value);
  91. launcher.setConst(offset);
  92. //( constBuffer );
  93. launcher.launch1D( n );
  94. }
  95. }