zhenglin | 0fb6cf5 | 2017-12-12 15:56:09 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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 | |
| 31 | /** Apply normalize_planar_yuv layer. |
| 32 | * |
| 33 | * @param[in] src_ptr Pointer to the first source tensor. Supported data types: F16 |
| 34 | * @param[in] src_attrs The attributes of the source tensor |
| 35 | * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 36 | * @param[in] dst_attrs The attributes of the destination tensor |
| 37 | * @param[in] mean_ptr Pointer to the mean source tensor. Supported data types: same as @p src_ptr |
| 38 | * @param[in] mean_attrs The attributes of the mean tensor |
| 39 | * @param[in] sd_ptr Standard deviation values tensor,pointer to the sd tensor. Supported data types: same as @p src_ptr |
| 40 | * @param[in] sd_attrs The attributes of the sd tensor |
| 41 | */ |
| 42 | SHADER_PARAMS_DECLARATION |
| 43 | { |
| 44 | Tensor3DAttributes src_attrs; |
| 45 | Tensor3DAttributes dst_attrs; |
| 46 | VectorAttributes mean_attrs; |
| 47 | VectorAttributes sd_attrs; |
| 48 | }; |
| 49 | |
| 50 | TENSOR_DECLARATION(1, srcBuffer, uvec2, src_ptr, src_shift, 3, readonly); |
| 51 | TENSOR_DECLARATION(2, dstBuffer, uvec2, dst_ptr, dst_shift, 3, writeonly); |
| 52 | TENSOR_DECLARATION(3, meanBuffer, uvec2, mean_ptr, mean_shift, 3, readonly); |
| 53 | TENSOR_DECLARATION(4, sdBuffer, uvec2, sd_ptr, sd_shift, 3, readonly); |
| 54 | |
| 55 | void main(void) |
| 56 | { |
| 57 | Tensor3DIterator src_iter = CONVERT_TO_TENSOR3D_ITERATOR(src_attrs, src_shift); |
| 58 | Tensor3DIterator dst_iter = CONVERT_TO_TENSOR3D_ITERATOR(dst_attrs, dst_shift); |
| 59 | VectorIterator mean_iter = CONVERT_TO_VECTOR_ITERATOR(mean_attrs, mean_shift); |
| 60 | VectorIterator sd_iter = CONVERT_TO_VECTOR_ITERATOR(sd_attrs, sd_shift); |
| 61 | |
| 62 | vec4 unpacked_s[3]; |
| 63 | vec4 tmp; |
| 64 | vec4 result; |
| 65 | |
| 66 | uint current_slice = gl_GlobalInvocationID.z; |
| 67 | unpacked_s[0] = LOAD_UNPACK4_CURRENT_ITEM_HALF(src_ptr, src_iter); |
| 68 | unpacked_s[1] = LOAD_UNPACK4_HALF(mean_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(mean_iter, current_slice * mean_attrs.stride_x)); |
| 69 | unpacked_s[2] = LOAD_UNPACK4_HALF(sd_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(sd_iter, current_slice * sd_attrs.stride_x)); |
| 70 | |
| 71 | if((current_slice % uint(4)) == uint(0)) |
| 72 | { |
| 73 | tmp = unpacked_s[0] - unpacked_s[1].x; |
| 74 | result = tmp / unpacked_s[2].x; |
| 75 | |
| 76 | STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); |
| 77 | } |
| 78 | else if((current_slice % uint(4)) == uint(1)) |
| 79 | { |
| 80 | tmp = unpacked_s[0] - unpacked_s[1].y; |
| 81 | result = tmp / unpacked_s[2].y; |
| 82 | |
| 83 | STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); |
| 84 | } |
| 85 | else if((current_slice % uint(4)) == uint(2)) |
| 86 | { |
| 87 | tmp = unpacked_s[0] - unpacked_s[1].z; |
| 88 | result = tmp / unpacked_s[2].z; |
| 89 | |
| 90 | STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | tmp = unpacked_s[0] - unpacked_s[1].w; |
| 95 | result = tmp / unpacked_s[2].w; |
| 96 | |
| 97 | STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); |
| 98 | } |
| 99 | } |