blob: 4f87b9242a921421fdf6d19ddb4de039e4b114dc [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in;
Anthony Barbier7068f992017-10-26 15:23:08 +010025
Joel Liange5384ff2017-12-06 15:33:28 +080026#include "helpers_cs.h"
27
28#if defined(DATA_TYPE_FP16)
29precision mediump float;
30#endif // DATA_TYPE_FP16
31
Anthony Barbier7068f992017-10-26 15:23:08 +010032#ifdef FILL_IMAGE_BORDERS_REPLICATE
Anthony Barbier7068f992017-10-26 15:23:08 +010033
34/** Fill N pixel of the padding edge of a single channel image by replicating the closest valid pixel.
35 *
Joel Liange5384ff2017-12-06 15:33:28 +080036 * @note The data type must be passed at compile time using "#define DATA_TYPE_NAME". e.g. "#define DATA_TYPE_FP32"
Anthony Barbier7068f992017-10-26 15:23:08 +010037 * @attention The border size for top, bottom, left, right needs to be passed at the compile time.
38 * e.g. BORDER_SIZE_TOP=0 BORDER_SIZE_BOTTOM=2 BORDER_SIZE_LEFT=0 BORDER_SIZE_RIGHT=2
39 *
Joel Liange5384ff2017-12-06 15:33:28 +080040 * @param[in,out] buf_ptr Pointer to the source image. Supported data types: F16/F32
41 * @param[in] buf_attrs The attributes of the source image
42 * @param[in] width Width of the valid region of the image
43 * @param[in] height Height of the valid region of the image
44 * @param[in] start_pos_x X coordinate indicating the start point of the valid region
45 * @param[in] start_pos_y Y coordinate indicating the start point of the valid region
Anthony Barbier7068f992017-10-26 15:23:08 +010046 */
Joel Liange5384ff2017-12-06 15:33:28 +080047SHADER_PARAMS_DECLARATION
48{
49 Tensor3DAttributes buf_attrs;
50 uint width;
51 uint height;
52 int start_pos_x;
53 int start_pos_y;
54};
55
56#if defined(DATA_TYPE_FP32)
57
58TENSOR_DECLARATION(1, bufBuffer, float, buf_ptr, buf_shift, 2, restrict);
59
Anthony Barbier7068f992017-10-26 15:23:08 +010060void main()
61{
Joel Liange5384ff2017-12-06 15:33:28 +080062 ImageIterator buf_iter = CONVERT_TENSOR3D_TO_IMAGE_ITERATOR_NO_STEP(buf_attrs, buf_shift);
Anthony Barbier7068f992017-10-26 15:23:08 +010063
64 // Update pointer to point to the starting point of the valid region
Joel Liange5384ff2017-12-06 15:33:28 +080065 TENSOR_ITERATOR_ADVANCE_IN_BYTES(buf_iter, start_pos_y * int(buf_attrs.stride_y) + start_pos_x * int(buf_attrs.stride_x));
Anthony Barbier7068f992017-10-26 15:23:08 +010066
67 int total_width = BORDER_SIZE_LEFT + int(width) + BORDER_SIZE_RIGHT;
68 int gid0 = int(gl_GlobalInvocationID.x);
69 int gidH = gid0 - total_width;
70 int gidW = gid0 - BORDER_SIZE_LEFT;
71
72 if(gidH >= 0)
73 {
74 // Handle left border
Joel Liange5384ff2017-12-06 15:33:28 +080075 float left_val = LOAD(buf_ptr, IMAGE_OFFSET(buf_iter, 0, gidH));
zhenglinf8b41e92017-12-01 18:56:59 +080076 for(int i = 0; i < BORDER_SIZE_LEFT; ++i)
Anthony Barbier7068f992017-10-26 15:23:08 +010077 {
Joel Liange5384ff2017-12-06 15:33:28 +080078 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, -(i + 1), gidH), left_val);
Anthony Barbier7068f992017-10-26 15:23:08 +010079 }
80 // Handle right border
Joel Liange5384ff2017-12-06 15:33:28 +080081 float right_val = LOAD(buf_ptr, IMAGE_OFFSET(buf_iter, int(width) - 1, gidH));
Anthony Barbier7068f992017-10-26 15:23:08 +010082 for(int i = 0; i < BORDER_SIZE_RIGHT; ++i)
83 {
Joel Liange5384ff2017-12-06 15:33:28 +080084 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, int(width) + i, gidH), right_val);
Anthony Barbier7068f992017-10-26 15:23:08 +010085 }
86 }
87 else
88 {
89 // Get value for corners
90 int val_idx = gidW;
91 if(gidW < 0 || gidW > (int(width) - 1))
92 {
93 val_idx = gidW < 0 ? 0 : int(width) - 1;
94 }
95
96 // Handle top border
Joel Liange5384ff2017-12-06 15:33:28 +080097 float top_val = LOAD(buf_ptr, IMAGE_OFFSET(buf_iter, val_idx, 0));
zhenglinf8b41e92017-12-01 18:56:59 +080098 for(int i = 0; i < BORDER_SIZE_TOP; ++i)
Anthony Barbier7068f992017-10-26 15:23:08 +010099 {
Joel Liange5384ff2017-12-06 15:33:28 +0800100 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, gidW, -(i + 1)), top_val);
Anthony Barbier7068f992017-10-26 15:23:08 +0100101 }
102 // Handle bottom border
Joel Liange5384ff2017-12-06 15:33:28 +0800103 float bottom_val = LOAD(buf_ptr, IMAGE_OFFSET(buf_iter, val_idx, int(height) - 1));
Anthony Barbier7068f992017-10-26 15:23:08 +0100104 for(int i = 0; i < BORDER_SIZE_BOTTOM; ++i)
105 {
Joel Liange5384ff2017-12-06 15:33:28 +0800106 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, gidW, int(height) + i), bottom_val);
Anthony Barbier7068f992017-10-26 15:23:08 +0100107 }
108 }
109}
Anthony Barbier7068f992017-10-26 15:23:08 +0100110#elif defined(DATA_TYPE_FP16)
Anthony Barbier7068f992017-10-26 15:23:08 +0100111
Joel Liange5384ff2017-12-06 15:33:28 +0800112TENSOR_DECLARATION(1, bufBuffer, uint, buf_ptr, buf_shift, 2, restrict);
113
114void set_replicate(uint offset, int pos, vec2 replicate_value)
Anthony Barbier7068f992017-10-26 15:23:08 +0100115{
Joel Liange5384ff2017-12-06 15:33:28 +0800116 vec2 b = LOAD_UNPACK2_HALF(buf_ptr, offset);
Anthony Barbier7068f992017-10-26 15:23:08 +0100117
118 if(pos % 2 == 0)
119 {
Joel Liange5384ff2017-12-06 15:33:28 +0800120 b.x = replicate_value.y;
Anthony Barbier7068f992017-10-26 15:23:08 +0100121 }
122 else
123 {
Joel Liange5384ff2017-12-06 15:33:28 +0800124 b.y = replicate_value.x;
Anthony Barbier7068f992017-10-26 15:23:08 +0100125 }
126
Joel Liange5384ff2017-12-06 15:33:28 +0800127 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100128}
129
Anthony Barbier7068f992017-10-26 15:23:08 +0100130void main()
131{
Joel Liange5384ff2017-12-06 15:33:28 +0800132 ImageIterator buf_iter = CONVERT_TENSOR3D_TO_IMAGE_ITERATOR_NO_STEP(buf_attrs, buf_shift);
Anthony Barbier7068f992017-10-26 15:23:08 +0100133
134 // Update pointer to point to the starting point of the valid region
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800135 TENSOR_ITERATOR_ADVANCE_IN_BYTES(buf_iter, start_pos_y * int(buf_attrs.stride_y) + start_pos_x * int(buf_attrs.stride_x));
Anthony Barbier7068f992017-10-26 15:23:08 +0100136
137 int total_width = BORDER_SIZE_LEFT + int(width) + BORDER_SIZE_RIGHT;
138 int gid0 = int(gl_GlobalInvocationID.x);
139 int gidH = gid0 - total_width;
140 int gidW = gid0 - BORDER_SIZE_LEFT;
141
142 if(gidH >= 0)
143 {
144 // Handle left border
Joel Liange5384ff2017-12-06 15:33:28 +0800145 vec2 left_val = LOAD_UNPACK2_HALF(buf_ptr, IMAGE_OFFSET(buf_iter, 0, gidH));
zhenglinf8b41e92017-12-01 18:56:59 +0800146 for(int i = 0; i < BORDER_SIZE_LEFT; ++i)
Anthony Barbier7068f992017-10-26 15:23:08 +0100147 {
Joel Liange5384ff2017-12-06 15:33:28 +0800148 uint offset = IMAGE_OFFSET(buf_iter, -(i + 1), gidH);
zhenglinf8b41e92017-12-01 18:56:59 +0800149 int pos = BORDER_SIZE_LEFT - i - 1;
150 if(i == 0)
Anthony Barbier7068f992017-10-26 15:23:08 +0100151 {
152 if(pos % 2 == 0)
153 {
154 set_replicate(offset, pos, left_val);
155 }
156 }
157 else
158 {
159 if(pos % 2 == 0)
160 {
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800161 if(BORDER_SIZE_LEFT % 2 == 0)
162 {
163 STORE_PACK2_HALF(buf_ptr, offset, left_val.xx);
164 }
165 else
166 {
167 STORE_PACK2_HALF(buf_ptr, offset, left_val.yy);
168 }
169 i++;
Anthony Barbier7068f992017-10-26 15:23:08 +0100170 }
171 }
172 }
173 // Handle right border
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800174 vec2 right_val_origin = LOAD_UNPACK2_HALF(buf_ptr, IMAGE_OFFSET(buf_iter, int(width) - 1, gidH));
175 vec2 right_val;
176 if((((BORDER_SIZE_LEFT + int(width)) % 2)) == 1)
177 {
178 right_val = vec2(right_val_origin.x, right_val_origin.x);
179 }
180 else
181 {
182 right_val = vec2(right_val_origin.y, right_val_origin.y);
183 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100184 for(int i = 0; i < BORDER_SIZE_RIGHT; ++i)
185 {
Joel Liange5384ff2017-12-06 15:33:28 +0800186 uint offset = IMAGE_OFFSET(buf_iter, int(width) + i, gidH);
Anthony Barbier7068f992017-10-26 15:23:08 +0100187 int pos = i + BORDER_SIZE_LEFT + int(width);
188
189 if(i == 0)
190 {
191 if(pos % 2 == 0)
192 {
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800193 STORE_PACK2_HALF(buf_ptr, offset, right_val);
194 i++;
Anthony Barbier7068f992017-10-26 15:23:08 +0100195 }
196 else
197 {
198 set_replicate(offset, pos, right_val);
199 }
200 }
201 else
202 {
203 if(pos % 2 == 0)
204 {
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800205 STORE_PACK2_HALF(buf_ptr, offset, right_val);
206 i++;
Anthony Barbier7068f992017-10-26 15:23:08 +0100207 }
208 }
209 }
210 }
211 else
212 {
213 // Get value for corners
214 int val_idx = gidW;
215 if(gidW < 0 || (gidW > (int(width) - 1)))
216 {
217 val_idx = gidW < 0 ? 0 : (int(width) - 1);
218 }
219
220 // Handle top border
Joel Liange5384ff2017-12-06 15:33:28 +0800221 vec2 top_val = LOAD_UNPACK2_HALF(buf_ptr, IMAGE_OFFSET(buf_iter, val_idx, 0));
zhenglinf8b41e92017-12-01 18:56:59 +0800222 for(int i = 0; i < BORDER_SIZE_TOP; ++i)
Anthony Barbier7068f992017-10-26 15:23:08 +0100223 {
Joel Liange5384ff2017-12-06 15:33:28 +0800224 uint offset = IMAGE_OFFSET(buf_iter, gidW, -(i + 1));
Anthony Barbier7068f992017-10-26 15:23:08 +0100225
226 if(gid0 % 2 == 0)
227 {
228 if(gidW == (int(width) - 1))
229 {
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800230 if(((BORDER_SIZE_LEFT + int(width)) % 2 == 1))
231 {
232 STORE_PACK2_HALF(buf_ptr, offset, top_val.xx);
233 }
234 else
235 {
236 STORE_PACK2_HALF(buf_ptr, offset, top_val.yy);
237 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100238 }
239 else
240 {
241 if(gidW < 0)
242 {
Anthony Barbier7068f992017-10-26 15:23:08 +0100243 if(BORDER_SIZE_LEFT % 2 == 0)
244 {
Joel Liange5384ff2017-12-06 15:33:28 +0800245 STORE_PACK2_HALF(buf_ptr, offset, top_val.xx);
Anthony Barbier7068f992017-10-26 15:23:08 +0100246 }
247 else
248 {
Joel Liange5384ff2017-12-06 15:33:28 +0800249 STORE_PACK2_HALF(buf_ptr, offset, top_val.yy);
Anthony Barbier7068f992017-10-26 15:23:08 +0100250 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100251 }
252 else if(gidW >= int(width))
253 {
Anthony Barbier7068f992017-10-26 15:23:08 +0100254 if((BORDER_SIZE_LEFT + int(width)) % 2 == 0)
255 {
Joel Liange5384ff2017-12-06 15:33:28 +0800256 STORE_PACK2_HALF(buf_ptr, offset, top_val.yy);
Anthony Barbier7068f992017-10-26 15:23:08 +0100257 }
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800258 else
259 {
260 STORE_PACK2_HALF(buf_ptr, offset, top_val.xx);
261 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100262 }
263 else
264 {
Joel Liange5384ff2017-12-06 15:33:28 +0800265 STORE_PACK2_HALF(buf_ptr, offset, top_val);
Anthony Barbier7068f992017-10-26 15:23:08 +0100266 }
267 }
268 }
269 }
270 // Handle bottom border
Joel Liange5384ff2017-12-06 15:33:28 +0800271 vec2 bottom_val = LOAD_UNPACK2_HALF(buf_ptr, IMAGE_OFFSET(buf_iter, val_idx, int(height) - 1));
Anthony Barbier7068f992017-10-26 15:23:08 +0100272 for(int i = 0; i < BORDER_SIZE_BOTTOM; ++i)
273 {
Joel Liange5384ff2017-12-06 15:33:28 +0800274 uint offset = IMAGE_OFFSET(buf_iter, gidW, int(height) + i);
Anthony Barbier7068f992017-10-26 15:23:08 +0100275
276 if(gid0 % 2 == 0)
277 {
278 if(gidW == (int(width) - 1))
279 {
Joel Liange5384ff2017-12-06 15:33:28 +0800280 STORE_PACK2_HALF(buf_ptr, offset, bottom_val.xx);
Anthony Barbier7068f992017-10-26 15:23:08 +0100281 }
282 else
283 {
284 if(gidW < 0)
285 {
Anthony Barbier7068f992017-10-26 15:23:08 +0100286 if(BORDER_SIZE_LEFT % 2 == 0)
287 {
Joel Liange5384ff2017-12-06 15:33:28 +0800288 STORE_PACK2_HALF(buf_ptr, offset, bottom_val.xx);
Anthony Barbier7068f992017-10-26 15:23:08 +0100289 }
290 else
291 {
Joel Liange5384ff2017-12-06 15:33:28 +0800292 STORE_PACK2_HALF(buf_ptr, offset, bottom_val.yy);
Anthony Barbier7068f992017-10-26 15:23:08 +0100293 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100294 }
295 else if(gidW >= int(width))
296 {
Anthony Barbier7068f992017-10-26 15:23:08 +0100297 if((BORDER_SIZE_LEFT + int(width)) % 2 == 0)
298 {
Joel Liange5384ff2017-12-06 15:33:28 +0800299 STORE_PACK2_HALF(buf_ptr, offset, bottom_val.yy);
Anthony Barbier7068f992017-10-26 15:23:08 +0100300 }
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800301 else
302 {
303 STORE_PACK2_HALF(buf_ptr, offset, bottom_val.xx);
304 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100305 }
306 else
307 {
Joel Liange5384ff2017-12-06 15:33:28 +0800308 STORE_PACK2_HALF(buf_ptr, offset, bottom_val);
Anthony Barbier7068f992017-10-26 15:23:08 +0100309 }
310 }
311 }
312 }
313 }
314}
Joel Liange5384ff2017-12-06 15:33:28 +0800315
316#endif /* DATA_TYPE_FP32 */
317
Anthony Barbier7068f992017-10-26 15:23:08 +0100318#endif /* FILL_IMAGE_BORDERS_REPLICATE */
319
320#ifdef FILL_IMAGE_BORDERS_CONSTANT
Anthony Barbier7068f992017-10-26 15:23:08 +0100321
Joel Liange5384ff2017-12-06 15:33:28 +0800322/** Fill N pixels of the padding edge of a single channel image with a constant value.
323 *
324 * @note The data type must be passed at compile time using "#define DATA_TYPE_NAME". e.g. "#define DATA_TYPE_FP32"
325 * @attention The border size for top, bottom, left, right needs to be passed at the compile time.
326 * e.g. BORDER_SIZE_TOP=0 BORDER_SIZE_BOTTOM=2 BORDER_SIZE_LEFT=0 BORDER_SIZE_RIGHT=2
327 *
328 * @param[out] buf_ptr Pointer to the source image. Supported data types: F16/F32
329 * @param[in] buf_attrs The attributes of the source image
330 * @param[in] width Width of the valid region of the image
331 * @param[in] height Height of the valid region of the image
332 * @param[in] start_pos_x X coordinate indicating the start point of the valid region
333 * @param[in] start_pos_y Y coordinate indicating the start point of the valid region
334 * @param[in] constant_value Constant value to use to fill the edges
335 */
336SHADER_PARAMS_DECLARATION
Anthony Barbier7068f992017-10-26 15:23:08 +0100337{
Joel Liange5384ff2017-12-06 15:33:28 +0800338 Tensor3DAttributes buf_attrs;
339 uint width;
340 uint height;
341 int start_pos_x;
342 int start_pos_y;
343 float constant_value;
Anthony Barbier7068f992017-10-26 15:23:08 +0100344};
345
Joel Liange5384ff2017-12-06 15:33:28 +0800346#if defined(DATA_TYPE_FP32)
347TENSOR_DECLARATION(1, bufBuffer, float, buf_ptr, buf_shift, 2, writeonly);
348
349void main()
350{
351 ImageIterator buf_iter = CONVERT_TENSOR3D_TO_IMAGE_ITERATOR_NO_STEP(buf_attrs, buf_shift);
352
353 // Update pointer to point to the starting point of the valid region
354 TENSOR_ITERATOR_ADVANCE_IN_BYTES(buf_iter, start_pos_y * int(buf_attrs.stride_y) + start_pos_x * int(buf_attrs.stride_x));
355
356 int total_width = BORDER_SIZE_LEFT + int(width) + BORDER_SIZE_RIGHT;
357 int gid0 = int(gl_GlobalInvocationID.x);
358 int gidH = gid0 - total_width;
359 int gidW = gid0 - BORDER_SIZE_LEFT;
360
361 if(gidH >= 0)
362 {
363 // Handle left border
364 for(int i = 0; i < BORDER_SIZE_LEFT; ++i)
365 {
366 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, -(i + 1), gidH), constant_value);
367 }
368 // Handle right border
369 for(int i = 0; i < BORDER_SIZE_RIGHT; ++i)
370 {
371 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, int(width) + i, gidH), constant_value);
372 }
373 }
374 else
375 {
376 // Handle top border
377 for(int i = 0; i < BORDER_SIZE_TOP; ++i)
378 {
379 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, gidW, -(i + 1)), constant_value);
380 }
381 // Handle bottom border
382 for(int i = 0; i < BORDER_SIZE_BOTTOM; ++i)
383 {
384 STORE(buf_ptr, IMAGE_OFFSET(buf_iter, gidW, int(height) + i), constant_value);
385 }
386 }
387}
388
389#elif defined(DATA_TYPE_FP16)
390TENSOR_DECLARATION(1, bufBuffer, uint, buf_ptr, buf_shift, 2, restrict);
391
Anthony Barbier7068f992017-10-26 15:23:08 +0100392void set_constant(uint offset, int pos)
393{
Joel Liange5384ff2017-12-06 15:33:28 +0800394 vec2 b = LOAD_UNPACK2_HALF(buf_ptr, offset);
Anthony Barbier7068f992017-10-26 15:23:08 +0100395
396 if(pos % 2 == 0)
397 {
398 b.x = constant_value;
399 }
400 else
401 {
402 b.y = constant_value;
403 }
404
Joel Liange5384ff2017-12-06 15:33:28 +0800405 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100406}
407
Anthony Barbier7068f992017-10-26 15:23:08 +0100408void main()
409{
Joel Liange5384ff2017-12-06 15:33:28 +0800410 ImageIterator buf_iter = CONVERT_TENSOR3D_TO_IMAGE_ITERATOR_NO_STEP(buf_attrs, buf_shift);
Anthony Barbier7068f992017-10-26 15:23:08 +0100411
412 int total_width = BORDER_SIZE_LEFT + int(width) + BORDER_SIZE_RIGHT;
413 int gid0 = int(gl_GlobalInvocationID.x);
414 int gidH = gid0 - total_width;
415 int gidW = gid0 - BORDER_SIZE_LEFT;
416
417 // Update pointer to point to the starting point of the valid region
Joel Liange5384ff2017-12-06 15:33:28 +0800418 TENSOR_ITERATOR_ADVANCE_IN_BYTES(buf_iter, start_pos_y * int(buf_attrs.stride_y) + start_pos_x * int(buf_attrs.stride_x));
Anthony Barbier7068f992017-10-26 15:23:08 +0100419
420 vec2 b = vec2(constant_value, constant_value);
421
Anthony Barbier7068f992017-10-26 15:23:08 +0100422 if(gidH >= 0)
423 {
424 // Handle left border
zhenglinf8b41e92017-12-01 18:56:59 +0800425 for(int i = 0; i < BORDER_SIZE_LEFT; ++i)
Anthony Barbier7068f992017-10-26 15:23:08 +0100426 {
Joel Liange5384ff2017-12-06 15:33:28 +0800427 uint offset = IMAGE_OFFSET(buf_iter, -(i + 1), gidH);
zhenglinf8b41e92017-12-01 18:56:59 +0800428 int pos = BORDER_SIZE_LEFT - i - 1;
Anthony Barbier7068f992017-10-26 15:23:08 +0100429
zhenglinf8b41e92017-12-01 18:56:59 +0800430 if(i == 0)
Anthony Barbier7068f992017-10-26 15:23:08 +0100431 {
432 if(pos % 2 == 0)
433 {
434 set_constant(offset, pos);
435 }
436 }
437 else
438 {
439 if(pos % 2 == 0)
440 {
Joel Liange5384ff2017-12-06 15:33:28 +0800441 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100442 }
443 }
444 }
445 // Handle right border
446 for(int i = 0; i < BORDER_SIZE_RIGHT; ++i)
447 {
Joel Liange5384ff2017-12-06 15:33:28 +0800448 uint offset = IMAGE_OFFSET(buf_iter, int(width) + i, gidH);
Anthony Barbier7068f992017-10-26 15:23:08 +0100449 int pos = i + BORDER_SIZE_LEFT + int(width);
450
451 if(i == 0)
452 {
453 if(pos % 2 == 0)
454 {
Joel Liange5384ff2017-12-06 15:33:28 +0800455 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100456 }
457 else
458 {
459 set_constant(offset, pos);
460 }
461 }
462 else
463 {
464 if(pos % 2 == 0)
465 {
Joel Liange5384ff2017-12-06 15:33:28 +0800466 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100467 }
468 }
469 }
470 }
471 else
472 {
473 // Handle top border
zhenglinf8b41e92017-12-01 18:56:59 +0800474 for(int i = 0; i < BORDER_SIZE_TOP; ++i)
Anthony Barbier7068f992017-10-26 15:23:08 +0100475 {
Joel Liange5384ff2017-12-06 15:33:28 +0800476 uint offset = IMAGE_OFFSET(buf_iter, gidW, -(i + 1));
Anthony Barbier7068f992017-10-26 15:23:08 +0100477
478 if(gid0 % 2 == 0)
479 {
Joel Liange5384ff2017-12-06 15:33:28 +0800480 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100481 }
482 }
483 // Handle bottom border
484 for(int i = 0; i < BORDER_SIZE_BOTTOM; ++i)
485 {
Joel Liange5384ff2017-12-06 15:33:28 +0800486 uint offset = IMAGE_OFFSET(buf_iter, gidW, int(height) + i);
Anthony Barbier7068f992017-10-26 15:23:08 +0100487
488 if(gid0 % 2 == 0)
489 {
Joel Liange5384ff2017-12-06 15:33:28 +0800490 STORE_PACK2_HALF(buf_ptr, offset, b);
Anthony Barbier7068f992017-10-26 15:23:08 +0100491 }
492 }
493 }
494}
Joel Liange5384ff2017-12-06 15:33:28 +0800495
Anthony Barbier7068f992017-10-26 15:23:08 +0100496#endif /* DATA_TYPE_FP32 */
Joel Liange5384ff2017-12-06 15:33:28 +0800497
498#endif /* FILL_IMAGE_BORDERS_CONSTANT */