GDAL

gdalwarpkernel_opencl.h
1 /******************************************************************************
2 * $Id$
3 *
4 * Project: OpenCL Image Reprojector
5 * Purpose: Implementation of the GDALWarpKernel reprojector in OpenCL.
6 * Author: Seth Price, seth@pricepages.org
7 *
8 ******************************************************************************
9 * Copyright (c) 2010, Seth Price <seth@pricepages.org>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 ****************************************************************************/
29
30 #if defined(HAVE_OPENCL)
31
32 /* The following relates to the profiling calls to
33 clSetCommandQueueProperty() which are not available by default
34 with some OpenCL implementation (i.e. ATI) */
35
36 #if defined(DEBUG_OPENCL) && DEBUG_OPENCL == 1
37 #define CL_USE_DEPRECATED_OPENCL_1_0_APIS
38 #endif
39
40 #define CL_TARGET_OPENCL_VERSION 100
41
42 #ifdef __APPLE__
43 #include <OpenCL/opencl.h>
44 #else
45 #include <CL/opencl.h>
46 #endif
47
48 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
49 extern "C"
50 {
51 #endif
52
53 typedef enum
54 {
55 OCL_Bilinear = 10,
56 OCL_Cubic = 11,
57 OCL_CubicSpline = 12,
58 OCL_Lanczos = 13
59 } OCLResampAlg;
60
61 typedef enum
62 {
63 VENDOR_OTHER,
64 VENDOR_AMD,
65 VENDOR_INTEL
66 } OCLVendor;
67
68 struct oclWarper
69 {
70 cl_command_queue queue;
71 cl_context context;
72 cl_device_id dev;
73 cl_kernel kern1;
74 cl_kernel kern4;
75
76 int srcWidth;
77 int srcHeight;
78 int dstWidth;
79 int dstHeight;
80
81 int useUnifiedSrcDensity;
82 int useUnifiedSrcValid;
83 int useDstDensity;
84 int useDstValid;
85
86 int numBands;
87 int numImages;
88 OCLResampAlg resampAlg;
89
90 cl_channel_type imageFormat;
91 cl_mem *realWorkCL;
92 union
93 {
94 void **v;
95 char **c;
96 unsigned char **uc;
97 short **s;
98 unsigned short **us;
99 float **f;
100 } realWork;
101
102 cl_mem *imagWorkCL;
103 union
104 {
105 void **v;
106 char **c;
107 unsigned char **uc;
108 short **s;
109 unsigned short **us;
110 float **f;
111 } imagWork;
112
113 cl_mem *dstRealWorkCL;
114 union
115 {
116 void **v;
117 char **c;
118 unsigned char **uc;
119 short **s;
120 unsigned short **us;
121 float **f;
122 } dstRealWork;
123
124 cl_mem *dstImagWorkCL;
125 union
126 {
127 void **v;
128 char **c;
129 unsigned char **uc;
130 short **s;
131 unsigned short **us;
132 float **f;
133 } dstImagWork;
134
135 unsigned int imgChSize1;
136 cl_channel_order imgChOrder1;
137 unsigned int imgChSize4;
138 cl_channel_order imgChOrder4;
139 char useVec;
140
141 cl_mem useBandSrcValidCL;
142 char *useBandSrcValid;
143
144 cl_mem nBandSrcValidCL;
145 float *nBandSrcValid;
146
147 cl_mem xyWorkCL;
148 float *xyWork;
149
150 int xyWidth;
151 int xyHeight;
152 int coordMult;
153
154 unsigned int xyChSize;
155 cl_channel_order xyChOrder;
156
157 cl_mem fDstNoDataRealCL;
158 float *fDstNoDataReal;
159
160 OCLVendor eCLVendor;
161 };
162
163 struct oclWarper *GDALWarpKernelOpenCL_createEnv(
164 int srcWidth, int srcHeight, int dstWidth, int dstHeight,
165 cl_channel_type imageFormat, int numBands, int coordMult, int useImag,
166 int useBandSrcValid, float *fDstDensity, double *dfDstNoDataReal,
167 OCLResampAlg resampAlg, cl_int *envErr);
168
169 cl_int GDALWarpKernelOpenCL_setSrcValid(struct oclWarper *warper,
170 int *bandSrcValid, int bandNum);
171
172 cl_int GDALWarpKernelOpenCL_setSrcImg(struct oclWarper *warper,
173 void *imgData, int bandNum);
174
175 cl_int GDALWarpKernelOpenCL_setDstImg(struct oclWarper *warper,
176 void *imgData, int bandNum);
177
178 cl_int GDALWarpKernelOpenCL_setCoordRow(struct oclWarper *warper,
179 double *rowSrcX, double *rowSrcY,
180 double srcXOff, double srcYOff,
181 int *success, int rowNum);
182
183 cl_int GDALWarpKernelOpenCL_runResamp(
184 struct oclWarper *warper, float *unifiedSrcDensity,
185 unsigned int *unifiedSrcValid, float *dstDensity,
186 unsigned int *dstValid, double dfXScale, double dfYScale,
187 double dfXFilter, double dfYFilter, int nXRadius, int nYRadius,
188 int nFiltInitX, int nFiltInitY);
189
190 cl_int GDALWarpKernelOpenCL_getRow(struct oclWarper *warper, void **rowReal,
191 void **rowImag, int rowNum, int bandNum);
192
193 cl_int GDALWarpKernelOpenCL_deleteEnv(struct oclWarper *warper);
194
195 #ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
196 }
197 #endif
198
199 #endif /* defined(HAVE_OPENCL) */