util: Merge util_format_write_4* functions.

Everyone wants the same thing: pack 4-bytes-per-channel data based on the
base type of the format.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5728>
This commit is contained in:
Eric Anholt 2020-07-01 16:37:05 -07:00 committed by Marge Bot
parent c3d0500389
commit 2f4d557a56
4 changed files with 28 additions and 105 deletions

View file

@ -371,22 +371,10 @@ pipe_put_tile_rgba(struct pipe_transfer *pt,
if (util_format_is_depth_or_stencil(format))
return;
if (util_format_is_pure_uint(format)) {
util_format_write_4ui(format,
p, src_stride * sizeof(float),
dst, pt->stride,
x, y, w, h);
} else if (util_format_is_pure_sint(format)) {
util_format_write_4i(format,
p, src_stride * sizeof(float),
dst, pt->stride,
x, y, w, h);
} else {
util_format_write_4f(format,
p, src_stride * sizeof(float),
dst, pt->stride,
x, y, w, h);
}
util_format_write_4(format,
p, src_stride * sizeof(float),
dst, pt->stride,
x, y, w, h);
}
void

View file

@ -352,25 +352,11 @@ sp_tgsi_store(const struct tgsi_image *image,
offset = get_image_offset(spr, iview, pformat, r_coord);
data_ptr = (char *)spr->data + offset;
if (util_format_is_pure_sint(pformat)) {
int32_t sdata[4];
for (c = 0; c < 4; c++)
sdata[c] = ((int32_t *)rgba[c])[j];
util_format_write_4i(pformat, sdata, 0, data_ptr, stride,
s_coord, t_coord, 1, 1);
} else if (util_format_is_pure_uint(pformat)) {
uint32_t sdata[4];
for (c = 0; c < 4; c++)
sdata[c] = ((uint32_t *)rgba[c])[j];
util_format_write_4ui(pformat, sdata, 0, data_ptr, stride,
s_coord, t_coord, 1, 1);
} else {
float sdata[4];
for (c = 0; c < 4; c++)
sdata[c] = rgba[c][j];
util_format_write_4f(pformat, sdata, 0, data_ptr, stride,
s_coord, t_coord, 1, 1);
}
uint32_t sdata[4];
for (c = 0; c < 4; c++)
sdata[c] = ((uint32_t *)rgba[c])[j];
util_format_write_4(pformat, sdata, 0, data_ptr, stride,
s_coord, t_coord, 1, 1);
}
}
@ -487,8 +473,8 @@ handle_op_uint(const struct pipe_image_view *iview,
assert(!"Unexpected TGSI opcode in sp_tgsi_op");
break;
}
util_format_write_4ui(params->format, sdata, 0, data_ptr, stride,
s, t, 1, 1);
util_format_write_4(params->format, sdata, 0, data_ptr, stride,
s, t, 1, 1);
}
/*
@ -603,8 +589,8 @@ handle_op_int(const struct pipe_image_view *iview,
assert(!"Unexpected TGSI opcode in sp_tgsi_op");
break;
}
util_format_write_4i(params->format, sdata, 0, data_ptr, stride,
s, t, 1, 1);
util_format_write_4(params->format, sdata, 0, data_ptr, stride,
s, t, 1, 1);
}
/* GLES OES_shader_image_atomic.txt allows XCHG on R32F */
@ -639,8 +625,8 @@ handle_op_r32f_xchg(const struct pipe_image_view *iview,
sdata[c] = ((float *)rgba[c])[qi];
((float *)rgba[c])[qi] = temp;
}
util_format_write_4f(params->format, sdata, 0, data_ptr, stride,
s, t, 1, 1);
util_format_write_4(params->format, sdata, 0, data_ptr, stride,
s, t, 1, 1);
}
/*

View file

@ -348,14 +348,13 @@ util_format_read_4f(enum pipe_format format,
void
util_format_write_4f(enum pipe_format format,
const float *src, unsigned src_stride,
util_format_write_4(enum pipe_format format,
const void *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h)
{
const struct util_format_description *format_desc;
uint8_t *dst_row;
const float *src_row;
format_desc = util_format_description(format);
@ -363,9 +362,13 @@ util_format_write_4f(enum pipe_format format,
assert(y % format_desc->block.height == 0);
dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
src_row = src;
format_desc->pack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h);
if (util_format_is_pure_uint(format))
format_desc->pack_rgba_uint(dst_row, dst_stride, src, src_stride, w, h);
else if (util_format_is_pure_sint(format))
format_desc->pack_rgba_sint(dst_row, dst_stride, src, src_stride, w, h);
else
format_desc->pack_rgba_float(dst_row, dst_stride, src, src_stride, w, h);
}
@ -427,27 +430,6 @@ util_format_read_4ui(enum pipe_format format,
format_desc->unpack_rgba_uint(dst_row, dst_stride, src_row, src_stride, w, h);
}
void
util_format_write_4ui(enum pipe_format format,
const unsigned int *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h)
{
const struct util_format_description *format_desc;
uint8_t *dst_row;
const uint32_t *src_row;
format_desc = util_format_description(format);
assert(x % format_desc->block.width == 0);
assert(y % format_desc->block.height == 0);
dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
src_row = src;
format_desc->pack_rgba_uint(dst_row, dst_stride, src_row, src_stride, w, h);
}
void
util_format_read_4i(enum pipe_format format,
int *dst, unsigned dst_stride,
@ -469,27 +451,6 @@ util_format_read_4i(enum pipe_format format,
format_desc->unpack_rgba_sint(dst_row, dst_stride, src_row, src_stride, w, h);
}
void
util_format_write_4i(enum pipe_format format,
const int *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h)
{
const struct util_format_description *format_desc;
uint8_t *dst_row;
const int32_t *src_row;
format_desc = util_format_description(format);
assert(x % format_desc->block.width == 0);
assert(y % format_desc->block.height == 0);
dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
src_row = src;
format_desc->pack_rgba_sint(dst_row, dst_stride, src_row, src_stride, w, h);
}
/**
* Check if we can safely memcopy from the source format to the dest format.
* This basically covers the cases of a "used" channel copied to a typeless

View file

@ -1547,7 +1547,7 @@ util_format_pack_rgba(enum pipe_format format, void *dst,
}
/*
* Format access functions.
* Format access functions for subrectangles
*/
void
@ -1557,10 +1557,10 @@ util_format_read_4f(enum pipe_format format,
unsigned x, unsigned y, unsigned w, unsigned h);
void
util_format_write_4f(enum pipe_format format,
const float *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h);
util_format_write_4(enum pipe_format format,
const void *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h);
void
util_format_read_4ub(enum pipe_format format,
@ -1580,24 +1580,12 @@ util_format_read_4ui(enum pipe_format format,
const void *src, unsigned src_stride,
unsigned x, unsigned y, unsigned w, unsigned h);
void
util_format_write_4ui(enum pipe_format format,
const unsigned int *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h);
void
util_format_read_4i(enum pipe_format format,
int *dst, unsigned dst_stride,
const void *src, unsigned src_stride,
unsigned x, unsigned y, unsigned w, unsigned h);
void
util_format_write_4i(enum pipe_format format,
const int *src, unsigned src_stride,
void *dst, unsigned dst_stride,
unsigned x, unsigned y, unsigned w, unsigned h);
/*
* Generic format conversion;
*/