Mesa (master): mesa: Reuse util_format's unpack_8unorm.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021
Module: Mesa
Branch: master
Commit: 696b552435ea9ec4ed35ceca91d33f686a5e056d
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=696b552435ea9ec4ed35ceca91d33f686a5e056d
Author: Eric Anholt <eric at anholt.net>
Date: Thu Nov 7 11:35:10 2019 -0800
mesa: Reuse util_format's unpack_8unorm.
Drops ~8k of compiled text from all GL drivers.
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>
---
src/mesa/main/format_unpack.py | 102 -----------------------------------------
src/mesa/main/pack.c | 28 +++++++++++
2 files changed, 28 insertions(+), 102 deletions(-)
diff --git a/src/mesa/main/format_unpack.py b/src/mesa/main/format_unpack.py
index e1a9a8d76b2..3cae58d0078 100644
--- a/src/mesa/main/format_unpack.py
+++ b/src/mesa/main/format_unpack.py
@@ -68,68 +68,6 @@ for f in formats:
rgb_formats.append(f)
%>
-/* ubyte packing functions */
-
-%for f in rgb_formats:
- %if not f.is_normalized():
- <% continue %>
- %endif
-
-static inline void
-unpack_ubyte_${f.short_name()}(const void *void_src, uint8_t dst[4])
-{
- ${f.datatype()} *src = (${f.datatype()} *)void_src;
- %if f.layout == parser.PACKED:
- %for c in f.channels:
- %if c.type != 'x':
- ${c.datatype()} ${c.name} = UNPACK(*src, ${c.shift}, ${c.size});
- %endif
- %endfor
- %elif f.layout == parser.ARRAY:
- %for (i, c) in enumerate(f.channels):
- %if c.type != 'x':
- ${c.datatype()} ${c.name} = src[${i}];
- %endif
- %endfor
- %else:
- <% assert False %>
- %endif
-
- %for i in range(4):
- <% s = f.swizzle[i] %>
- %if 0 <= s and s <= parser.Swizzle.SWIZZLE_W:
- <% c = f.channels[s] %>
- %if c.type == parser.UNSIGNED:
- %if f.colorspace == 'srgb' and c.name in 'rgb':
- <% assert c.size == 8 %>
- dst[${i}] = util_format_srgb_to_linear_8unorm(${c.name});
- %else:
- dst[${i}] = _mesa_unorm_to_unorm(${c.name}, ${c.size}, 8);
- %endif
- %elif c.type == parser.SIGNED:
- dst[${i}] = _mesa_snorm_to_unorm(${c.name}, ${c.size}, 8);
- %elif c.type == parser.FLOAT:
- %if c.size == 32:
- dst[${i}] = _mesa_float_to_unorm(${c.name}, 8);
- %elif c.size == 16:
- dst[${i}] = _mesa_half_to_unorm(${c.name}, 8);
- %else:
- <% assert False %>
- %endif
- %else:
- <% assert False %>
- %endif
- %elif s == parser.Swizzle.SWIZZLE_ZERO:
- dst[${i}] = 0;
- %elif s == parser.Swizzle.SWIZZLE_ONE:
- dst[${i}] = 255;
- %else:
- <% assert False %>
- %endif
- %endfor
-}
-%endfor
-
/* integer packing functions */
%for f in rgb_formats:
@@ -175,46 +113,6 @@ unpack_int_${f.short_name()}(const void *void_src, uint32_t dst[4])
%endfor
-void
-_mesa_unpack_ubyte_rgba_row(mesa_format format, uint32_t n,
- const void *src, uint8_t dst[][4])
-{
- uint8_t *s = (uint8_t *)src;
- uint32_t i;
-
- switch (format) {
-%for f in rgb_formats:
- %if not f.is_normalized():
- <% continue %>
- %endif
-
- case ${f.name}:
- for (i = 0; i < n; ++i) {
- unpack_ubyte_${f.short_name()}(s, dst[i]);
- s += ${f.block_size() // 8};
- }
- break;
-%endfor
- default:
- /* get float values, convert to ubyte */
- {
- float *tmp = malloc(n * 4 * sizeof(float));
- if (tmp) {
- uint32_t i;
- _mesa_unpack_rgba_row(format, n, src, (float (*)[4]) tmp);
- for (i = 0; i < n; i++) {
- dst[i][0] = _mesa_float_to_unorm(tmp[i*4+0], 8);
- dst[i][1] = _mesa_float_to_unorm(tmp[i*4+1], 8);
- dst[i][2] = _mesa_float_to_unorm(tmp[i*4+2], 8);
- dst[i][3] = _mesa_float_to_unorm(tmp[i*4+3], 8);
- }
- free(tmp);
- }
- }
- break;
- }
-}
-
void
_mesa_unpack_uint_rgba_row(mesa_format format, uint32_t n,
const void *src, uint32_t dst[][4])
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 4fb0b17aea8..4cc843613a0 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -1633,6 +1633,34 @@ _mesa_unpack_color_index_to_rgba_ubyte(struct gl_context *ctx, GLuint dims,
return dst;
}
+void
+_mesa_unpack_ubyte_rgba_row(mesa_format format, uint32_t n,
+ const void *src, uint8_t dst[][4])
+{
+ const struct util_format_unpack_description *unpack =
+ util_format_unpack_description((enum pipe_format)format);
+
+ if (unpack->unpack_rgba_8unorm) {
+ unpack->unpack_rgba_8unorm((uint8_t *)dst, 0, src, 0, n, 1);
+ } else {
+ /* get float values, convert to ubyte */
+ {
+ float *tmp = malloc(n * 4 * sizeof(float));
+ if (tmp) {
+ uint32_t i;
+ _mesa_unpack_rgba_row(format, n, src, (float (*)[4]) tmp);
+ for (i = 0; i < n; i++) {
+ dst[i][0] = _mesa_float_to_unorm(tmp[i*4+0], 8);
+ dst[i][1] = _mesa_float_to_unorm(tmp[i*4+1], 8);
+ dst[i][2] = _mesa_float_to_unorm(tmp[i*4+2], 8);
+ dst[i][3] = _mesa_float_to_unorm(tmp[i*4+3], 8);
+ }
+ free(tmp);
+ }
+ }
+ }
+}
+
/**
* Unpack a 2D rect of pixels returning float RGBA colors.
* \param format the source image format
More information about the mesa-commit
mailing list