blob: 2ab6d5eac54c55a1b6dbc4f59c9ffe124d62453d [file] [log] [blame]
zhenglin926d5e12017-12-21 15:36:50 +08001/*
Frank Lei4406fd62018-02-01 14:47:14 +08002 * Copyright (c) 2016-2018 ARM Limited.
zhenglin926d5e12017-12-21 15:36:50 +08003 *
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 */
24
25layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in;
26
27#include "helpers_cs.h"
28
29precision mediump float;
30#define ADD(x, y) (x) + (y)
31
Frank Lei4406fd62018-02-01 14:47:14 +080032/** This function add two tensors.
zhenglin926d5e12017-12-21 15:36:50 +080033 *
Frank Lei4406fd62018-02-01 14:47:14 +080034 * @param[in] src1_ptr Pointer to the first source tensor. Supported data types: F16
35 * @param[in] src1_attrs The attributes of the first source tensor
36 * @param[in] src2_ptr Pointer to the second source tensor. Supported data types: Same as @p src1_ptr
37 * @param[in] src2_attrs The attributes of the second source tensor
38 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: Same as @p src1_ptr
39 * @param[in] dst_attrs The attributes of the destination tensor
zhenglin926d5e12017-12-21 15:36:50 +080040 */
41SHADER_PARAMS_DECLARATION
42{
Frank Lei4406fd62018-02-01 14:47:14 +080043 Tensor3DAttributes src1_attrs;
44 Tensor3DAttributes src2_attrs;
45 Tensor3DAttributes dst_attrs;
zhenglin926d5e12017-12-21 15:36:50 +080046};
47
48TENSOR_DECLARATION(1, src1Buffer, uvec4, src1_ptr, src1_shift, 4, readonly);
49TENSOR_DECLARATION(2, src2Buffer, uvec4, src2_ptr, src2_shift, 4, readonly);
50TENSOR_DECLARATION(3, dstBuffer, uvec4, dst_ptr, dst_shift, 4, writeonly);
51
52void main(void)
53{
Frank Lei4406fd62018-02-01 14:47:14 +080054 Tensor3DIterator src1_iter = CONVERT_TO_TENSOR3D_ITERATOR(src1_attrs, src1_shift);
55 Tensor3DIterator src2_iter = CONVERT_TO_TENSOR3D_ITERATOR(src2_attrs, src2_shift);
56 Tensor3DIterator dst_iter = CONVERT_TO_TENSOR3D_ITERATOR(dst_attrs, dst_shift);
zhenglin926d5e12017-12-21 15:36:50 +080057
58 vec4 tmp1[2] = LOAD_UNPACK8_CURRENT_ITEM_HALF(src1_ptr, src1_iter);
59 vec4 tmp2[2] = LOAD_UNPACK8_CURRENT_ITEM_HALF(src2_ptr, src2_iter);
60 vec4 addition[2];
61 addition[0] = ADD(tmp1[0], tmp2[0]);
62 addition[1] = ADD(tmp1[1], tmp2[1]);
63
64 STORE_PACK8_CURRENT_ITEM_HALF(dst_ptr, dst_iter, addition);
Frank Lei4406fd62018-02-01 14:47:14 +080065}