From 018aae950df449a18d7d69de54d51af587be94c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 31 Mar 2010 21:16:16 +0100 Subject: [PATCH] util: Make the accessors bidimensional again. Otherwise there's no way to unpack blocks with height >1 --- progs/gallium/unit/u_format_test.c | 8 +-- src/gallium/auxiliary/util/u_format.c | 36 ++--------- src/gallium/auxiliary/util/u_format.h | 28 ++++++--- src/gallium/auxiliary/util/u_format_pack.py | 70 ++++++++++++--------- 4 files changed, 69 insertions(+), 73 deletions(-) diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index ba4e9fab66d..54cb6b879e5 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -72,7 +72,7 @@ test_format_unpack_float(const struct util_format_description *format_desc, unsigned i; boolean success; - format_desc->unpack_float(unpacked, test->packed, 1); + format_desc->unpack_float(unpacked, 0, test->packed, 0, 1, 1); success = TRUE; for (i = 0; i < 4; ++i) @@ -102,7 +102,7 @@ test_format_pack_float(const struct util_format_description *format_desc, for (i = 0; i < 4; ++i) unpacked[i] = (float) test->unpacked[i]; - format_desc->pack_float(packed, unpacked, 1); + format_desc->pack_float(packed, 0, unpacked, 0, 1, 1); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) @@ -160,7 +160,7 @@ test_format_unpack_8unorm(const struct util_format_description *format_desc, unsigned i; boolean success; - format_desc->unpack_8unorm(unpacked, test->packed, 1); + format_desc->unpack_8unorm(unpacked, 0, test->packed, 0, 1, 1); convert_float_to_8unorm(expected, test->unpacked); @@ -196,7 +196,7 @@ test_format_pack_8unorm(const struct util_format_description *format_desc, memset(packed, 0, sizeof packed); - format_desc->pack_8unorm(packed, unpacked, 1); + format_desc->pack_8unorm(packed, 0, unpacked, 0, 1, 1); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index 11ef839ec19..7f16cf7d018 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -44,8 +44,6 @@ util_format_read_4f(enum pipe_format format, const struct util_format_description *format_desc; const uint8_t *src_row; float *dst_row; - unsigned row_blocks; - unsigned i; format_desc = util_format_description(format); @@ -54,13 +52,8 @@ util_format_read_4f(enum pipe_format format, src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); dst_row = dst; - row_blocks = (w + format_desc->block.width - 1) / format_desc->block.width; - for (i = 0; i < h; i += format_desc->block.height) { - format_desc->unpack_float(dst_row, src_row, row_blocks); - src_row += src_stride; - dst_row += dst_stride/sizeof(*dst_row); - } + format_desc->unpack_float(dst_row, dst_stride, src_row, src_stride, w, h); } @@ -73,8 +66,6 @@ util_format_write_4f(enum pipe_format format, const struct util_format_description *format_desc; uint8_t *dst_row; const float *src_row; - unsigned row_blocks; - unsigned i; format_desc = util_format_description(format); @@ -83,13 +74,8 @@ util_format_write_4f(enum pipe_format format, dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8); src_row = src; - row_blocks = (w + format_desc->block.width - 1) / format_desc->block.width; - for (i = 0; i < h; i += format_desc->block.height) { - format_desc->pack_float(dst_row, src_row, row_blocks); - dst_row += dst_stride; - src_row += src_stride/sizeof(*src_row); - } + format_desc->pack_float(dst_row, dst_stride, src_row, src_stride, w, h); } @@ -99,8 +85,6 @@ util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, const struct util_format_description *format_desc; const uint8_t *src_row; uint8_t *dst_row; - unsigned row_blocks; - unsigned i; format_desc = util_format_description(format); @@ -109,13 +93,8 @@ util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); dst_row = dst; - row_blocks = (w + format_desc->block.width - 1) / format_desc->block.width; - for (i = 0; i < h; i += format_desc->block.height) { - format_desc->unpack_8unorm(dst_row, src_row, row_blocks); - src_row += src_stride; - dst_row += dst_stride/sizeof(*dst_row); - } + format_desc->unpack_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); } @@ -125,8 +104,6 @@ util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_ const struct util_format_description *format_desc; uint8_t *dst_row; const uint8_t *src_row; - unsigned row_blocks; - unsigned i; format_desc = util_format_description(format); @@ -135,12 +112,7 @@ util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_ dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8); src_row = src; - row_blocks = (w + format_desc->block.width - 1) / format_desc->block.width; - for (i = 0; i < h; i += format_desc->block.height) { - format_desc->pack_8unorm(dst_row, src_row, row_blocks); - dst_row += dst_stride; - src_row += src_stride/sizeof(*src_row); - } + format_desc->pack_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); } diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 0fad81fe403..93818a31611 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -191,34 +191,44 @@ struct util_format_description enum util_format_colorspace colorspace; /** - * Unpack a span of pixel blocks to R8G8B8A8_UNORM. + * Unpack pixel blocks to R8G8B8A8_UNORM. */ void - (*unpack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + (*unpack_8unorm)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); /** - * Pack a span of pixel blocks from R8G8B8A8_UNORM. + * Pack pixel blocks from R8G8B8A8_UNORM. */ void - (*pack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + (*pack_8unorm)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); /** - * Unpack a span of pixel blocks to R32G32B32A32_FLOAT. + * Unpack pixel blocks to R32G32B32A32_FLOAT. */ void - (*unpack_float)(float *dst, const uint8_t *src, unsigned nr_blocks); + (*unpack_float)(float *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); /** - * Pack a span of pixel blocks from R32G32B32A32_FLOAT. + * Pack pixel blocks from R32G32B32A32_FLOAT. */ void - (*pack_float)(uint8_t *dst, const float *src, unsigned nr_blocks); + (*pack_float)(uint8_t *dst, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height); /** * Fetch a single pixel (i, j) from a block. */ void - (*fetch_float)(float *dst, const uint8_t *src, unsigned i, unsigned j); + (*fetch_float)(float *dst, + const uint8_t *src, + unsigned i, unsigned j); }; diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 26f87486046..73309cca5ce 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -343,19 +343,19 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): if format.is_bitmask(): depth = format.block_size() - print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth) + print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth) # Declare the intermediate variables for i in range(format.nr_channels()): src_channel = format.channels[i] if src_channel.type == UNSIGNED: - print ' uint%u_t %s;' % (depth, src_channel.name) + print ' uint%u_t %s;' % (depth, src_channel.name) elif src_channel.type == SIGNED: - print ' int%u_t %s;' % (depth, src_channel.name) + print ' int%u_t %s;' % (depth, src_channel.name) - print ' #ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print ' #endif' + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' # Compute the intermediate unshifted values shift = 0 @@ -382,7 +382,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): value = None if value is not None: - print ' %s = %s;' % (src_channel.name, value) + print ' %s = %s;' % (src_channel.name, value) shift += src_channel.size @@ -406,11 +406,11 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): value = get_one(dst_channel) elif i >= 1: value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) else: - print ' union util_format_%s pixel;' % format.short_name() - print ' memcpy(&pixel, src, sizeof pixel);' + print ' union util_format_%s pixel;' % format.short_name() + print ' memcpy(&pixel, src, sizeof pixel);' bswap_format(format) for i in range(4): @@ -432,7 +432,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): value = get_one(dst_channel) elif i >= 1: value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) def generate_pack_kernel(format, src_channel, src_native_type): @@ -448,7 +448,7 @@ def generate_pack_kernel(format, src_channel, src_native_type): if format.is_bitmask(): depth = format.block_size() - print ' uint%u_t value = 0;' % depth + print ' uint%u_t value = 0;' % depth shift = 0 for i in range(4): @@ -472,18 +472,18 @@ def generate_pack_kernel(format, src_channel, src_native_type): else: value = None if value is not None: - print ' value |= %s;' % (value) + print ' value |= %s;' % (value) shift += dst_channel.size print '#ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth + print ' value = util_bswap%u(value);' % depth print '#endif' - print ' *(uint%u_t *)dst = value;' % depth + print ' *(uint%u_t *)dst = value;' % depth else: - print ' union util_format_%s pixel;' % format.short_name() + print ' union util_format_%s pixel;' % format.short_name() for i in range(4): dst_channel = format.channels[i] @@ -497,10 +497,10 @@ def generate_pack_kernel(format, src_channel, src_native_type): value = get_one(dst_channel) elif i >= 1: value = '0' - print ' pixel.chan.%s = %s;' % (dst_channel.name, value) + print ' pixel.chan.%s = %s;' % (dst_channel.name, value) bswap_format(format) - print ' memcpy(dst, &pixel, sizeof pixel);' + print ' memcpy(dst, &pixel, sizeof pixel);' def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): @@ -509,16 +509,23 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): name = format.short_name() print 'static INLINE void' - print 'util_format_%s_unpack_%s(%s *dst, const uint8_t *src, unsigned length)' % (name, dst_suffix, dst_native_type) + print 'util_format_%s_unpack_%s(%s *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, dst_suffix, dst_native_type) print '{' if is_format_supported(format): - print ' while(length--) {' - + print ' unsigned x, y;' + print ' for(y = 0; y < height; y += %u) {' % (format.block_height,) + print ' %s *dst = dst_row;' % (dst_native_type) + print ' const uint8_t *src = src_row;' + print ' for(x = 0; x < width; x += %u) {' % (format.block_width,) + generate_unpack_kernel(format, dst_channel, dst_native_type) - print ' src += %u;' % (format.block_size() / 8,) - print ' dst += 4;' + print ' src += %u;' % (format.block_size() / 8,) + print ' dst += 4;' + print ' }' + print ' src_row += src_stride;' + print ' dst_row += dst_stride/sizeof(*dst_row);' print ' }' print '}' @@ -531,18 +538,25 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): name = format.short_name() print 'static INLINE void' - print 'util_format_%s_pack_%s(uint8_t *dst, const %s *src, unsigned length)' % (name, src_suffix, src_native_type) + print 'util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, src_suffix, src_native_type) print '{' if is_format_supported(format): - print ' while(length--) {' + print ' unsigned x, y;' + print ' for(y = 0; y < height; y += %u) {' % (format.block_height,) + print ' const %s *src = src_row;' % (src_native_type) + print ' uint8_t *dst = dst_row;' + print ' for(x = 0; x < width; x += %u) {' % (format.block_width,) generate_pack_kernel(format, src_channel, src_native_type) - print ' src += 4;' - print ' dst += %u;' % (format.block_size() / 8,) + print ' src += 4;' + print ' dst += %u;' % (format.block_size() / 8,) + print ' }' + print ' dst_row += dst_stride;' + print ' src_row += src_stride/sizeof(*src_row);' print ' }' - + print '}' print -- 2.30.2