From c5114d33293e3124c04655a6f50df5394c424fd6 Mon Sep 17 00:00:00 2001 From: Joel Liang Date: Mon, 4 Dec 2017 15:30:53 +0800 Subject: APPBROWSER-331: Code refactoring for absdiff shader and fix the example running issue The 8-bits unsigned integer pack/unpack functions have been removed accidentally. Added new pack/unpack functions to the new common shader code. Change-Id: I0ef4507b1758f29686b1dadb76781e4f1f220249 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/111637 Reviewed-by: Stephen Li Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com Reviewed-by: Georgios Pinitas Reviewed-by: Anthony Barbier --- src/core/GLES_COMPUTE/cs_shaders/absdiff.cs | 61 ++++++++++++----------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'src/core/GLES_COMPUTE/cs_shaders/absdiff.cs') diff --git a/src/core/GLES_COMPUTE/cs_shaders/absdiff.cs b/src/core/GLES_COMPUTE/cs_shaders/absdiff.cs index f6113e13eb..d06de3a7b6 100644 --- a/src/core/GLES_COMPUTE/cs_shaders/absdiff.cs +++ b/src/core/GLES_COMPUTE/cs_shaders/absdiff.cs @@ -23,49 +23,38 @@ */ layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in; -#include "helpers.h" -layout(std140) uniform shader_params -{ - IMAGE_PARAM_DECLARATION(src1); - IMAGE_PARAM_DECLARATION(src2); - IMAGE_PARAM_DECLARATION(dst); -}; - -BUFFER_DECLARATION(src1, 1, uint, readonly); -BUFFER_DECLARATION(src2, 2, uint, readonly); -BUFFER_DECLARATION(dst, 3, uint, writeonly); +#include "helpers_cs.h" /** Calculate the absolute difference of two input images. * - * @param[in] src1_ptr Pointer to the first source image. Supported data types: U8 - * @param[in] src1_stride_x Stride of the first source image in X dimension (in bytes) - * @param[in] src1_step_x src_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] src1_stride_y Stride of the first source image in Y dimension (in bytes) - * @param[in] src1_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] src1_offset_first_element_in_bytes The offset of the first element in the first source image - * @param[in] src2_ptr Pointer to the second source image. Supported data types: Same as @p in1_ptr - * @param[in] src2_stride_x Stride of the second source image in X dimension (in bytes) - * @param[in] src2_step_x src_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] src2_stride_y Stride of the second source image in Y dimension (in bytes) - * @param[in] src2_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] src2_offset_first_element_in_bytes The offset of the first element in the second source image - * @param[out] dst_ptr Pointer to the destination image. Supported data types: Same as @p in1_ptr - * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) - * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) - * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image + * @param[in] src1_ptr Pointer to the first source image. Supported data types: U8 + * @param[in] src1_attrs The attributes of the first source image + * @param[in] src2_ptr Pointer to the second source image. Supported data types: Same as @p in1_ptr + * @param[in] src2_attrs The attributes of the second source image + * @param[out] dst_ptr Pointer to the destination image. Supported data types: Same as @p in1_ptr + * @param[in] dst_attrs The attributes of the destination image */ +SHADER_PARAMS_DECLARATION +{ + ImageAttributes src1_attrs; + ImageAttributes src2_attrs; + ImageAttributes dst_attrs; +}; + +TENSOR_DECLARATION(1, src1Buffer, uint, src1_ptr, src1_shift, 2, readonly); +TENSOR_DECLARATION(2, src2Buffer, uint, src2_ptr, src2_shift, 2, readonly); +TENSOR_DECLARATION(3, dstBuffer, uint, dst_ptr, dst_shift, 2, writeonly); + void main(void) { - Image src1 = CONVERT_TO_IMAGE_STRUCT(src1); - Image src2 = CONVERT_TO_IMAGE_STRUCT(src2); - Image dst = CONVERT_TO_IMAGE_STRUCT(dst); + ImageIterator src1_iter = CONVERT_TO_IMAGE_ITERATOR(src1_attrs, src1_shift); + ImageIterator src2_iter = CONVERT_TO_IMAGE_ITERATOR(src2_attrs, src2_shift); + ImageIterator dst_iter = CONVERT_TO_IMAGE_ITERATOR(dst_attrs, dst_shift); - uvec4 tmp1 = UNPACK(LOAD4(src1, CURRENT_OFFSET(src1)), uint, uvec4); - uvec4 tmp2 = UNPACK(LOAD4(src2, CURRENT_OFFSET(src2)), uint, uvec4); - uvec4 diff = uvec4(abs(ivec4(tmp1 - tmp2))); + lowp uvec4 tmp1 = LOAD_UNPACK4_CURRENT_ITEM_U8(src1_ptr, src1_iter); + lowp uvec4 tmp2 = LOAD_UNPACK4_CURRENT_ITEM_U8(src2_ptr, src2_iter); + lowp uvec4 diff = uvec4(abs(ivec4(tmp1 - tmp2))); - STORE4(dst, CURRENT_OFFSET(dst), PACK(diff, uvec4, uint)); + STORE_PACK4_CURRENT_ITEM_U8(dst_ptr, dst_iter, diff); } -- cgit v1.2.1