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@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8532>
This commit is contained in:
Eric Anholt 2021-01-15 12:22:48 -08:00 committed by Marge Bot
parent f1403d66d4
commit 23bb92c4f6
2 changed files with 6 additions and 112 deletions

View File

@ -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,

View File

@ -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