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