<div dir="ltr">Hi!<br><br>Thank you. I will move all shared code to texcompress_bptc_tmp.h, and send new patch series.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 25, 2018 at 7:47 PM Marek Olšák <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This looks OK, but did you try to build other gallium state trackers?<br>
They don't link with anything in src/mesa, so the build will fail,<br>
because the bptc functions are missing. The solution used for other<br>
formats was to put all functions into header files, see<br>
texcompress_*_tmp.h. Another solution would be to move the functions<br>
to src/util, which is shared by all Mesa components.<br>
<br>
Also, all the function names (like compress_rgb_float) are too<br>
generic. All non-static non-inline function names are global and<br>
shouldn't conflict with anything else in Mesa, so they need to be more<br>
unique. It's generally a good idea to make public inline function<br>
names look unique to minimize name conflicts.<br>
<br>
Marek<br>
<br>
<br>
<br>
On Sat, Jun 23, 2018 at 9:19 AM, Denis Pauk <<a href="mailto:pauk.denis@gmail.com" target="_blank">pauk.denis@gmail.com</a>> wrote:<br>
> Make functions public:<br>
> * fetch_rgba_unorm_from_block<br>
> * fetch_rgb_float_from_block<br>
> * compress_rgba_unorm<br>
> * compress_rgb_float<br>
><br>
> Create decompress functions:<br>
> * decompress_rgba_unorm<br>
> * decompress_rgb_float<br>
><br>
> Functions will be reused in gallium/auxiliary code.<br>
><br>
> v2: Add block decompress function<br>
><br>
> Signed-off-by: Denis Pauk <<a href="mailto:pauk.denis@gmail.com" target="_blank">pauk.denis@gmail.com</a>><br>
> CC: Marek Olšák <<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>><br>
> ---<br>
>  src/mesa/Makefile.sources              |   1 +<br>
>  src/mesa/main/texcompress_bptc.c       | 303 ++++++++++++++++++++++++-<br>
>  src/mesa/main/texcompress_bptc_share.h |  58 +++++<br>
>  3 files changed, 358 insertions(+), 4 deletions(-)<br>
>  create mode 100644 src/mesa/main/texcompress_bptc_share.h<br>
><br>
> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources<br>
> index 00aba0a2f7..d644112e6a 100644<br>
> --- a/src/mesa/Makefile.sources<br>
> +++ b/src/mesa/Makefile.sources<br>
> @@ -216,6 +216,7 @@ MAIN_FILES = \<br>
>         main/texcompress.c \<br>
>         main/texcompress_bptc.c \<br>
>         main/texcompress_bptc.h \<br>
> +       main/texcompress_bptc_share.h \<br>
>         main/texcompress_cpal.c \<br>
>         main/texcompress_cpal.h \<br>
>         main/texcompress_etc.c \<br>
> diff --git a/src/mesa/main/texcompress_bptc.c b/src/mesa/main/texcompress_bptc.c<br>
> index fd37be97f3..74828d63db 100644<br>
> --- a/src/mesa/main/texcompress_bptc.c<br>
> +++ b/src/mesa/main/texcompress_bptc.c<br>
> @@ -29,6 +29,7 @@<br>
>  #include <stdbool.h><br>
>  #include "texcompress.h"<br>
>  #include "texcompress_bptc.h"<br>
> +#include "texcompress_bptc_share.h"<br>
>  #include "util/format_srgb.h"<br>
>  #include "util/half_float.h"<br>
>  #include "texstore.h"<br>
> @@ -535,7 +536,7 @@ apply_rotation(int rotation,<br>
>     result[3] = t;<br>
>  }<br>
><br>
> -static void<br>
> +void<br>
>  fetch_rgba_unorm_from_block(const uint8_t *block,<br>
>                              uint8_t *result,<br>
>                              int texel)<br>
> @@ -657,6 +658,173 @@ fetch_rgba_unorm_from_block(const uint8_t *block,<br>
>     apply_rotation(rotation, result);<br>
>  }<br>
><br>
> +static void<br>
> +decompress_rgba_unorm_block(int src_width, int src_height,<br>
> +                            const uint8_t *block,<br>
> +                            uint8_t *dst_row, int dst_rowstride)<br>
> +{<br>
> +   int mode_num = ffs(block[0]);<br>
> +   const struct bptc_unorm_mode *mode;<br>
> +   int bit_offset, secondary_bit_offset;<br>
> +   int partition_num;<br>
> +   int subset_num;<br>
> +   int rotation;<br>
> +   int index_selection;<br>
> +   int index_bits;<br>
> +   int indices[2];<br>
> +   int index;<br>
> +   int anchors_before_texel;<br>
> +   bool anchor;<br>
> +   uint8_t endpoints[3 * 2][4];<br>
> +   uint32_t subsets;<br>
> +   int component;<br>
> +   unsigned x, y;<br>
> +<br>
> +   if (mode_num == 0) {<br>
> +      /* According to the spec this mode is reserved and shouldn't be used. */<br>
> +      for(y = 0; y < src_height; y += 1) {<br>
> +         uint8_t *result = dst_row;<br>
> +         memset(result, 0, 4 * src_width);<br>
> +         for(x = 0; x < src_width; x += 1) {<br>
> +            result[3] = 0xff;<br>
> +            result += 4;<br>
> +         }<br>
> +         dst_row += dst_rowstride;<br>
> +      }<br>
> +      return;<br>
> +   }<br>
> +<br>
> +   mode = bptc_unorm_modes + mode_num - 1;<br>
> +   bit_offset = mode_num;<br>
> +<br>
> +   partition_num = extract_bits(block, bit_offset, mode->n_partition_bits);<br>
> +   bit_offset += mode->n_partition_bits;<br>
> +<br>
> +   switch (mode->n_subsets) {<br>
> +   case 1:<br>
> +      subsets = 0;<br>
> +      break;<br>
> +   case 2:<br>
> +      subsets = partition_table1[partition_num];<br>
> +      break;<br>
> +   case 3:<br>
> +      subsets = partition_table2[partition_num];<br>
> +      break;<br>
> +   default:<br>
> +      assert(false);<br>
> +      return;<br>
> +   }<br>
> +<br>
> +   if (mode->has_rotation_bits) {<br>
> +      rotation = extract_bits(block, bit_offset, 2);<br>
> +      bit_offset += 2;<br>
> +   } else {<br>
> +      rotation = 0;<br>
> +   }<br>
> +<br>
> +   if (mode->has_index_selection_bit) {<br>
> +      index_selection = extract_bits(block, bit_offset, 1);<br>
> +      bit_offset++;<br>
> +   } else {<br>
> +      index_selection = 0;<br>
> +   }<br>
> +<br>
> +   bit_offset = extract_unorm_endpoints(mode, block, bit_offset, endpoints);<br>
> +<br>
> +   for(y = 0; y < src_height; y += 1) {<br>
> +      uint8_t *result = dst_row;<br>
> +      for(x = 0; x < src_width; x += 1) {<br>
> +         int texel;<br>
> +         texel = x + y * 4;<br>
> +<br>
> +         anchors_before_texel = count_anchors_before_texel(mode->n_subsets,<br>
> +                                                           partition_num,<br>
> +                                                           texel);<br>
> +<br>
> +         /* Calculate the offset to the secondary index */<br>
> +         secondary_bit_offset = (bit_offset +<br>
> +                                 BLOCK_SIZE * BLOCK_SIZE * mode->n_index_bits -<br>
> +                                 mode->n_subsets +<br>
> +                                 mode->n_secondary_index_bits * texel -<br>
> +                                 anchors_before_texel);<br>
> +<br>
> +         /* Calculate the offset to the primary index for this texel */<br>
> +         bit_offset += mode->n_index_bits * texel - anchors_before_texel;<br>
> +<br>
> +         subset_num = (subsets >> (texel * 2)) & 3;<br>
> +<br>
> +         anchor = is_anchor(mode->n_subsets, partition_num, texel);<br>
> +<br>
> +         index_bits = mode->n_index_bits;<br>
> +         if (anchor)<br>
> +            index_bits--;<br>
> +         indices[0] = extract_bits(block, bit_offset, index_bits);<br>
> +<br>
> +         if (mode->n_secondary_index_bits) {<br>
> +            index_bits = mode->n_secondary_index_bits;<br>
> +            if (anchor)<br>
> +               index_bits--;<br>
> +            indices[1] = extract_bits(block, secondary_bit_offset, index_bits);<br>
> +         }<br>
> +<br>
> +         index = indices[index_selection];<br>
> +         index_bits = (index_selection ?<br>
> +                       mode->n_secondary_index_bits :<br>
> +                       mode->n_index_bits);<br>
> +<br>
> +         for (component = 0; component < 3; component++)<br>
> +            result[component] = interpolate(endpoints[subset_num * 2][component],<br>
> +                                            endpoints[subset_num * 2 + 1][component],<br>
> +                                            index,<br>
> +                                            index_bits);<br>
> +<br>
> +         /* Alpha uses the opposite index from the color components */<br>
> +         if (mode->n_secondary_index_bits && !index_selection) {<br>
> +            index = indices[1];<br>
> +            index_bits = mode->n_secondary_index_bits;<br>
> +         } else {<br>
> +            index = indices[0];<br>
> +            index_bits = mode->n_index_bits;<br>
> +         }<br>
> +<br>
> +         result[3] = interpolate(endpoints[subset_num * 2][3],<br>
> +                                 endpoints[subset_num * 2 + 1][3],<br>
> +                                 index,<br>
> +                                 index_bits);<br>
> +<br>
> +         apply_rotation(rotation, result);<br>
> +         result += 4;<br>
> +      }<br>
> +      dst_row += dst_rowstride;<br>
> +   }<br>
> +}<br>
> +<br>
> +void<br>
> +decompress_rgba_unorm(int width, int height,<br>
> +                      const uint8_t *src, int src_rowstride,<br>
> +                      uint8_t *dst, int dst_rowstride)<br>
> +{<br>
> +   int src_row_diff;<br>
> +   int y, x;<br>
> +<br>
> +   if (src_rowstride >= width * 4)<br>
> +      src_row_diff = src_rowstride - ((width + 3) & ~3) * 4;<br>
> +   else<br>
> +      src_row_diff = 0;<br>
> +<br>
> +   for (y = 0; y < height; y += BLOCK_SIZE) {<br>
> +      for (x = 0; x < width; x += BLOCK_SIZE) {<br>
> +         decompress_rgba_unorm_block(MIN2(width - x, BLOCK_SIZE),<br>
> +                                     MIN2(height - y, BLOCK_SIZE),<br>
> +                                     src,<br>
> +                                     dst + x * 4 + y * dst_rowstride,<br>
> +                                     dst_rowstride);<br>
> +         src += BLOCK_BYTES;<br>
> +      }<br>
> +      src += src_row_diff;<br>
> +   }<br>
> +}<br>
> +<br>
>  static void<br>
>  fetch_bptc_rgba_unorm_bytes(const GLubyte *map,<br>
>                              GLint rowStride, GLint i, GLint j,<br>
> @@ -840,7 +1008,7 @@ finish_signed_unquantize(int32_t value)<br>
>        return value * 31 / 32;<br>
>  }<br>
><br>
> -static void<br>
> +void<br>
>  fetch_rgb_float_from_block(const uint8_t *block,<br>
>                             float *result,<br>
>                             int texel,<br>
> @@ -921,6 +1089,133 @@ fetch_rgb_float_from_block(const uint8_t *block,<br>
>     result[3] = 1.0f;<br>
>  }<br>
><br>
> +static void<br>
> +decompress_rgb_float_block(unsigned src_width, unsigned src_height,<br>
> +                           const uint8_t *block,<br>
> +                           float *dst_row, unsigned dst_rowstride,<br>
> +                           bool is_signed)<br>
> +{<br>
> +   int mode_num;<br>
> +   const struct bptc_float_mode *mode;<br>
> +   int bit_offset;<br>
> +   int partition_num;<br>
> +   int subset_num;<br>
> +   int index_bits;<br>
> +   int index;<br>
> +   int anchors_before_texel;<br>
> +   int32_t endpoints[2 * 2][3];<br>
> +   uint32_t subsets;<br>
> +   int n_subsets;<br>
> +   int component;<br>
> +   int32_t value;<br>
> +   unsigned x, y;<br>
> +<br>
> +   if (block[0] & 0x2) {<br>
> +      mode_num = (((block[0] >> 1) & 0xe) | (block[0] & 1)) + 2;<br>
> +      bit_offset = 5;<br>
> +   } else {<br>
> +      mode_num = block[0] & 3;<br>
> +      bit_offset = 2;<br>
> +   }<br>
> +<br>
> +   mode = bptc_float_modes + mode_num;<br>
> +<br>
> +   if (mode->reserved) {<br>
> +      for(y = 0; y < src_height; y += 1) {<br>
> +         float *result = dst_row;<br>
> +         memset(result, 0, sizeof result[0] * 4 * src_width);<br>
> +         for(x = 0; x < src_width; x += 1) {<br>
> +            result[3] = 1.0f;<br>
> +            result += 4;<br>
> +         }<br>
> +         dst_row += dst_rowstride / sizeof dst_row[0];<br>
> +      }<br>
> +      return;<br>
> +   }<br>
> +<br>
> +   bit_offset = extract_float_endpoints(mode, block, bit_offset,<br>
> +                                        endpoints, is_signed);<br>
> +<br>
> +   if (mode->n_partition_bits) {<br>
> +      partition_num = extract_bits(block, bit_offset, mode->n_partition_bits);<br>
> +      bit_offset += mode->n_partition_bits;<br>
> +<br>
> +      subsets = partition_table1[partition_num];<br>
> +      n_subsets = 2;<br>
> +   } else {<br>
> +      partition_num = 0;<br>
> +      subsets = 0;<br>
> +      n_subsets = 1;<br>
> +   }<br>
> +<br>
> +   for(y = 0; y < src_height; y += 1) {<br>
> +      float *result = dst_row;<br>
> +      for(x = 0; x < src_width; x += 1) {<br>
> +         int texel;<br>
> +<br>
> +         texel = x + y * 4;<br>
> +<br>
> +         anchors_before_texel =<br>
> +            count_anchors_before_texel(n_subsets, partition_num, texel);<br>
> +<br>
> +         /* Calculate the offset to the primary index for this texel */<br>
> +         bit_offset += mode->n_index_bits * texel - anchors_before_texel;<br>
> +<br>
> +         subset_num = (subsets >> (texel * 2)) & 3;<br>
> +<br>
> +         index_bits = mode->n_index_bits;<br>
> +         if (is_anchor(n_subsets, partition_num, texel))<br>
> +            index_bits--;<br>
> +         index = extract_bits(block, bit_offset, index_bits);<br>
> +<br>
> +         for (component = 0; component < 3; component++) {<br>
> +            value = interpolate(endpoints[subset_num * 2][component],<br>
> +                                endpoints[subset_num * 2 + 1][component],<br>
> +                                index,<br>
> +                                mode->n_index_bits);<br>
> +<br>
> +            if (is_signed)<br>
> +               value = finish_signed_unquantize(value);<br>
> +            else<br>
> +               value = finish_unsigned_unquantize(value);<br>
> +<br>
> +            result[component] = _mesa_half_to_float(value);<br>
> +         }<br>
> +<br>
> +         result[3] = 1.0f;<br>
> +         result += 4;<br>
> +      }<br>
> +      dst_row += dst_rowstride / sizeof dst_row[0];<br>
> +   }<br>
> +}<br>
> +<br>
> +void<br>
> +decompress_rgb_float(int width, int height,<br>
> +                      const uint8_t *src, int src_rowstride,<br>
> +                      float *dst, int dst_rowstride, bool is_signed)<br>
> +{<br>
> +   int src_row_diff;<br>
> +   int y, x;<br>
> +<br>
> +   if (src_rowstride >= width * 4)<br>
> +      src_row_diff = src_rowstride - ((width + 3) & ~3) * 4;<br>
> +   else<br>
> +      src_row_diff = 0;<br>
> +<br>
> +   for (y = 0; y < height; y += BLOCK_SIZE) {<br>
> +      for (x = 0; x < width; x += BLOCK_SIZE) {<br>
> +         decompress_rgb_float_block(MIN2(width - x, BLOCK_SIZE),<br>
> +                                    MIN2(height - y, BLOCK_SIZE),<br>
> +                                    src,<br>
> +                                    (dst + x * 4 +<br>
> +                                     (y * dst_rowstride / sizeof dst[0])),<br>
> +                                    dst_rowstride, is_signed);<br>
> +         src += BLOCK_BYTES;<br>
> +      }<br>
> +      src += src_row_diff;<br>
> +   }<br>
> +}<br>
> +<br>
>  static void<br>
>  fetch_bptc_rgb_float(const GLubyte *map,<br>
>                       GLint rowStride, GLint i, GLint j,<br>
> @@ -1247,7 +1542,7 @@ compress_rgba_unorm_block(int src_width, int src_height,<br>
>                               endpoints);<br>
>  }<br>
><br>
> -static void<br>
> +void<br>
>  compress_rgba_unorm(int width, int height,<br>
>                      const uint8_t *src, int src_rowstride,<br>
>                      uint8_t *dst, int dst_rowstride)<br>
> @@ -1555,7 +1850,7 @@ compress_rgb_float_block(int src_width, int src_height,<br>
>                             endpoints);<br>
>  }<br>
><br>
> -static void<br>
> +void<br>
>  compress_rgb_float(int width, int height,<br>
>                     const float *src, int src_rowstride,<br>
>                     uint8_t *dst, int dst_rowstride,<br>
> diff --git a/src/mesa/main/texcompress_bptc_share.h b/src/mesa/main/texcompress_bptc_share.h<br>
> new file mode 100644<br>
> index 0000000000..b62e58806f<br>
> --- /dev/null<br>
> +++ b/src/mesa/main/texcompress_bptc_share.h<br>
> @@ -0,0 +1,58 @@<br>
> +/*<br>
> + * Copyright (C) 2014 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +#ifndef TEXCOMPRESS_BPTC_SHARE_H<br>
> +#define TEXCOMPRESS_BPTC_SHARE_H<br>
> +<br>
> +void<br>
> +fetch_rgba_unorm_from_block(const uint8_t *block,<br>
> +                            uint8_t *result,<br>
> +                            int texel);<br>
> +void<br>
> +fetch_rgb_float_from_block(const uint8_t *block,<br>
> +                           float *result,<br>
> +                           int texel,<br>
> +                           bool is_signed);<br>
> +<br>
> +void<br>
> +compress_rgb_float(int width, int height,<br>
> +                   const float *src, int src_rowstride,<br>
> +                   uint8_t *dst, int dst_rowstride,<br>
> +                   bool is_signed);<br>
> +<br>
> +void<br>
> +compress_rgba_unorm(int width, int height,<br>
> +                    const uint8_t *src, int src_rowstride,<br>
> +                    uint8_t *dst, int dst_rowstride);<br>
> +<br>
> +void<br>
> +decompress_rgba_unorm(int width, int height,<br>
> +                      const uint8_t *src, int src_rowstride,<br>
> +                      uint8_t *dst, int dst_rowstride);<br>
> +<br>
> +void<br>
> +decompress_rgb_float(int width, int height,<br>
> +                      const uint8_t *src, int src_rowstride,<br>
> +                      float *dst, int dst_rowstride, bool is_signed);<br>
> +<br>
> +#endif<br>
> --<br>
> 2.17.1<br>
><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Best regards,<br>                  Denis.</div>