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 */
49extern "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
93 union
94 {
95 void **v;
96 char **c;
97 unsigned char **uc;
98 short **s;
99 unsigned short **us;
100 float **f;
101 } realWork;
102
103 cl_mem *imagWorkCL;
104
105 union
106 {
107 void **v;
108 char **c;
109 unsigned char **uc;
110 short **s;
111 unsigned short **us;
112 float **f;
113 } imagWork;
114
115 cl_mem *dstRealWorkCL;
116
117 union
118 {
119 void **v;
120 char **c;
121 unsigned char **uc;
122 short **s;
123 unsigned short **us;
124 float **f;
125 } dstRealWork;
126
127 cl_mem *dstImagWorkCL;
128
129 union
130 {
131 void **v;
132 char **c;
133 unsigned char **uc;
134 short **s;
135 unsigned short **us;
136 float **f;
137 } dstImagWork;
138
139 unsigned int imgChSize1;
140 cl_channel_order imgChOrder1;
141 unsigned int imgChSize4;
142 cl_channel_order imgChOrder4;
143 char useVec;
144
145 cl_mem useBandSrcValidCL;
146 char *useBandSrcValid;
147
148 cl_mem nBandSrcValidCL;
149 float *nBandSrcValid;
150
151 cl_mem xyWorkCL;
152 float *xyWork;
153
154 int xyWidth;
155 int xyHeight;
156 int coordMult;
157
158 unsigned int xyChSize;
159 cl_channel_order xyChOrder;
160
161 cl_mem fDstNoDataRealCL;
162 float *fDstNoDataReal;
163
164 OCLVendor eCLVendor;
165 };
166
167 struct oclWarper *GDALWarpKernelOpenCL_createEnv(
168 int srcWidth, int srcHeight, int dstWidth, int dstHeight,
169 cl_channel_type imageFormat, int numBands, int coordMult, int useImag,
170 int useBandSrcValid, float *fDstDensity, double *dfDstNoDataReal,
171 OCLResampAlg resampAlg, cl_int *envErr);
172
173 cl_int GDALWarpKernelOpenCL_setSrcValid(struct oclWarper *warper,
174 int *bandSrcValid, int bandNum);
175
176 cl_int GDALWarpKernelOpenCL_setSrcImg(struct oclWarper *warper,
177 void *imgData, int bandNum);
178
179 cl_int GDALWarpKernelOpenCL_setDstImg(struct oclWarper *warper,
180 void *imgData, int bandNum);
181
182 cl_int GDALWarpKernelOpenCL_setCoordRow(struct oclWarper *warper,
183 double *rowSrcX, double *rowSrcY,
184 double srcXOff, double srcYOff,
185 int *success, int rowNum);
186
187 cl_int GDALWarpKernelOpenCL_runResamp(
188 struct oclWarper *warper, float *unifiedSrcDensity,
189 unsigned int *unifiedSrcValid, float *dstDensity,
190 unsigned int *dstValid, double dfXScale, double dfYScale,
191 double dfXFilter, double dfYFilter, int nXRadius, int nYRadius,
192 int nFiltInitX, int nFiltInitY);
193
194 cl_int GDALWarpKernelOpenCL_getRow(struct oclWarper *warper, void **rowReal,
195 void **rowImag, int rowNum, int bandNum);
196
197 cl_int GDALWarpKernelOpenCL_deleteEnv(struct oclWarper *warper);
198
199#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
200}
201#endif
202
203#endif /* defined(HAVE_OPENCL) */