aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Liang <joel.liang@arm.com>2017-12-04 15:30:53 +0800
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:41:58 +0000
commitc5114d33293e3124c04655a6f50df5394c424fd6 (patch)
tree937b042a7e8682c5eae8ec3e48de0772654501b6
parentf6a43c576e4eb731e5e0fa70ce4a0d3bd6a01a61 (diff)
downloadComputeLibrary-c5114d33293e3124c04655a6f50df5394c424fd6.tar.gz
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 <stephen.li@arm.com> Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
-rw-r--r--src/core/GLES_COMPUTE/cs_shaders/absdiff.cs61
-rw-r--r--src/core/GLES_COMPUTE/cs_shaders/helpers_cs.h41
2 files changed, 66 insertions, 36 deletions
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);
}
diff --git a/src/core/GLES_COMPUTE/cs_shaders/helpers_cs.h b/src/core/GLES_COMPUTE/cs_shaders/helpers_cs.h
index 55a598354a..31deaf67e3 100644
--- a/src/core/GLES_COMPUTE/cs_shaders/helpers_cs.h
+++ b/src/core/GLES_COMPUTE/cs_shaders/helpers_cs.h
@@ -393,4 +393,45 @@ mediump vec4[2] unpack8_half(highp uvec4 packed_data)
#define LOAD_UNPACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) LOAD_UNPACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
#define STORE_PACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) STORE_PACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
+/** Converting the uvec4 object to 4 low-precision uint values and packing into a uint object
+ *
+ * @param[in] data The uvec4 object to be packed
+ *
+ * @return The packed uint object
+ */
+highp uint pack4_u8(lowp uvec4 data)
+{
+ highp uint r = uint(0);
+
+ for(int i = 0; i < 4; i++)
+ {
+ r |= data[i] << uint(i * 8);
+ }
+
+ return r;
+}
+
+/** Unpacking the uint object to 4 low-precision uint values and converting to a uvec4 object
+ *
+ * @param[in] packed_data The uint object to be unpacked
+ *
+ * @return The unpacked uvec4 object
+ */
+lowp uvec4 unpack4_u8(highp uint packed_data)
+{
+ lowp uvec4 uvec;
+
+ for(int i = 0; i < 4; i++)
+ {
+ uvec[i] = (packed_data >> uint(i * 8)) & uint(0xFF);
+ }
+
+ return uvec;
+}
+
+#define LOAD_UNPACK4_U8(tensor_ptr, offset) unpack4_u8(uint(LOAD(tensor_ptr, offset)))
+#define STORE_PACK4_U8(tensor_ptr, offset, data) STORE(tensor_ptr, offset, pack4_u8(data))
+#define LOAD_UNPACK4_CURRENT_ITEM_U8(tensor_ptr, tensor_iter) LOAD_UNPACK4_U8(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
+#define STORE_PACK4_CURRENT_ITEM_U8(tensor_ptr, tensor_iter, data) STORE_PACK4_U8(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
+
#endif // ARM_COMPUTE_HELPER_CS_H