Mesa (master): mesa/main: Replace float pack function with util_format_pack_rgba().
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jan 19 20:20:00 UTC 2021
Module: Mesa
Branch: master
Commit: 23bb92c4f683f5e286af8f5c1bfc50204bd5ea1e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=23bb92c4f683f5e286af8f5c1bfc50204bd5ea1e
Author: Eric Anholt <eric at anholt.net>
Date: Fri Jan 15 12:22:48 2021 -0800
mesa/main: Replace float pack function with util_format_pack_rgba().
Less main-specific code when we're pulling in util/ formats anyway. Drops
about 20kb from Mesa drivers.
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8532>
---
src/mesa/main/format_pack.h | 8 +++-
src/mesa/main/format_pack.py | 110 -------------------------------------------
2 files changed, 6 insertions(+), 112 deletions(-)
diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
index ea3ae1727ce..15b065611e5 100644
--- a/src/mesa/main/format_pack.h
+++ b/src/mesa/main/format_pack.h
@@ -27,6 +27,7 @@
#define FORMAT_PACK_H
+#include "util/format/u_format.h"
#include "formats.h"
#ifdef __cplusplus
@@ -58,9 +59,12 @@ extern mesa_pack_ubyte_stencil_func
_mesa_get_pack_ubyte_stencil_func(mesa_format format);
-extern void
+static inline void
_mesa_pack_float_rgba_row(mesa_format format, uint32_t n,
- const float src[][4], void *dst);
+ const float src[][4], void *dst)
+{
+ util_format_pack_rgba(format, dst, src, n);
+}
extern void
_mesa_pack_ubyte_rgba_row(mesa_format format, uint32_t n,
diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
index 30b805738ce..8af349b4b66 100644
--- a/src/mesa/main/format_pack.py
+++ b/src/mesa/main/format_pack.py
@@ -213,86 +213,6 @@ pack_uint_${f.short_name()}(const uint32_t src[4], void *dst)
}
%endfor
-/* float packing functions */
-
-%for f in rgb_formats:
- %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
- <% continue %>
- %elif f.is_int() and not f.is_normalized():
- <% continue %>
- %elif f.is_compressed():
- <% continue %>
- %endif
-
-static inline void
-pack_float_${f.short_name()}(const float src[4], void *dst)
-{
- %for (i, c) in enumerate(f.channels):
- <% i = f.swizzle.inverse()[i] %>
- %if c.type == 'x':
- <% continue %>
- %endif
-
- ${c.datatype()} ${c.name} =
- %if c.type == parser.UNSIGNED:
- %if f.colorspace == 'srgb' and c.name in 'rgb':
- <% assert c.size == 8 %>
- util_format_linear_float_to_srgb_8unorm(src[${i}]);
- %else:
- _mesa_float_to_unorm(src[${i}], ${c.size});
- %endif
- %elif c.type == parser.SIGNED:
- _mesa_float_to_snorm(src[${i}], ${c.size});
- %elif c.type == parser.FLOAT:
- %if c.size == 32:
- src[${i}];
- %elif c.size == 16:
- _mesa_float_to_half(src[${i}]);
- %else:
- <% assert False %>
- %endif
- %else:
- <% assert False %>
- %endif
- %endfor
-
- %if f.layout == parser.ARRAY:
- ${f.datatype()} *d = (${f.datatype()} *)dst;
- %for (i, c) in enumerate(f.channels):
- %if c.type == 'x':
- <% continue %>
- %endif
- d[${i}] = ${c.name};
- %endfor
- %elif f.layout == parser.PACKED:
- ${f.datatype()} d = 0;
- %for (i, c) in enumerate(f.channels):
- %if c.type == 'x':
- <% continue %>
- %endif
- d |= PACK(${c.name}, ${c.shift}, ${c.size});
- %endfor
- (*(${f.datatype()} *)dst) = d;
- %else:
- <% assert False %>
- %endif
-}
-%endfor
-
-static inline void
-pack_float_r9g9b9e5_float(const float src[4], void *dst)
-{
- uint32_t *d = (uint32_t *) dst;
- *d = float3_to_rgb9e5(src);
-}
-
-static inline void
-pack_float_r11g11b10_float(const float src[4], void *dst)
-{
- uint32_t *d = (uint32_t *) dst;
- *d = float3_to_r11g11b10f(src);
-}
-
/**
* Pack a row of uint8_t rgba[4] values to the destination.
@@ -354,36 +274,6 @@ _mesa_pack_uint_rgba_row(mesa_format format, uint32_t n,
}
}
-/**
- * Pack a row of float rgba[4] values to the destination.
- */
-void
-_mesa_pack_float_rgba_row(mesa_format format, uint32_t n,
- const float src[][4], void *dst)
-{
- uint32_t i;
- uint8_t *d = dst;
-
- switch (format) {
-%for f in rgb_formats:
- %if f.is_compressed():
- <% continue %>
- %elif f.is_int() and not f.is_normalized():
- <% continue %>
- %endif
-
- case ${f.name}:
- for (i = 0; i < n; ++i) {
- pack_float_${f.short_name()}(src[i], d);
- d += ${f.block_size() // 8};
- }
- break;
-%endfor
- default:
- assert(!"Invalid format");
- }
-}
-
/**
* Pack a 2D image of ubyte RGBA pixels in the given format.
* \param srcRowStride source image row stride in bytes
More information about the mesa-commit
mailing list