aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2020-07-01 16:50:02 -0700
committerMarge Bot <[email protected]>2020-07-07 18:19:23 +0000
commite7010eeff03d96179f79a93b7766bb8e998ca8bf (patch)
tree7100e471bcf781de63650d5fcdf7441e743749a0 /src
parent2f4d557a561b468dcbe806e02e703ec7a26791a1 (diff)
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 <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5728>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/util/u_tile.c20
-rw-r--r--src/gallium/drivers/softpipe/sp_image.c57
-rw-r--r--src/util/format/u_format.c59
-rw-r--r--src/util/format/u_format.h20
-rw-r--r--src/util/format/u_format_bptc.c32
5 files changed, 53 insertions, 135 deletions
diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c
index 939943a1818..56770749030 100644
--- a/src/gallium/auxiliary/util/u_tile.c
+++ b/src/gallium/auxiliary/util/u_tile.c
@@ -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);
diff --git a/src/gallium/drivers/softpipe/sp_image.c b/src/gallium/drivers/softpipe/sp_image.c
index 9d244235fa4..b0240c95265 100644
--- a/src/gallium/drivers/softpipe/sp_image.c
+++ b/src/gallium/drivers/softpipe/sp_image.c
@@ -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];
diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c
index 12af0ed6562..5bb4b0fdb00 100644
--- a/src/util/format/u_format.c
+++ b/src/util/format/u_format.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
diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h
index 961b0ac72b7..4ce3b58bde2 100644
--- a/src/util/format/u_format.h
+++ b/src/util/format/u_format.h
@@ -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;
*/
diff --git a/src/util/format/u_format_bptc.c b/src/util/format/u_format_bptc.c
index 2d02e11f48b..60f789ce0e0 100644
--- a/src/util/format/u_format_bptc.c
+++ b/src/util/format/u_format_bptc.c
@@ -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