util: Switch the non-block formats to unpacking rgba rows instead of rects.

We have only a few callers of unpack that do rects, so add a helper that
iterates over y adding the strides.  This saves us 36kb of generated code
and means that adding cpu-specific variants for RGBA format unpack will be
much simpler.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10014>
This commit is contained in:
Eric Anholt
2021-04-02 14:35:01 -07:00
committed by Marge Bot
parent 921b05f582
commit 2b5178ee48
11 changed files with 268 additions and 200 deletions
+51 -16
View File
@@ -359,6 +359,47 @@ util_get_depth_format_mrd(const struct util_format_description *desc)
return mrd;
}
void
util_format_unpack_rgba_rect(enum pipe_format format,
void *dst, unsigned dst_stride,
const void *src, unsigned src_stride,
unsigned w, unsigned h)
{
const struct util_format_unpack_description *unpack =
util_format_unpack_description(format);
/* Optimized function for block-compressed formats */
if (unpack->unpack_rgba_rect) {
unpack->unpack_rgba_rect(dst, dst_stride, src, src_stride, w, h);
} else {
for (unsigned y = 0; y < h; y++) {
unpack->unpack_rgba(dst, src, w);
src = (const char *)src + src_stride;
dst = (char *)dst + dst_stride;
}
}
}
void
util_format_unpack_rgba_8unorm_rect(enum pipe_format format,
void *dst, unsigned dst_stride,
const void *src, unsigned src_stride,
unsigned w, unsigned h)
{
const struct util_format_unpack_description *unpack =
util_format_unpack_description(format);
/* Optimized function for block-compressed formats */
if (unpack->unpack_rgba_8unorm_rect) {
unpack->unpack_rgba_8unorm_rect(dst, dst_stride, src, src_stride, w, h);
} else {
for (unsigned y = 0; y < h; y++) {
unpack->unpack_rgba_8unorm(dst, src, w);
src = (const char *)src + src_stride;
dst = (char *)dst + dst_stride;
}
}
}
void
util_format_read_4(enum pipe_format format,
@@ -367,8 +408,6 @@ util_format_read_4(enum pipe_format format,
unsigned x, unsigned y, unsigned w, unsigned h)
{
const struct util_format_description *format_desc;
const struct util_format_unpack_description *unpack =
util_format_unpack_description(format);
const uint8_t *src_row;
format_desc = util_format_description(format);
@@ -378,7 +417,7 @@ util_format_read_4(enum pipe_format format,
src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
unpack->unpack_rgba(dst, dst_stride, src_row, src_stride, w, h);
util_format_unpack_rgba_rect(format, dst, dst_stride, src_row, src_stride, w, h);
}
@@ -413,10 +452,7 @@ void
util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h)
{
const struct util_format_description *format_desc;
const struct util_format_unpack_description *unpack =
util_format_unpack_description(format);
const uint8_t *src_row;
uint8_t *dst_row;
format_desc = util_format_description(format);
@@ -424,9 +460,8 @@ util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride,
assert(y % format_desc->block.height == 0);
src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
dst_row = dst;
unpack->unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
util_format_unpack_rgba_8unorm_rect(format, dst, dst_stride, src_row, src_stride, w, h);
}
@@ -715,7 +750,7 @@ util_format_translate(enum pipe_format dst_format,
return FALSE;
while (height >= y_step) {
unpack->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, y_step);
util_format_unpack_rgba_8unorm_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, y_step);
pack->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step);
dst_row += dst_step;
@@ -724,7 +759,7 @@ util_format_translate(enum pipe_format dst_format,
}
if (height) {
unpack->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, height);
util_format_unpack_rgba_8unorm_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, height);
pack->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, height);
}
@@ -746,7 +781,7 @@ util_format_translate(enum pipe_format dst_format,
return FALSE;
while (height >= y_step) {
unpack->unpack_rgba(tmp_row, tmp_stride, src_row, src_stride, width, y_step);
util_format_unpack_rgba_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, y_step);
pack->pack_rgba_sint(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step);
dst_row += dst_step;
@@ -755,7 +790,7 @@ util_format_translate(enum pipe_format dst_format,
}
if (height) {
unpack->unpack_rgba(tmp_row, tmp_stride, src_row, src_stride, width, height);
util_format_unpack_rgba_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, height);
pack->pack_rgba_sint(dst_row, dst_stride, tmp_row, tmp_stride, width, height);
}
@@ -777,7 +812,7 @@ util_format_translate(enum pipe_format dst_format,
return FALSE;
while (height >= y_step) {
unpack->unpack_rgba(tmp_row, tmp_stride, src_row, src_stride, width, y_step);
util_format_unpack_rgba_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, y_step);
pack->pack_rgba_uint(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step);
dst_row += dst_step;
@@ -786,7 +821,7 @@ util_format_translate(enum pipe_format dst_format,
}
if (height) {
unpack->unpack_rgba(tmp_row, tmp_stride, src_row, src_stride, width, height);
util_format_unpack_rgba_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, height);
pack->pack_rgba_uint(dst_row, dst_stride, tmp_row, tmp_stride, width, height);
}
@@ -807,7 +842,7 @@ util_format_translate(enum pipe_format dst_format,
return FALSE;
while (height >= y_step) {
unpack->unpack_rgba(tmp_row, tmp_stride, src_row, src_stride, width, y_step);
util_format_unpack_rgba_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, y_step);
pack->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step);
dst_row += dst_step;
@@ -816,7 +851,7 @@ util_format_translate(enum pipe_format dst_format,
}
if (height) {
unpack->unpack_rgba(tmp_row, tmp_stride, src_row, src_stride, width, height);
util_format_unpack_rgba_rect(src_format, tmp_row, tmp_stride, src_row, src_stride, width, height);
pack->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, height);
}