zhenglin | 926d5e1 | 2017-12-21 15:36:50 +0800 | [diff] [blame] | 1 | /* |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
zhenglin | 926d5e1 | 2017-12-21 15:36:50 +0800 | [diff] [blame] | 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 | */ |
| 24 | |
| 25 | layout(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 | |
| 29 | precision mediump float; |
| 30 | #define ADD(x, y) (x) + (y) |
| 31 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 32 | /** This function add two tensors. |
zhenglin | 926d5e1 | 2017-12-21 15:36:50 +0800 | [diff] [blame] | 33 | * |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 34 | * @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 |
zhenglin | 926d5e1 | 2017-12-21 15:36:50 +0800 | [diff] [blame] | 40 | */ |
| 41 | SHADER_PARAMS_DECLARATION |
| 42 | { |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 43 | Tensor3DAttributes src1_attrs; |
| 44 | Tensor3DAttributes src2_attrs; |
| 45 | Tensor3DAttributes dst_attrs; |
zhenglin | 926d5e1 | 2017-12-21 15:36:50 +0800 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | TENSOR_DECLARATION(1, src1Buffer, uvec4, src1_ptr, src1_shift, 4, readonly); |
| 49 | TENSOR_DECLARATION(2, src2Buffer, uvec4, src2_ptr, src2_shift, 4, readonly); |
| 50 | TENSOR_DECLARATION(3, dstBuffer, uvec4, dst_ptr, dst_shift, 4, writeonly); |
| 51 | |
| 52 | void main(void) |
| 53 | { |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 54 | 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); |
zhenglin | 926d5e1 | 2017-12-21 15:36:50 +0800 | [diff] [blame] | 57 | |
| 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 Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 65 | } |