[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3OpenCL / ParallelPrimitives / kernels / PrefixScanKernelsFloat4CL.h
1 //this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
2 static const char* prefixScanKernelsFloat4CL =
3         "/*\n"
4         "Copyright (c) 2012 Advanced Micro Devices, Inc.  \n"
5         "This software is provided 'as-is', without any express or implied warranty.\n"
6         "In no event will the authors be held liable for any damages arising from the use of this software.\n"
7         "Permission is granted to anyone to use this software for any purpose, \n"
8         "including commercial applications, and to alter it and redistribute it freely, \n"
9         "subject to the following restrictions:\n"
10         "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.\n"
11         "2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\n"
12         "3. This notice may not be removed or altered from any source distribution.\n"
13         "*/\n"
14         "//Originally written by Takahiro Harada\n"
15         "typedef unsigned int u32;\n"
16         "#define GET_GROUP_IDX get_group_id(0)\n"
17         "#define GET_LOCAL_IDX get_local_id(0)\n"
18         "#define GET_GLOBAL_IDX get_global_id(0)\n"
19         "#define GET_GROUP_SIZE get_local_size(0)\n"
20         "#define GROUP_LDS_BARRIER barrier(CLK_LOCAL_MEM_FENCE)\n"
21         "// takahiro end\n"
22         "#define WG_SIZE 128 \n"
23         "#define m_numElems x\n"
24         "#define m_numBlocks y\n"
25         "#define m_numScanBlocks z\n"
26         "/*typedef struct\n"
27         "{\n"
28         "       uint m_numElems;\n"
29         "       uint m_numBlocks;\n"
30         "       uint m_numScanBlocks;\n"
31         "       uint m_padding[1];\n"
32         "} ConstBuffer;\n"
33         "*/\n"
34         "float4 ScanExclusiveFloat4(__local float4* data, u32 n, int lIdx, int lSize)\n"
35         "{\n"
36         "       float4 blocksum;\n"
37         "    int offset = 1;\n"
38         "    for(int nActive=n>>1; nActive>0; nActive>>=1, offset<<=1)\n"
39         "    {\n"
40         "        GROUP_LDS_BARRIER;\n"
41         "        for(int iIdx=lIdx; iIdx<nActive; iIdx+=lSize)\n"
42         "        {\n"
43         "            int ai = offset*(2*iIdx+1)-1;\n"
44         "            int bi = offset*(2*iIdx+2)-1;\n"
45         "            data[bi] += data[ai];\n"
46         "        }\n"
47         "       }\n"
48         "    GROUP_LDS_BARRIER;\n"
49         "    if( lIdx == 0 )\n"
50         "       {\n"
51         "               blocksum = data[ n-1 ];\n"
52         "    data[ n-1 ] = 0;\n"
53         "       }\n"
54         "       GROUP_LDS_BARRIER;\n"
55         "       offset >>= 1;\n"
56         "    for(int nActive=1; nActive<n; nActive<<=1, offset>>=1 )\n"
57         "    {\n"
58         "        GROUP_LDS_BARRIER;\n"
59         "        for( int iIdx = lIdx; iIdx<nActive; iIdx += lSize )\n"
60         "        {\n"
61         "            int ai = offset*(2*iIdx+1)-1;\n"
62         "            int bi = offset*(2*iIdx+2)-1;\n"
63         "            float4 temp = data[ai];\n"
64         "            data[ai] = data[bi];\n"
65         "            data[bi] += temp;\n"
66         "        }\n"
67         "       }\n"
68         "       GROUP_LDS_BARRIER;\n"
69         "       return blocksum;\n"
70         "}\n"
71         "__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
72         "__kernel\n"
73         "void LocalScanKernel(__global float4* dst, __global float4* src, __global float4* sumBuffer,   uint4 cb)\n"
74         "{\n"
75         "       __local float4 ldsData[WG_SIZE*2];\n"
76         "       int gIdx = GET_GLOBAL_IDX;\n"
77         "       int lIdx = GET_LOCAL_IDX;\n"
78         "       ldsData[2*lIdx]     = ( 2*gIdx < cb.m_numElems )? src[2*gIdx]: 0;\n"
79         "       ldsData[2*lIdx + 1] = ( 2*gIdx+1 < cb.m_numElems )? src[2*gIdx + 1]: 0;\n"
80         "       float4 sum = ScanExclusiveFloat4(ldsData, WG_SIZE*2, GET_LOCAL_IDX, GET_GROUP_SIZE);\n"
81         "       if( lIdx == 0 ) \n"
82         "               sumBuffer[GET_GROUP_IDX] = sum;\n"
83         "       if( (2*gIdx) < cb.m_numElems )\n"
84         "    {\n"
85         "        dst[2*gIdx]     = ldsData[2*lIdx];\n"
86         "       }\n"
87         "       if( (2*gIdx + 1) < cb.m_numElems )\n"
88         "       {\n"
89         "        dst[2*gIdx + 1] = ldsData[2*lIdx + 1];\n"
90         "    }\n"
91         "}\n"
92         "__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
93         "__kernel\n"
94         "void AddOffsetKernel(__global float4* dst, __global float4* blockSum, uint4 cb)\n"
95         "{\n"
96         "       const u32 blockSize = WG_SIZE*2;\n"
97         "       int myIdx = GET_GROUP_IDX+1;\n"
98         "       int lIdx = GET_LOCAL_IDX;\n"
99         "       float4 iBlockSum = blockSum[myIdx];\n"
100         "       int endValue = min((myIdx+1)*(blockSize), cb.m_numElems);\n"
101         "       for(int i=myIdx*blockSize+lIdx; i<endValue; i+=GET_GROUP_SIZE)\n"
102         "       {\n"
103         "               dst[i] += iBlockSum;\n"
104         "       }\n"
105         "}\n"
106         "__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
107         "__kernel\n"
108         "void TopLevelScanKernel(__global float4* dst, uint4 cb)\n"
109         "{\n"
110         "       __local float4 ldsData[2048];\n"
111         "       int gIdx = GET_GLOBAL_IDX;\n"
112         "       int lIdx = GET_LOCAL_IDX;\n"
113         "       int lSize = GET_GROUP_SIZE;\n"
114         "       for(int i=lIdx; i<cb.m_numScanBlocks; i+=lSize )\n"
115         "       {\n"
116         "               ldsData[i] = (i<cb.m_numBlocks)? dst[i]:0;\n"
117         "       }\n"
118         "       GROUP_LDS_BARRIER;\n"
119         "       float4 sum = ScanExclusiveFloat4(ldsData, cb.m_numScanBlocks, GET_LOCAL_IDX, GET_GROUP_SIZE);\n"
120         "       for(int i=lIdx; i<cb.m_numBlocks; i+=lSize )\n"
121         "       {\n"
122         "               dst[i] = ldsData[i];\n"
123         "       }\n"
124         "       if( gIdx == 0 )\n"
125         "       {\n"
126         "               dst[cb.m_numBlocks] = sum;\n"
127         "       }\n"
128         "}\n";