mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-15 02:20:29 +01:00
util: Merge util_format_read_4* functions.
Everyone wants the same thing: unpack 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:
parent
2f4d557a56
commit
e7010eeff0
5 changed files with 53 additions and 135 deletions
|
|
@ -436,22 +436,10 @@ pipe_get_tile_rgba(struct pipe_transfer *pt,
|
|||
x32_s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
|
||||
break;
|
||||
default:
|
||||
if (util_format_is_pure_uint(format)) {
|
||||
util_format_read_4ui(format,
|
||||
dst, dst_stride * sizeof(float),
|
||||
packed, util_format_get_stride(format, w),
|
||||
0, 0, w, h);
|
||||
} else if (util_format_is_pure_sint(format)) {
|
||||
util_format_read_4i(format,
|
||||
dst, dst_stride * sizeof(float),
|
||||
packed, util_format_get_stride(format, w),
|
||||
0, 0, w, h);
|
||||
} else {
|
||||
util_format_read_4f(format,
|
||||
dst, dst_stride * sizeof(float),
|
||||
packed, util_format_get_stride(format, w),
|
||||
0, 0, w, h);
|
||||
}
|
||||
util_format_read_4(format,
|
||||
dst, dst_stride * sizeof(float),
|
||||
packed, util_format_get_stride(format, w),
|
||||
0, 0, w, h);
|
||||
}
|
||||
|
||||
FREE(packed);
|
||||
|
|
|
|||
|
|
@ -262,32 +262,13 @@ sp_tgsi_load(const struct tgsi_image *image,
|
|||
offset = get_image_offset(spr, iview, params->format, r_coord);
|
||||
data_ptr = (char *)spr->data + offset;
|
||||
|
||||
if (util_format_is_pure_sint(params->format)) {
|
||||
int32_t sdata[4];
|
||||
|
||||
util_format_read_4i(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s_coord, t_coord, 1, 1);
|
||||
for (c = 0; c < 4; c++)
|
||||
((int32_t *)rgba[c])[j] = sdata[c];
|
||||
} else if (util_format_is_pure_uint(params->format)) {
|
||||
uint32_t sdata[4];
|
||||
util_format_read_4ui(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s_coord, t_coord, 1, 1);
|
||||
for (c = 0; c < 4; c++)
|
||||
((uint32_t *)rgba[c])[j] = sdata[c];
|
||||
} else {
|
||||
float sdata[4];
|
||||
util_format_read_4f(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s_coord, t_coord, 1, 1);
|
||||
for (c = 0; c < 4; c++)
|
||||
rgba[c][j] = sdata[c];
|
||||
}
|
||||
uint32_t sdata[4];
|
||||
util_format_read_4(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s_coord, t_coord, 1, 1);
|
||||
for (c = 0; c < 4; c++)
|
||||
((uint32_t *)rgba[c])[j] = sdata[c];
|
||||
}
|
||||
return;
|
||||
fail_write_all_zero:
|
||||
|
|
@ -380,10 +361,10 @@ handle_op_uint(const struct pipe_image_view *iview,
|
|||
int nc = util_format_get_nr_components(params->format);
|
||||
unsigned sdata[4];
|
||||
|
||||
util_format_read_4ui(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s, t, 1, 1);
|
||||
util_format_read_4(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s, t, 1, 1);
|
||||
|
||||
if (just_read) {
|
||||
for (c = 0; c < nc; c++) {
|
||||
|
|
@ -496,10 +477,10 @@ handle_op_int(const struct pipe_image_view *iview,
|
|||
uint c;
|
||||
int nc = util_format_get_nr_components(params->format);
|
||||
int sdata[4];
|
||||
util_format_read_4i(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s, t, 1, 1);
|
||||
util_format_read_4(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s, t, 1, 1);
|
||||
|
||||
if (just_read) {
|
||||
for (c = 0; c < nc; c++) {
|
||||
|
|
@ -609,10 +590,10 @@ handle_op_r32f_xchg(const struct pipe_image_view *iview,
|
|||
float sdata[4];
|
||||
uint c;
|
||||
int nc = 1;
|
||||
util_format_read_4f(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s, t, 1, 1);
|
||||
util_format_read_4(params->format,
|
||||
sdata, 0,
|
||||
data_ptr, stride,
|
||||
s, t, 1, 1);
|
||||
if (just_read) {
|
||||
for (c = 0; c < nc; c++) {
|
||||
((int32_t *)rgba[c])[qi] = sdata[c];
|
||||
|
|
|
|||
|
|
@ -326,14 +326,13 @@ util_get_depth_format_mrd(const struct util_format_description *desc)
|
|||
|
||||
|
||||
void
|
||||
util_format_read_4f(enum pipe_format format,
|
||||
float *dst, unsigned dst_stride,
|
||||
const void *src, unsigned src_stride,
|
||||
unsigned x, unsigned y, unsigned w, unsigned h)
|
||||
util_format_read_4(enum pipe_format format,
|
||||
void *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 uint8_t *src_row;
|
||||
float *dst_row;
|
||||
|
||||
format_desc = util_format_description(format);
|
||||
|
||||
|
|
@ -341,9 +340,13 @@ util_format_read_4f(enum pipe_format format,
|
|||
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;
|
||||
|
||||
format_desc->unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h);
|
||||
if (util_format_is_pure_uint(format))
|
||||
format_desc->unpack_rgba_sint(dst, dst_stride, src_row, src_stride, w, h);
|
||||
else if (util_format_is_pure_uint(format))
|
||||
format_desc->unpack_rgba_uint(dst, dst_stride, src_row, src_stride, w, h);
|
||||
else
|
||||
format_desc->unpack_rgba_float(dst, dst_stride, src_row, src_stride, w, h);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -409,48 +412,6 @@ util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_
|
|||
format_desc->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
|
||||
}
|
||||
|
||||
void
|
||||
util_format_read_4ui(enum pipe_format format,
|
||||
unsigned *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 uint8_t *src_row;
|
||||
uint32_t *dst_row;
|
||||
|
||||
format_desc = util_format_description(format);
|
||||
|
||||
assert(x % format_desc->block.width == 0);
|
||||
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;
|
||||
|
||||
format_desc->unpack_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,
|
||||
const void *src, unsigned src_stride,
|
||||
unsigned x, unsigned y, unsigned w, unsigned h)
|
||||
{
|
||||
const struct util_format_description *format_desc;
|
||||
const uint8_t *src_row;
|
||||
int32_t *dst_row;
|
||||
|
||||
format_desc = util_format_description(format);
|
||||
|
||||
assert(x % format_desc->block.width == 0);
|
||||
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;
|
||||
|
||||
format_desc->unpack_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
|
||||
|
|
|
|||
|
|
@ -1551,10 +1551,10 @@ util_format_pack_rgba(enum pipe_format format, void *dst,
|
|||
*/
|
||||
|
||||
void
|
||||
util_format_read_4f(enum pipe_format format,
|
||||
float *dst, unsigned dst_stride,
|
||||
const void *src, unsigned src_stride,
|
||||
unsigned x, unsigned y, unsigned w, unsigned h);
|
||||
util_format_read_4(enum pipe_format format,
|
||||
void *dst, unsigned dst_stride,
|
||||
const void *src, unsigned src_stride,
|
||||
unsigned x, unsigned y, unsigned w, unsigned h);
|
||||
|
||||
void
|
||||
util_format_write_4(enum pipe_format format,
|
||||
|
|
@ -1574,18 +1574,6 @@ util_format_write_4ub(enum pipe_format format,
|
|||
void *dst, unsigned dst_stride,
|
||||
unsigned x, unsigned y, unsigned w, unsigned h);
|
||||
|
||||
void
|
||||
util_format_read_4ui(enum pipe_format format,
|
||||
unsigned *dst, unsigned dst_stride,
|
||||
const void *src, unsigned src_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);
|
||||
|
||||
/*
|
||||
* Generic format conversion;
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_strid
|
|||
decompress_rgba_unorm(width, height,
|
||||
src_row, src_stride,
|
||||
temp_block, width * 4 * sizeof(uint8_t));
|
||||
util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM,
|
||||
dst_row, dst_stride,
|
||||
temp_block, width * 4 * sizeof(uint8_t),
|
||||
0, 0, width, height);
|
||||
util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM,
|
||||
dst_row, dst_stride,
|
||||
temp_block, width * 4 * sizeof(uint8_t),
|
||||
0, 0, width, height);
|
||||
free((void *) temp_block);
|
||||
}
|
||||
|
||||
|
|
@ -94,10 +94,10 @@ util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
|
|||
fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16,
|
||||
temp_block, (width % 4) + (height % 4) * 4);
|
||||
|
||||
util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM,
|
||||
dst, 4 * sizeof(float),
|
||||
temp_block, 4 * sizeof(uint8_t),
|
||||
0, 0, 1, 1);
|
||||
util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM,
|
||||
dst, 4 * sizeof(float),
|
||||
temp_block, 4 * sizeof(uint8_t),
|
||||
0, 0, 1, 1);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -130,10 +130,10 @@ util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
|
|||
decompress_rgba_unorm(width, height,
|
||||
src_row, src_stride,
|
||||
temp_block, width * 4 * sizeof(uint8_t));
|
||||
util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB,
|
||||
dst_row, dst_stride,
|
||||
temp_block, width * 4 * sizeof(uint8_t),
|
||||
0, 0, width, height);
|
||||
util_format_read_4(PIPE_FORMAT_R8G8B8A8_SRGB,
|
||||
dst_row, dst_stride,
|
||||
temp_block, width * 4 * sizeof(uint8_t),
|
||||
0, 0, width, height);
|
||||
free((void *) temp_block);
|
||||
}
|
||||
|
||||
|
|
@ -156,10 +156,10 @@ util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src,
|
|||
|
||||
fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16,
|
||||
temp_block, (width % 4) + (height % 4) * 4);
|
||||
util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB,
|
||||
dst, 4 * sizeof(float),
|
||||
temp_block, width * 4 * sizeof(uint8_t),
|
||||
0, 0, 1, 1);
|
||||
util_format_read_4(PIPE_FORMAT_R8G8B8A8_SRGB,
|
||||
dst, 4 * sizeof(float),
|
||||
temp_block, width * 4 * sizeof(uint8_t),
|
||||
0, 0, 1, 1);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue