summaryrefslogtreecommitdiff
path: root/thirdparty/bullet/src/Bullet3OpenCL/ParallelPrimitives/kernels/BoundSearchKernels.cl
blob: f3b4a1e8a79592e80b0f1ee7dc95a587321a3239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Copyright (c) 2012 Advanced Micro Devices, Inc.  

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, 
including commercial applications, and to alter it and redistribute it freely, 
subject to the following restrictions:

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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
//Originally written by Takahiro Harada


typedef unsigned int u32;
#define GET_GROUP_IDX get_group_id(0)
#define GET_LOCAL_IDX get_local_id(0)
#define GET_GLOBAL_IDX get_global_id(0)
#define GET_GROUP_SIZE get_local_size(0)
#define GROUP_LDS_BARRIER barrier(CLK_LOCAL_MEM_FENCE)

typedef struct
{
	u32 m_key; 
	u32 m_value;
}SortData;



typedef struct
{
	u32 m_nSrc;
	u32 m_nDst;
	u32 m_padding[2];
} ConstBuffer;



__attribute__((reqd_work_group_size(64,1,1)))
__kernel
void SearchSortDataLowerKernel(__global SortData* src, __global u32 *dst, 
					unsigned int nSrc, unsigned int nDst)
{
	int gIdx = GET_GLOBAL_IDX;

	if( gIdx < nSrc )
	{
		SortData first; first.m_key = (u32)(-1); first.m_value = (u32)(-1);
		SortData end; end.m_key = nDst; end.m_value = nDst;

		SortData iData = (gIdx==0)? first: src[gIdx-1];
		SortData jData = (gIdx==nSrc)? end: src[gIdx];

		if( iData.m_key != jData.m_key )
		{
//			for(u32 k=iData.m_key+1; k<=min(jData.m_key, nDst-1); k++)
			u32 k = jData.m_key;
			{
				dst[k] = gIdx;
			}
		}
	}
}


__attribute__((reqd_work_group_size(64,1,1)))
__kernel
void SearchSortDataUpperKernel(__global SortData* src, __global u32 *dst, 
					unsigned int nSrc, unsigned int nDst)
{
	int gIdx = GET_GLOBAL_IDX+1;

	if( gIdx < nSrc+1 )
	{
		SortData first; first.m_key = 0; first.m_value = 0;
		SortData end; end.m_key = nDst; end.m_value = nDst;

		SortData iData = src[gIdx-1];
		SortData jData = (gIdx==nSrc)? end: src[gIdx];

		if( iData.m_key != jData.m_key )
		{
			u32 k = iData.m_key;
			{
				dst[k] = gIdx;
			}
		}
	}
}

__attribute__((reqd_work_group_size(64,1,1)))
__kernel
void SubtractKernel(__global u32* A, __global u32 *B, __global u32 *C, 
					unsigned int nSrc, unsigned int nDst)
{
	int gIdx = GET_GLOBAL_IDX;
	

	if( gIdx < nDst )
	{
		C[gIdx] = A[gIdx] - B[gIdx];
	}
}