From 4e9690f00ca67e42e31367c50f9c216ad10ef553 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Tue, 30 Mar 2010 01:33:28 +0200 Subject: gallium: make the python scripts for format parsing not fail on new formats they won't generate any useful conversion code for some of the new formats but at least don't assert. Also needed some more hacks so they don't generate code for some of the new formats, as gcc was not impressed. Also declare unused channels as void, and change the scripts to not fail if the first channel happened to be unused. Needs serious fixing. --- src/gallium/auxiliary/util/u_format_pack.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 409d024c63..47def90317 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -46,11 +46,11 @@ def generate_format_type(format): '''Generate a structure that describes the format.''' print 'union util_format_%s {' % format.short_name() - if format.is_bitmask(): + if format.is_bitmask() or format.short_name() == "r11g11b10_float": print ' uint%u_t value;' % (format.block_size(),) print ' struct {' for channel in format.channels: - if format.is_bitmask() and not format.is_array(): + if (format.is_bitmask() or format.is_mixed()) and not format.is_array() or format.short_name() == "r11g11b10_float": if channel.type == VOID: if channel.size: print ' unsigned %s:%u;' % (channel.name, channel.size) @@ -58,6 +58,11 @@ def generate_format_type(format): print ' unsigned %s:%u;' % (channel.name, channel.size) elif channel.type == SIGNED: print ' int %s:%u;' % (channel.name, channel.size) + elif channel.type == FLOAT: + if channel.size == 32: + print ' float %s;' % (channel.name) + else: + print ' unsigned %s:%u;' % (channel.name, channel.size) else: assert 0 else: @@ -107,6 +112,9 @@ def is_format_supported(format): channel = format.channels[i] if channel.type not in (VOID, UNSIGNED, SIGNED, FLOAT): return False + if channel.type == FLOAT: + if channel.size not in (32, 64): + return False # We can only read a color from a depth/stencil format if the depth channel is present if format.colorspace == 'zs' and format.swizzles[0] == SWIZZLE_NONE: @@ -125,6 +133,8 @@ def native_type(format): else: # For array pixel formats return the integer type that matches the color channel type = format.channels[0] + if type.type == VOID: + type = format.channels[1] if type.type == UNSIGNED: return 'uint%u_t' % type.size elif type.type == SIGNED: -- cgit v1.2.3 From 338b9d71dfd93cfe516b16db1be4038725c5bc7b Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 14:28:34 +0100 Subject: util: Use VOID type for X channels in format descriptions. --- src/gallium/auxiliary/util/u_format.csv | 18 +++++++++--------- src/gallium/auxiliary/util/u_format_access.py | 2 +- src/gallium/auxiliary/util/u_format_pack.py | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index d819bbbde1..25a661eb45 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -58,12 +58,12 @@ # Typical rendertarget formats PIPE_FORMAT_B8G8R8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb -PIPE_FORMAT_B8G8R8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyx1, rgb +PIPE_FORMAT_B8G8R8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, rgb PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb -PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzw1, rgb +PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, rgb PIPE_FORMAT_A8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb -PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzy1, rgb -PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyx1, rgb +PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, rgb +PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , x1 , zyx1, rgb PIPE_FORMAT_B5G5R5A1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb PIPE_FORMAT_B4G4R4A4_UNORM , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb PIPE_FORMAT_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb @@ -81,11 +81,11 @@ PIPE_FORMAT_L8_SRGB , plain, 1, 1, un8 , , , , xxx1, s PIPE_FORMAT_L8A8_SRGB , plain, 1, 1, un8 , un8 , , , xxxy, srgb PIPE_FORMAT_R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , , xyz1, srgb PIPE_FORMAT_A8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, srgb -PIPE_FORMAT_X8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzy1, srgb +PIPE_FORMAT_X8B8G8R8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, srgb PIPE_FORMAT_B8G8R8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, srgb -PIPE_FORMAT_B8G8R8X8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyx1, srgb +PIPE_FORMAT_B8G8R8X8_SRGB , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, srgb PIPE_FORMAT_A8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, srgb -PIPE_FORMAT_X8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzw1, srgb +PIPE_FORMAT_X8R8G8B8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, srgb # Mixed-sign formats (typically used for bump map textures) PIPE_FORMAT_R8SG8SB8UX8U_NORM , plain, 1, 1, sn8 , sn8 , un8 , x8 , xyz1, rgb @@ -98,8 +98,8 @@ PIPE_FORMAT_Z32_UNORM , plain, 1, 1, un32, , , , x___, z PIPE_FORMAT_Z32_FLOAT , plain, 1, 1, f32 , , , , x___, zs PIPE_FORMAT_Z24S8_UNORM , plain, 1, 1, un24, un8 , , , xy__, zs PIPE_FORMAT_S8Z24_UNORM , plain, 1, 1, un8 , un24, , , yx__, zs -PIPE_FORMAT_Z24X8_UNORM , plain, 1, 1, un24, un8 , , , x___, zs -PIPE_FORMAT_X8Z24_UNORM , plain, 1, 1, un8 , un24, , , y___, zs +PIPE_FORMAT_Z24X8_UNORM , plain, 1, 1, un24, x8 , , , x___, zs +PIPE_FORMAT_X8Z24_UNORM , plain, 1, 1, x8 , un24, , , y___, zs # YUV formats # http://www.fourcc.org/yuv.php#UYVY diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py index 00424779d2..a5cb67f7e4 100644 --- a/src/gallium/auxiliary/util/u_format_access.py +++ b/src/gallium/auxiliary/util/u_format_access.py @@ -78,7 +78,7 @@ def native_type(format): else: # For array pixel formats return the integer type that matches the color channel channel = format.channels[0] - if channel.type == UNSIGNED: + if channel.type in (UNSIGNED, VOID): return 'uint%u_t' % channel.size elif channel.type == SIGNED: return 'int%u_t' % channel.size diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 409d024c63..e9d2573667 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -124,15 +124,15 @@ def native_type(format): return 'uint%u_t' % format.block_size() else: # For array pixel formats return the integer type that matches the color channel - type = format.channels[0] - if type.type == UNSIGNED: - return 'uint%u_t' % type.size - elif type.type == SIGNED: - return 'int%u_t' % type.size - elif type.type == FLOAT: - if type.size == 32: + channel = format.channels[0] + if channel.type in (UNSIGNED, VOID): + return 'uint%u_t' % channel.size + elif channel.type == SIGNED: + return 'int%u_t' % channel.size + elif channel.type == FLOAT: + if channel.size == 32: return 'float' - elif type.size == 64: + elif channel.size == 64: return 'double' else: assert False -- cgit v1.2.3 From 325d55303d5920c137c0047e673a3940a99e4629 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 14:31:29 +0100 Subject: util: Make util_format_xxx_pack_xxx take pointer as arguments. --- progs/gallium/unit/u_format_test.c | 8 ++++++-- src/gallium/auxiliary/util/u_format_pack.py | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index 5274311e03..1aef416a7e 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -60,13 +60,17 @@ test_format_unpack_4f(const struct util_format_test_case *test) static boolean test_format_pack_4f(const struct util_format_test_case *test) { + float unpacked[4]; uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; unsigned i; boolean success; memset(packed, 0, sizeof packed); - util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); + for (i = 0; i < 4; ++i) + unpacked[i] = (float) test->unpacked[i]; + + util_format_pack_4f(test->format, packed, unpacked); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) @@ -158,7 +162,7 @@ test_format_pack_4ub(const struct util_format_test_case *test) memset(packed, 0, sizeof packed); - util_format_pack_4ub(test->format, packed, unpacked[0], unpacked[1], unpacked[2], unpacked[3]); + util_format_pack_4ub(test->format, packed, unpacked); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index e9d2573667..43468ecf56 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -423,7 +423,7 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): inv_swizzle = format.inv_swizzles() print 'static INLINE void' - print 'util_format_%s_pack_%s(void *dst, %s r, %s g, %s b, %s a)' % (name, src_suffix, src_native_type, src_native_type, src_native_type, src_native_type) + print 'util_format_%s_pack_%s(void *dst, const %s *src)' % (name, src_suffix, src_native_type) print '{' if format.is_bitmask(): @@ -434,7 +434,7 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): for i in range(4): dst_channel = format.channels[i] if inv_swizzle[i] is not None: - value = 'rgba'[inv_swizzle[i]] + value ='src[%u]' % inv_swizzle[i] value = conversion_expr(src_channel, dst_channel, dst_native_type, value) if format.colorspace == ZS: if i == 3: @@ -470,7 +470,7 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): width = dst_channel.size if inv_swizzle[i] is None: continue - value = 'rgba'[inv_swizzle[i]] + value ='src[%u]' % inv_swizzle[i] value = conversion_expr(src_channel, dst_channel, dst_native_type, value) if format.colorspace == ZS: if i == 3: @@ -520,9 +520,9 @@ def generate_pack(formats, src_channel, src_native_type, src_suffix): generate_format_pack(format, src_channel, src_native_type, src_suffix) print 'static INLINE void' - print 'util_format_pack_%s(enum pipe_format format, void *dst, %s r, %s g, %s b, %s a)' % (src_suffix, src_native_type, src_native_type, src_native_type, src_native_type) + print 'util_format_pack_%s(enum pipe_format format, void *dst, %s *src)' % (src_suffix, src_native_type) print '{' - print ' void (*func)(void *dst, %s r, %s g, %s b, %s a);' % (src_native_type, src_native_type, src_native_type, src_native_type) + print ' void (*func)(void *dst, const %s *src);' % (src_native_type,) print ' switch(format) {' for format in formats: if is_format_supported(format): @@ -533,7 +533,7 @@ def generate_pack(formats, src_channel, src_native_type, src_suffix): print ' debug_printf("%s: unsupported format\\n", __FUNCTION__);' print ' return;' print ' }' - print ' func(dst, r, g, b, a);' + print ' func(dst, src);' print '}' print -- cgit v1.2.3 From e245ca74e11869750cafb1ab3fbb6957100c554b Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 14:43:09 +0100 Subject: util: Make pack/unpack operate on spans. --- progs/gallium/unit/u_format_test.c | 8 ++-- src/gallium/auxiliary/util/u_format_pack.py | 64 +++++++++++++++++------------ 2 files changed, 42 insertions(+), 30 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index 1aef416a7e..303f4fa499 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -41,7 +41,7 @@ test_format_unpack_4f(const struct util_format_test_case *test) unsigned i; boolean success; - util_format_unpack_4f(test->format, unpacked, test->packed); + util_format_unpack_4f(test->format, unpacked, test->packed, 1); success = TRUE; for (i = 0; i < 4; ++i) @@ -70,7 +70,7 @@ test_format_pack_4f(const struct util_format_test_case *test) for (i = 0; i < 4; ++i) unpacked[i] = (float) test->unpacked[i]; - util_format_pack_4f(test->format, packed, unpacked); + util_format_pack_4f(test->format, packed, unpacked, 1); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) @@ -127,7 +127,7 @@ test_format_unpack_4ub(const struct util_format_test_case *test) unsigned i; boolean success; - util_format_unpack_4ub(test->format, unpacked, test->packed); + util_format_unpack_4ub(test->format, unpacked, test->packed, 1); convert_4f_to_4ub(expected, test->unpacked); @@ -162,7 +162,7 @@ test_format_pack_4ub(const struct util_format_test_case *test) memset(packed, 0, sizeof packed); - util_format_pack_4ub(test->format, packed, unpacked); + util_format_pack_4ub(test->format, packed, unpacked, 1); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 43468ecf56..e156b30203 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -311,24 +311,26 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): src_native_type = native_type(format) print 'static INLINE void' - print 'util_format_%s_unpack_%s(%s *dst, const void *src)' % (name, dst_suffix, dst_native_type) + print 'util_format_%s_unpack_%s(%s *dst, const uint8_t *src, unsigned length)' % (name, dst_suffix, dst_native_type) print '{' + print ' while(length--) {' + 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 @@ -355,7 +357,7 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): 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 @@ -379,11 +381,11 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): 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): @@ -405,7 +407,11 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): 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]) + + print ' src += %u;' % (format.block_size() / 8,) + print ' dst += 4;' + print ' }' print '}' print @@ -423,12 +429,14 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): inv_swizzle = format.inv_swizzles() print 'static INLINE void' - print 'util_format_%s_pack_%s(void *dst, const %s *src)' % (name, src_suffix, src_native_type) + print 'util_format_%s_pack_%s(uint8_t *dst, const %s *src, unsigned length)' % (name, src_suffix, src_native_type) print '{' + print ' while(length--) {' + 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): @@ -452,18 +460,18 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): 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] @@ -477,11 +485,15 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): 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);' + print ' src += 4;' + print ' dst += %u;' % (format.block_size() / 8,) + print ' }' + print '}' print @@ -494,9 +506,9 @@ def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix): generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) print 'static INLINE void' - print 'util_format_unpack_%s(enum pipe_format format, %s *dst, const void *src)' % (dst_suffix, dst_native_type) + print 'util_format_unpack_%s(enum pipe_format format, %s *dst, const uint8_t *src, unsigned length)' % (dst_suffix, dst_native_type) print '{' - print ' void (*func)(%s *dst, const void *src);' % dst_native_type + print ' void (*func)(%s *dst, const uint8_t *src, unsigned length);' % dst_native_type print ' switch(format) {' for format in formats: if is_format_supported(format): @@ -507,7 +519,7 @@ def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix): print ' debug_printf("unsupported format\\n");' print ' return;' print ' }' - print ' func(dst, src);' + print ' func(dst, src, length);' print '}' print @@ -520,9 +532,9 @@ def generate_pack(formats, src_channel, src_native_type, src_suffix): generate_format_pack(format, src_channel, src_native_type, src_suffix) print 'static INLINE void' - print 'util_format_pack_%s(enum pipe_format format, void *dst, %s *src)' % (src_suffix, src_native_type) + print 'util_format_pack_%s(enum pipe_format format, uint8_t *dst, const %s *src, unsigned length)' % (src_suffix, src_native_type) print '{' - print ' void (*func)(void *dst, const %s *src);' % (src_native_type,) + print ' void (*func)(uint8_t *dst, const %s *src, unsigned length);' % (src_native_type,) print ' switch(format) {' for format in formats: if is_format_supported(format): @@ -533,7 +545,7 @@ def generate_pack(formats, src_channel, src_native_type, src_suffix): print ' debug_printf("%s: unsupported format\\n", __FUNCTION__);' print ' return;' print ' }' - print ' func(dst, src);' + print ' func(dst, src, length);' print '}' print -- cgit v1.2.3 From 96bf4aff5bd674bba5d83ab32c46024a686c1a1d Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 15:30:14 +0100 Subject: util: Put the format pack/unpack functions in the description table. --- progs/gallium/unit/u_format_test.c | 45 +-- src/gallium/auxiliary/Makefile | 6 +- src/gallium/auxiliary/SConscript | 7 - src/gallium/auxiliary/util/.gitignore | 1 - src/gallium/auxiliary/util/u_format.h | 17 ++ src/gallium/auxiliary/util/u_format_access.py | 2 +- src/gallium/auxiliary/util/u_format_pack.py | 389 +++++++++++--------------- src/gallium/auxiliary/util/u_format_table.py | 36 ++- 8 files changed, 245 insertions(+), 258 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index 303f4fa499..e96f0a9d12 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -31,17 +31,17 @@ #include "util/u_format.h" #include "util/u_format_tests.h" -#include "util/u_format_pack.h" static boolean -test_format_unpack_4f(const struct util_format_test_case *test) +test_format_unpack_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) { float unpacked[4]; unsigned i; boolean success; - util_format_unpack_4f(test->format, unpacked, test->packed, 1); + format_desc->unpack_float(unpacked, test->packed, 1); success = TRUE; for (i = 0; i < 4; ++i) @@ -58,7 +58,8 @@ test_format_unpack_4f(const struct util_format_test_case *test) static boolean -test_format_pack_4f(const struct util_format_test_case *test) +test_format_pack_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) { float unpacked[4]; uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; @@ -70,7 +71,7 @@ test_format_pack_4f(const struct util_format_test_case *test) for (i = 0; i < 4; ++i) unpacked[i] = (float) test->unpacked[i]; - util_format_pack_4f(test->format, packed, unpacked, 1); + format_desc->pack_float(packed, unpacked, 1); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) @@ -96,7 +97,7 @@ test_format_pack_4f(const struct util_format_test_case *test) static boolean -convert_4f_to_4ub(uint8_t *dst, const double *src) +convert_float_to_8unorm(uint8_t *dst, const double *src) { unsigned i; boolean accurate = TRUE; @@ -120,16 +121,17 @@ convert_4f_to_4ub(uint8_t *dst, const double *src) static boolean -test_format_unpack_4ub(const struct util_format_test_case *test) +test_format_unpack_8unorm(const struct util_format_description *format_desc, + const struct util_format_test_case *test) { uint8_t unpacked[4]; uint8_t expected[4]; unsigned i; boolean success; - util_format_unpack_4ub(test->format, unpacked, test->packed, 1); + format_desc->unpack_8unorm(unpacked, test->packed, 1); - convert_4f_to_4ub(expected, test->unpacked); + convert_float_to_8unorm(expected, test->unpacked); success = TRUE; for (i = 0; i < 4; ++i) @@ -146,14 +148,15 @@ test_format_unpack_4ub(const struct util_format_test_case *test) static boolean -test_format_pack_4ub(const struct util_format_test_case *test) +test_format_pack_8unorm(const struct util_format_description *format_desc, + const struct util_format_test_case *test) { uint8_t unpacked[4]; uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; unsigned i; boolean success; - if (!convert_4f_to_4ub(unpacked, test->unpacked)) { + if (!convert_float_to_8unorm(unpacked, test->unpacked)) { /* * Skip test cases which cannot be represented by four unorm bytes. */ @@ -162,7 +165,7 @@ test_format_pack_4ub(const struct util_format_test_case *test) memset(packed, 0, sizeof packed); - util_format_pack_4ub(test->format, packed, unpacked, 1); + format_desc->pack_8unorm(packed, unpacked, 1); success = TRUE; for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) @@ -188,7 +191,8 @@ test_format_pack_4ub(const struct util_format_test_case *test) typedef boolean -(*test_func_t)(const struct util_format_test_case *test); +(*test_func_t)(const struct util_format_description *format_desc, + const struct util_format_test_case *test); static boolean @@ -200,14 +204,15 @@ test_one(test_func_t func, const char *suffix) for (i = 0; i < util_format_nr_test_cases; ++i) { const struct util_format_test_case *test = &util_format_test_cases[i]; + const struct util_format_description *format_desc; + format_desc = util_format_description(test->format); + if (test->format != last_format) { - const struct util_format_description *format_desc; - format_desc = util_format_description(test->format); printf("Testing util_format_%s_%s ...\n", format_desc->short_name, suffix); last_format = test->format; } - if (!func(&util_format_test_cases[i])) + if (!func(format_desc, &util_format_test_cases[i])) success = FALSE; } @@ -220,16 +225,16 @@ test_all(void) { bool success = TRUE; - if (!test_one(&test_format_pack_4f, "pack_4f")) + if (!test_one(&test_format_pack_float, "pack_float")) success = FALSE; - if (!test_one(&test_format_unpack_4f, "unpack_4f")) + if (!test_one(&test_format_unpack_float, "unpack_float")) success = FALSE; - if (!test_one(&test_format_pack_4ub, "pack_4ub")) + if (!test_one(&test_format_pack_8unorm, "pack_8unorm")) success = FALSE; - if (!test_one(&test_format_unpack_4ub, "unpack_4ub")) + if (!test_one(&test_format_unpack_8unorm, "unpack_8unorm")) success = FALSE; return success; diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 1b75915ff2..903c5a331c 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -168,7 +168,6 @@ GENERATED_SOURCES = \ indices/u_indices_gen.c \ indices/u_unfilled_gen.c \ util/u_format_access.c \ - util/u_format_pack.h \ util/u_format_table.c @@ -192,12 +191,9 @@ indices/u_indices_gen.c: indices/u_indices_gen.py indices/u_unfilled_gen.c: indices/u_unfilled_gen.py python $< > $@ -util/u_format_table.c: util/u_format_table.py util/u_format_parse.py util/u_format.csv +util/u_format_table.c: util/u_format_table.py util/u_format_pack.py util/u_format_parse.py util/u_format.csv python util/u_format_table.py util/u_format.csv > $@ -util/u_format_pack.h: util/u_format_pack.py util/u_format_parse.py util/u_format.csv - python util/u_format_pack.py util/u_format.csv > $@ - util/u_format_access.c: util/u_format_access.py util/u_format_parse.py util/u_format.csv python util/u_format_access.py util/u_format.csv > $@ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 8cf13fc293..772ab41523 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -30,13 +30,6 @@ env.CodeGenerate( command = 'python $SCRIPT $SOURCE > $TARGET' ) -env.CodeGenerate( - target = File('util/u_format_pack.h').srcnode(), - script = 'util/u_format_pack.py', - source = ['util/u_format.csv'], - command = 'python $SCRIPT $SOURCE > $TARGET' -) - env.CodeGenerate( target = 'util/u_format_access.c', script = 'util/u_format_access.py', diff --git a/src/gallium/auxiliary/util/.gitignore b/src/gallium/auxiliary/util/.gitignore index 448d2f304f..29c586c9b5 100644 --- a/src/gallium/auxiliary/util/.gitignore +++ b/src/gallium/auxiliary/util/.gitignore @@ -1,3 +1,2 @@ u_format_access.c u_format_table.c -u_format_pack.h diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 4d59b9927d..609d398ebf 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -189,6 +189,23 @@ struct util_format_description * Colorspace transformation. */ enum util_format_colorspace colorspace; + + /** + * Accessor functions. + */ + + void + (*unpack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + + void + (*pack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + + void + (*unpack_float)(float *dst, const uint8_t *src, unsigned nr_blocks); + + void + (*pack_float)(uint8_t *dst, const float *src, unsigned nr_blocks); + }; diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py index a5cb67f7e4..c85f538626 100644 --- a/src/gallium/auxiliary/util/u_format_access.py +++ b/src/gallium/auxiliary/util/u_format_access.py @@ -317,7 +317,7 @@ def main(): print print '#include "pipe/p_compiler.h"' print '#include "u_math.h"' - print '#include "u_format_pack.h"' + print '#include "u_format.h"' print generate_srgb_tables() diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index e156b30203..28a9dad60e 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -304,114 +304,116 @@ def conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=True def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): '''Generate the function to unpack pixels from a particular format''' - assert format.layout == PLAIN - name = format.short_name() - src_native_type = native_type(format) - 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 '{' + + if is_format_supported(format): + + assert format.layout == PLAIN - print ' while(length--) {' + src_native_type = native_type(format) - if format.is_bitmask(): - depth = format.block_size() - 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) - elif src_channel.type == SIGNED: - print ' int%u_t %s;' % (depth, src_channel.name) - - print ' #ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print ' #endif' - - # Compute the intermediate unshifted values - shift = 0 - for i in range(format.nr_channels()): - src_channel = format.channels[i] - value = 'value' - if src_channel.type == UNSIGNED: - if shift: - value = '%s >> %u' % (value, shift) - if shift + src_channel.size < depth: - value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) - elif src_channel.type == SIGNED: - if shift + src_channel.size < depth: - # Align the sign bit - lshift = depth - (shift + src_channel.size) - value = '%s << %u' % (value, lshift) - # Cast to signed - value = '(int%u_t)(%s) ' % (depth, value) - if src_channel.size < depth: - # Align the LSB bit - rshift = depth - src_channel.size - value = '(%s) >> %u' % (value, rshift) - else: - value = None - - if value is not None: - print ' %s = %s;' % (src_channel.name, value) - - shift += src_channel.size - - # Convert, swizzle, and store final values - for i in range(4): - swizzle = format.swizzles[i] - if swizzle < 4: - src_channel = format.channels[swizzle] - value = src_channel.name - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: - value = get_one(dst_channel) - elif swizzle == SWIZZLE_NONE: - value = '0' - else: - assert False - if format.colorspace == ZS: - if i == 3: + print ' while(length--) {' + + if format.is_bitmask(): + depth = format.block_size() + 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) + elif src_channel.type == SIGNED: + print ' int%u_t %s;' % (depth, src_channel.name) + + print ' #ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print ' #endif' + + # Compute the intermediate unshifted values + shift = 0 + for i in range(format.nr_channels()): + src_channel = format.channels[i] + value = 'value' + if src_channel.type == UNSIGNED: + if shift: + value = '%s >> %u' % (value, shift) + if shift + src_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) + elif src_channel.type == SIGNED: + if shift + src_channel.size < depth: + # Align the sign bit + lshift = depth - (shift + src_channel.size) + value = '%s << %u' % (value, lshift) + # Cast to signed + value = '(int%u_t)(%s) ' % (depth, value) + if src_channel.size < depth: + # Align the LSB bit + rshift = depth - src_channel.size + value = '(%s) >> %u' % (value, rshift) + else: + value = None + + if value is not None: + print ' %s = %s;' % (src_channel.name, value) + + shift += src_channel.size + + # Convert, swizzle, and store final values + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: value = get_one(dst_channel) - elif i >= 1: - value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + 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);' + bswap_format(format) - else: - print ' union util_format_%s pixel;' % format.short_name() - print ' memcpy(&pixel, src, sizeof pixel);' - bswap_format(format) - - for i in range(4): - swizzle = format.swizzles[i] - if swizzle < 4: - src_channel = format.channels[swizzle] - value = 'pixel.chan.%s' % src_channel.name - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: - value = get_one(dst_channel) - elif swizzle == SWIZZLE_NONE: - value = '0' - else: - assert False - if format.colorspace == ZS: - if i == 3: + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = 'pixel.chan.%s' % src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: value = get_one(dst_channel) - elif i >= 1: - value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) - - print ' src += %u;' % (format.block_size() / 8,) - print ' dst += 4;' - print ' }' + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + print ' src += %u;' % (format.block_size() / 8,) + print ' dst += 4;' + print ' }' print '}' print @@ -422,26 +424,63 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): name = format.short_name() - dst_native_type = native_type(format) - - assert format.layout == PLAIN - - inv_swizzle = format.inv_swizzles() - 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 '{' - print ' while(length--) {' - - if format.is_bitmask(): - depth = format.block_size() - print ' uint%u_t value = 0;' % depth - - shift = 0 - for i in range(4): - dst_channel = format.channels[i] - if inv_swizzle[i] is not None: + if is_format_supported(format): + dst_native_type = native_type(format) + + assert format.layout == PLAIN + + inv_swizzle = format.inv_swizzles() + + print ' while(length--) {' + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = 0;' % depth + + shift = 0 + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value ='src[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = '0' + if dst_channel.type in (UNSIGNED, SIGNED): + if shift + dst_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) + if shift: + value = '(%s) << %u' % (value, shift) + if dst_channel.type == SIGNED: + # Cast to unsigned + value = '(uint%u_t)(%s) ' % (depth, value) + else: + value = None + if value is not None: + print ' value |= %s;' % (value) + + shift += dst_channel.size + + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' + + print ' *(uint%u_t *)dst = value;' % depth + + else: + print ' union util_format_%s pixel;' % format.short_name() + + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is None: + continue value ='src[%u]' % inv_swizzle[i] value = conversion_expr(src_channel, dst_channel, dst_native_type, value) if format.colorspace == ZS: @@ -449,50 +488,14 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): value = get_one(dst_channel) elif i >= 1: value = '0' - if dst_channel.type in (UNSIGNED, SIGNED): - if shift + dst_channel.size < depth: - value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) - if shift: - value = '(%s) << %u' % (value, shift) - if dst_channel.type == SIGNED: - # Cast to unsigned - value = '(uint%u_t)(%s) ' % (depth, value) - else: - value = None - if value is not None: - print ' value |= %s;' % (value) - - shift += dst_channel.size - - print '#ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print '#endif' - - print ' *(uint%u_t *)dst = value;' % depth - - else: - print ' union util_format_%s pixel;' % format.short_name() - - for i in range(4): - dst_channel = format.channels[i] - width = dst_channel.size - if inv_swizzle[i] is None: - continue - value ='src[%u]' % inv_swizzle[i] - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - if format.colorspace == ZS: - if i == 3: - value = get_one(dst_channel) - elif i >= 1: - value = '0' - print ' pixel.chan.%s = %s;' % (dst_channel.name, value) - - bswap_format(format) - print ' memcpy(dst, &pixel, sizeof pixel);' + print ' pixel.chan.%s = %s;' % (dst_channel.name, value) - print ' src += 4;' - print ' dst += %u;' % (format.block_size() / 8,) - print ' }' + bswap_format(format) + print ' memcpy(dst, &pixel, sizeof pixel);' + + print ' src += 4;' + print ' dst += %u;' % (format.block_size() / 8,) + print ' }' print '}' print @@ -502,67 +505,17 @@ def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix): '''Generate the dispatch function to unpack pixels from any format''' for format in formats: - if is_format_supported(format): - generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) - - print 'static INLINE void' - print 'util_format_unpack_%s(enum pipe_format format, %s *dst, const uint8_t *src, unsigned length)' % (dst_suffix, dst_native_type) - print '{' - print ' void (*func)(%s *dst, const uint8_t *src, unsigned length);' % dst_native_type - print ' switch(format) {' - for format in formats: - if is_format_supported(format): - print ' case %s:' % format.name - print ' func = &util_format_%s_unpack_%s;' % (format.short_name(), dst_suffix) - print ' break;' - print ' default:' - print ' debug_printf("unsupported format\\n");' - print ' return;' - print ' }' - print ' func(dst, src, length);' - print '}' - print + generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) def generate_pack(formats, src_channel, src_native_type, src_suffix): '''Generate the dispatch function to pack pixels to any format''' for format in formats: - if is_format_supported(format): - generate_format_pack(format, src_channel, src_native_type, src_suffix) - - print 'static INLINE void' - print 'util_format_pack_%s(enum pipe_format format, uint8_t *dst, const %s *src, unsigned length)' % (src_suffix, src_native_type) - print '{' - print ' void (*func)(uint8_t *dst, const %s *src, unsigned length);' % (src_native_type,) - print ' switch(format) {' - for format in formats: - if is_format_supported(format): - print ' case %s:' % format.name - print ' func = &util_format_%s_pack_%s;' % (format.short_name(), src_suffix) - print ' break;' - print ' default:' - print ' debug_printf("%s: unsupported format\\n", __FUNCTION__);' - print ' return;' - print ' }' - print ' func(dst, src, length);' - print '}' - print - + generate_format_pack(format, src_channel, src_native_type, src_suffix) -def main(): - formats = [] - for arg in sys.argv[1:]: - formats.extend(parse(arg)) - print '/* This file is autogenerated by u_format_pack.py from u_format.csv. Do not edit directly. */' - print - # This will print the copyright message on the top of this file - print __doc__.strip() - - print - print '#ifndef U_FORMAT_PACK_H' - print '#define U_FORMAT_PACK_H' +def generate(formats): print print '#include "pipe/p_compiler.h"' print '#include "u_math.h"' @@ -572,30 +525,20 @@ def main(): generate_clamp() for format in formats: - if format.layout == PLAIN: + if is_format_supported(format): generate_format_type(format) channel = Channel(FLOAT, False, 32) native_type = 'float' - suffix = '4f' + suffix = 'float' generate_unpack(formats, channel, native_type, suffix) generate_pack(formats, channel, native_type, suffix) channel = Channel(UNSIGNED, True, 8) native_type = 'uint8_t' - suffix = '4ub' + suffix = '8unorm' generate_unpack(formats, channel, native_type, suffix) generate_pack(formats, channel, native_type, suffix) - print - print '#ifdef __cplusplus' - print '}' - print '#endif' - print - print '#endif /* ! U_FORMAT_PACK_H */' - - -if __name__ == '__main__': - main() diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index fb68852a53..fe910d9a77 100755 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -33,6 +33,7 @@ import sys from u_format_parse import * +import u_format_pack def layout_map(layout): @@ -86,6 +87,27 @@ def write_format_table(formats): print print '#include "u_format.h"' print + print ''' +static void +util_format_none_unpack_8unorm(uint8_t *dst, const uint8_t *src, unsigned length) +{ +} + +static void +util_format_none_pack_8unorm(uint8_t *dst, const uint8_t *src, unsigned length) +{ +} + +static void +util_format_none_unpack_float(float *dst, const uint8_t *src, unsigned length) +{ +} + +static void +util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length) +{ +} + ''' print 'const struct util_format_description' print 'util_format_none_description = {' print " PIPE_FORMAT_NONE," @@ -99,9 +121,16 @@ def write_format_table(formats): print " 0," print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}," print " {0, 0, 0, 0}," - print " 0" + print " 0," + print " &util_format_none_unpack_8unorm," + print " &util_format_none_pack_8unorm," + print " &util_format_none_unpack_float," + print " &util_format_none_pack_float" print "};" print + + u_format_pack.generate(formats) + for format in formats: print 'const struct util_format_description' print 'util_format_%s_description = {' % (format.short_name(),) @@ -140,8 +169,13 @@ def write_format_table(formats): print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment) print " }," print " %s," % (colorspace_map(format.colorspace),) + print " &util_format_%s_unpack_8unorm," % format.short_name() + print " &util_format_%s_pack_8unorm," % format.short_name() + print " &util_format_%s_unpack_float," % format.short_name() + print " &util_format_%s_pack_float" % format.short_name() print "};" print + print "const struct util_format_description *" print "util_format_description(enum pipe_format format)" print "{" -- cgit v1.2.3 From c5d4a44f449a8203a8b1da9b18806a718d80f131 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 17:26:31 +0100 Subject: util: Use u_format_pack.py's code instead of u_format_access.py. --- src/gallium/auxiliary/Makefile | 3 +- src/gallium/auxiliary/SConscript | 9 +- src/gallium/auxiliary/util/.gitignore | 1 - src/gallium/auxiliary/util/u_format.c | 146 +++++++++++ src/gallium/auxiliary/util/u_format_access.py | 344 -------------------------- src/gallium/auxiliary/util/u_format_pack.py | 15 ++ 6 files changed, 163 insertions(+), 355 deletions(-) create mode 100644 src/gallium/auxiliary/util/u_format.c delete mode 100644 src/gallium/auxiliary/util/u_format_access.py (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 903c5a331c..4df3fbd132 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -105,7 +105,7 @@ C_SOURCES = \ util/u_cpu_detect.c \ util/u_dl.c \ util/u_draw_quad.c \ - util/u_format_access.c \ + util/u_format.c \ util/u_format_table.c \ util/u_format_tests.c \ util/u_gen_mipmap.c \ @@ -167,7 +167,6 @@ GALLIVM_CPP_SOURCES = \ GENERATED_SOURCES = \ indices/u_indices_gen.c \ indices/u_unfilled_gen.c \ - util/u_format_access.c \ util/u_format_table.c diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 772ab41523..db2c13ce5b 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -30,13 +30,6 @@ env.CodeGenerate( command = 'python $SCRIPT $SOURCE > $TARGET' ) -env.CodeGenerate( - target = 'util/u_format_access.c', - script = 'util/u_format_access.py', - source = ['util/u_format.csv'], - command = 'python $SCRIPT $SOURCE > $TARGET' -) - source = [ 'cso_cache/cso_context.c', 'cso_cache/cso_cache.c', @@ -142,7 +135,7 @@ source = [ 'util/u_dump_state.c', 'util/u_dl.c', 'util/u_draw_quad.c', - 'util/u_format_access.c', + 'util/u_format.c', 'util/u_format_table.c', 'util/u_format_tests.c', 'util/u_gen_mipmap.c', diff --git a/src/gallium/auxiliary/util/.gitignore b/src/gallium/auxiliary/util/.gitignore index 29c586c9b5..53fe9b8a65 100644 --- a/src/gallium/auxiliary/util/.gitignore +++ b/src/gallium/auxiliary/util/.gitignore @@ -1,2 +1 @@ -u_format_access.c u_format_table.c diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c new file mode 100644 index 0000000000..11ef839ec1 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format.c @@ -0,0 +1,146 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Pixel format accessor functions. + * + * @author Jose Fonseca + */ + +#include "u_format.h" + + +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) +{ + 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); + + 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; + 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); + } +} + + +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) +{ + 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); + + 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; + 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); + } +} + + +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 uint8_t *src_row; + uint8_t *dst_row; + unsigned row_blocks; + unsigned i; + + 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; + 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); + } +} + + +void +util_format_write_4ub(enum pipe_format format, const uint8_t *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 uint8_t *src_row; + unsigned row_blocks; + unsigned i; + + 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; + 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); + } +} + diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py deleted file mode 100644 index 1c76d9a79d..0000000000 --- a/src/gallium/auxiliary/util/u_format_access.py +++ /dev/null @@ -1,344 +0,0 @@ -#!/usr/bin/env python - -''' -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * @file - * Pixel format accessor functions. - * - * @author Jose Fonseca - */ -''' - - -import math -import sys - -from u_format_pack import * - - -def is_format_supported(format): - '''Determines whether we actually have the plumbing necessary to generate the - to read/write to/from this format.''' - - # FIXME: Ideally we would support any format combination here. - - # XXX: It should be straightforward to support srgb - if format.colorspace not in ('rgb', 'zs'): - return False - - if format.layout != PLAIN: - return False - - for i in range(4): - channel = format.channels[i] - if channel.type not in (VOID, UNSIGNED, FLOAT): - return False - if channel.type == FLOAT: - if channel.size not in (32, 64) or format.is_mixed(): - return False - - # We can only read a color from a depth/stencil format if the depth channel is present - if format.colorspace == 'zs' and format.swizzles[0] == SWIZZLE_NONE: - return False - - return True - - -def native_type(format): - '''Get the native appropriate for a format.''' - - if format.layout == PLAIN: - if not format.is_array(): - # For arithmetic pixel formats return the integer type that matches the whole pixel - return 'uint%u_t' % format.block_size() - else: - # For array pixel formats return the integer type that matches the color channel - channel = format.channels[0] - if channel.type in (UNSIGNED, VOID): - return 'uint%u_t' % channel.size - elif channel.type == SIGNED: - return 'int%u_t' % channel.size - elif channel.type == FLOAT: - if channel.size == 32: - return 'float' - elif channel.size == 64: - return 'double' - else: - assert False - else: - assert False - else: - assert False - - -def generate_srgb_tables(): - print 'static ubyte srgb_to_linear[256] = {' - for i in range(256): - print ' %s,' % (int(math.pow((i / 255.0 + 0.055) / 1.055, 2.4) * 255)) - print '};' - print - print 'static ubyte linear_to_srgb[256] = {' - print ' 0,' - for i in range(1, 256): - print ' %s,' % (int((1.055 * math.pow(i / 255.0, 0.41666) - 0.055) * 255)) - print '};' - print - - -def generate_format_read(format, dst_channel, dst_native_type, dst_suffix): - '''Generate the function to read pixels from a particular format''' - - name = format.short_name() - - src_native_type = native_type(format) - - print 'static void' - print 'util_format_%s_read_%s(%s *dst, unsigned dst_stride, const uint8_t *src, unsigned src_stride, unsigned x0, unsigned y0, unsigned w, unsigned h)' % (name, dst_suffix, dst_native_type) - print '{' - print ' unsigned x, y;' - print ' const uint8_t *src_row = src + y0*src_stride;' - print ' %s *dst_row = dst;' % dst_native_type - print ' for (y = 0; y < h; ++y) {' - print ' const %s *src_pixel = (const %s *)(src_row + x0*%u);' % (src_native_type, src_native_type, format.stride()) - print ' %s *dst_pixel = dst_row;' %dst_native_type - print ' for (x = 0; x < w; ++x) {' - - names = ['']*4 - if format.colorspace == 'rgb': - for i in range(4): - swizzle = format.swizzles[i] - if swizzle < 4: - names[swizzle] += 'rgba'[i] - elif format.colorspace == 'zs': - swizzle = format.swizzles[0] - if swizzle < 4: - names[swizzle] = 'z' - else: - assert False - else: - assert False - - if format.layout == PLAIN: - if not format.is_array(): - print ' %s pixel = *src_pixel++;' % src_native_type - shift = 0; - for i in range(4): - src_channel = format.channels[i] - width = src_channel.size - if names[i]: - value = 'pixel' - mask = (1 << width) - 1 - if shift: - value = '(%s >> %u)' % (value, shift) - if shift + width < format.block_size(): - value = '(%s & 0x%x)' % (value, mask) - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - print ' %s %s = %s;' % (dst_native_type, names[i], value) - shift += width - else: - for i in range(4): - src_channel = format.channels[i] - if names[i]: - value = 'src_pixel[%u]' % i - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - print ' %s %s = %s;' % (dst_native_type, names[i], value) - print ' src_pixel += %u;' % (format.nr_channels()) - else: - assert False - - for i in range(4): - if format.colorspace == 'rgb': - swizzle = format.swizzles[i] - if swizzle < 4: - value = names[swizzle] - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: - value = get_one(dst_channel) - else: - assert False - elif format.colorspace == 'zs': - if i < 3: - value = 'z' - else: - value = get_one(dst_channel) - else: - assert False - print ' *dst_pixel++ = %s; /* %s */' % (value, 'rgba'[i]) - - print ' }' - print ' src_row += src_stride;' - print ' dst_row += dst_stride/sizeof(*dst_row);' - print ' }' - print '}' - print - - -def generate_format_write(format, src_channel, src_native_type, src_suffix): - '''Generate the function to write pixels to a particular format''' - - name = format.short_name() - - dst_native_type = native_type(format) - - print 'static void' - print 'util_format_%s_write_%s(const %s *src, unsigned src_stride, uint8_t *dst, unsigned dst_stride, unsigned x0, unsigned y0, unsigned w, unsigned h)' % (name, src_suffix, src_native_type) - print '{' - print ' unsigned x, y;' - print ' uint8_t *dst_row = dst + y0*dst_stride;' - print ' const %s *src_row = src;' % src_native_type - print ' for (y = 0; y < h; ++y) {' - print ' %s *dst_pixel = (%s *)(dst_row + x0*%u);' % (dst_native_type, dst_native_type, format.stride()) - print ' const %s *src_pixel = src_row;' %src_native_type - print ' for (x = 0; x < w; ++x) {' - - inv_swizzle = format.inv_swizzles() - - if format.layout == PLAIN: - if not format.is_array(): - print ' %s pixel = 0;' % dst_native_type - shift = 0; - for i in range(4): - dst_channel = format.channels[i] - width = dst_channel.size - if inv_swizzle[i] is not None: - value = 'src_pixel[%u]' % inv_swizzle[i] - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - if shift: - value = '(%s << %u)' % (value, shift) - print ' pixel |= %s;' % value - shift += width - print ' *dst_pixel++ = pixel;' - else: - for i in range(4): - dst_channel = format.channels[i] - if inv_swizzle[i] is not None: - value = 'src_pixel[%u]' % inv_swizzle[i] - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - print ' *dst_pixel++ = %s;' % value - else: - assert False - print ' src_pixel += 4;' - - print ' }' - print ' dst_row += dst_stride;' - print ' src_row += src_stride/sizeof(*src_row);' - print ' }' - print '}' - print - - -def generate_read(formats, dst_channel, dst_native_type, dst_suffix): - '''Generate the dispatch function to read pixels from any format''' - - for format in formats: - if is_format_supported(format): - generate_format_read(format, dst_channel, dst_native_type, dst_suffix) - - print 'void' - print 'util_format_read_%s(enum pipe_format format, %s *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h)' % (dst_suffix, dst_native_type) - print '{' - print ' void (*func)(%s *dst, unsigned dst_stride, const uint8_t *src, unsigned src_stride, unsigned x0, unsigned y0, unsigned w, unsigned h);' % dst_native_type - print ' switch(format) {' - for format in formats: - if is_format_supported(format): - print ' case %s:' % format.name - print ' func = &util_format_%s_read_%s;' % (format.short_name(), dst_suffix) - print ' break;' - print ' default:' - print ' debug_printf("unsupported format\\n");' - print ' return;' - print ' }' - print ' func(dst, dst_stride, (const uint8_t *)src, src_stride, x, y, w, h);' - print '}' - print - - -def generate_write(formats, src_channel, src_native_type, src_suffix): - '''Generate the dispatch function to write pixels to any format''' - - for format in formats: - if is_format_supported(format): - generate_format_write(format, src_channel, src_native_type, src_suffix) - - print 'void' - print 'util_format_write_%s(enum pipe_format format, const %s *src, unsigned src_stride, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h)' % (src_suffix, src_native_type) - - print '{' - print ' void (*func)(const %s *src, unsigned src_stride, uint8_t *dst, unsigned dst_stride, unsigned x0, unsigned y0, unsigned w, unsigned h);' % src_native_type - print ' switch(format) {' - for format in formats: - if is_format_supported(format): - print ' case %s:' % format.name - print ' func = &util_format_%s_write_%s;' % (format.short_name(), src_suffix) - print ' break;' - print ' default:' - print ' debug_printf("unsupported format\\n");' - print ' return;' - print ' }' - print ' func(src, src_stride, (uint8_t *)dst, dst_stride, x, y, w, h);' - print '}' - print - - -def main(): - formats = [] - for arg in sys.argv[1:]: - formats.extend(parse(arg)) - - print '/* This file is autogenerated by u_format_access.py from u_format.csv. Do not edit directly. */' - print - # This will print the copyright message on the top of this file - print __doc__.strip() - print - print '#include "pipe/p_compiler.h"' - print '#include "u_math.h"' - print '#include "u_format.h"' - print - - generate_srgb_tables() - - type = Channel(FLOAT, False, 32) - native_type = 'float' - suffix = '4f' - - generate_read(formats, type, native_type, suffix) - generate_write(formats, type, native_type, suffix) - - type = Channel(UNSIGNED, True, 8) - native_type = 'uint8_t' - suffix = '4ub' - - generate_read(formats, type, native_type, suffix) - generate_write(formats, type, native_type, suffix) - - -if __name__ == '__main__': - main() diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index f40b3bdf2e..4831912f02 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -38,6 +38,7 @@ import sys +import math from u_format_parse import * @@ -90,6 +91,20 @@ def generate_format_type(format): print +def generate_srgb_tables(): + print 'static ubyte srgb_to_linear[256] = {' + for i in range(256): + print ' %s,' % (int(math.pow((i / 255.0 + 0.055) / 1.055, 2.4) * 255)) + print '};' + print + print 'static ubyte linear_to_srgb[256] = {' + print ' 0,' + for i in range(1, 256): + print ' %s,' % (int((1.055 * math.pow(i / 255.0, 0.41666) - 0.055) * 255)) + print '};' + print + + def bswap_format(format): '''Generate a structure that describes the format.''' -- cgit v1.2.3 From 69895725cfe9d4dc917ff6e643af9e6e3a6e093f Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 20:15:17 +0100 Subject: util: Add callback to fetch a single pixel. --- progs/gallium/unit/u_format_test.c | 34 +++ src/gallium/auxiliary/util/u_format.h | 17 +- src/gallium/auxiliary/util/u_format_pack.py | 360 ++++++++++++++------------- src/gallium/auxiliary/util/u_format_table.py | 11 +- 4 files changed, 248 insertions(+), 174 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index e96f0a9d12..ba4e9fab66 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -33,6 +33,37 @@ #include "util/u_format_tests.h" +static boolean +test_format_fetch_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[4]; + unsigned i; + boolean success; + + /* + * TODO: test block formats too. + */ + if (format_desc->block.width != 1 && format_desc->block.height != 1) { + return TRUE; + } + + format_desc->fetch_float(unpacked, test->packed, 0, 0); + + success = TRUE; + for (i = 0; i < 4; ++i) + if (test->unpacked[i] != unpacked[i]) + success = FALSE; + + if (!success) { + printf("FAILED: (%f %f %f %f) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]); + printf(" (%f %f %f %f) expected\n", test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); + } + + return success; +} + + static boolean test_format_unpack_float(const struct util_format_description *format_desc, const struct util_format_test_case *test) @@ -225,6 +256,9 @@ test_all(void) { bool success = TRUE; + if (!test_one(&test_format_fetch_float, "fetch_float")) + success = FALSE; + if (!test_one(&test_format_pack_float, "pack_float")) success = FALSE; diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 609d398ebf..8e76e13b66 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -191,21 +191,34 @@ struct util_format_description enum util_format_colorspace colorspace; /** - * Accessor functions. + * Unpack a span of pixel blocks to R8G8B8A8_UNORM. */ - void (*unpack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + /** + * Pack a span of pixel blocks from R8G8B8A8_UNORM. + */ void (*pack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + /** + * Unpack a span of pixel blocks to R32G32B32A32_FLOAT. + */ void (*unpack_float)(float *dst, const uint8_t *src, unsigned nr_blocks); + /** + * Pack a span of pixel blocks from R32G32B32A32_FLOAT. + */ void (*pack_float)(uint8_t *dst, const float *src, unsigned nr_blocks); + /** + * Fetch a single pixel (i, j) from a block. + */ + void + (*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 4831912f02..c74900ce63 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -324,115 +324,190 @@ def conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=True assert False -def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): - '''Generate the function to unpack pixels from a particular format''' - - 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 '{' +def generate_unpack_kernel(format, dst_channel, dst_native_type): - if is_format_supported(format): - - assert format.layout == PLAIN - - src_native_type = native_type(format) - - print ' while(length--) {' - - if format.is_bitmask(): - depth = format.block_size() - print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth) + if not is_format_supported(format): + return - # 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) - elif src_channel.type == SIGNED: - print ' int%u_t %s;' % (depth, src_channel.name) + assert format.layout == PLAIN + + src_native_type = native_type(format) + + if format.is_bitmask(): + depth = format.block_size() + 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) + elif src_channel.type == SIGNED: + print ' int%u_t %s;' % (depth, src_channel.name) + + print ' #ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print ' #endif' + + # Compute the intermediate unshifted values + shift = 0 + for i in range(format.nr_channels()): + src_channel = format.channels[i] + value = 'value' + if src_channel.type == UNSIGNED: + if shift: + value = '%s >> %u' % (value, shift) + if shift + src_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) + elif src_channel.type == SIGNED: + if shift + src_channel.size < depth: + # Align the sign bit + lshift = depth - (shift + src_channel.size) + value = '%s << %u' % (value, lshift) + # Cast to signed + value = '(int%u_t)(%s) ' % (depth, value) + if src_channel.size < depth: + # Align the LSB bit + rshift = depth - src_channel.size + value = '(%s) >> %u' % (value, rshift) + else: + value = None + + if value is not None: + print ' %s = %s;' % (src_channel.name, value) + + shift += src_channel.size + + # Convert, swizzle, and store final values + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + 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);' + bswap_format(format) - print ' #ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print ' #endif' + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = 'pixel.chan.%s' % src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) - # Compute the intermediate unshifted values - shift = 0 - for i in range(format.nr_channels()): - src_channel = format.channels[i] - value = 'value' - if src_channel.type == UNSIGNED: - if shift: - value = '%s >> %u' % (value, shift) - if shift + src_channel.size < depth: - value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) - elif src_channel.type == SIGNED: - if shift + src_channel.size < depth: - # Align the sign bit - lshift = depth - (shift + src_channel.size) - value = '%s << %u' % (value, lshift) - # Cast to signed - value = '(int%u_t)(%s) ' % (depth, value) - if src_channel.size < depth: - # Align the LSB bit - rshift = depth - src_channel.size - value = '(%s) >> %u' % (value, rshift) - else: - value = None - - if value is not None: - print ' %s = %s;' % (src_channel.name, value) - - shift += src_channel.size + +def generate_pack_kernel(format, src_channel, src_native_type): + + if not is_format_supported(format): + return - # Convert, swizzle, and store final values - for i in range(4): - swizzle = format.swizzles[i] - if swizzle < 4: - src_channel = format.channels[swizzle] - value = src_channel.name - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: - value = get_one(dst_channel) - elif swizzle == SWIZZLE_NONE: - value = '0' - else: - assert False + dst_native_type = native_type(format) + + assert format.layout == PLAIN + + inv_swizzle = format.inv_swizzles() + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = 0;' % depth + + shift = 0 + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value ='src[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) if format.colorspace == ZS: if i == 3: value = get_one(dst_channel) elif i >= 1: - value = 'dst[0]' - 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);' - bswap_format(format) + value = '0' + if dst_channel.type in (UNSIGNED, SIGNED): + if shift + dst_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) + if shift: + value = '(%s) << %u' % (value, shift) + if dst_channel.type == SIGNED: + # Cast to unsigned + value = '(uint%u_t)(%s) ' % (depth, value) + else: + value = None + if value is not None: + print ' value |= %s;' % (value) + + shift += dst_channel.size + + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' - for i in range(4): - swizzle = format.swizzles[i] - if swizzle < 4: - src_channel = format.channels[swizzle] - value = 'pixel.chan.%s' % src_channel.name - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: + print ' *(uint%u_t *)dst = value;' % depth + + else: + print ' union util_format_%s pixel;' % format.short_name() + + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is None: + continue + value ='src[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + if format.colorspace == ZS: + if i == 3: value = get_one(dst_channel) - elif swizzle == SWIZZLE_NONE: + elif i >= 1: value = '0' - else: - assert False - if format.colorspace == ZS: - if i == 3: - value = get_one(dst_channel) - elif i >= 1: - value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + print ' pixel.chan.%s = %s;' % (dst_channel.name, value) + + bswap_format(format) + print ' memcpy(dst, &pixel, sizeof pixel);' + + +def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): + '''Generate the function to unpack pixels from a particular format''' + + 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 '{' + + if is_format_supported(format): + print ' while(length--) {' + + generate_unpack_kernel(format, dst_channel, dst_native_type) print ' src += %u;' % (format.block_size() / 8,) print ' dst += 4;' @@ -452,69 +527,9 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): print '{' if is_format_supported(format): - dst_native_type = native_type(format) - - assert format.layout == PLAIN - - inv_swizzle = format.inv_swizzles() - print ' while(length--) {' - if format.is_bitmask(): - depth = format.block_size() - print ' uint%u_t value = 0;' % depth - - shift = 0 - for i in range(4): - dst_channel = format.channels[i] - if inv_swizzle[i] is not None: - value ='src[%u]' % inv_swizzle[i] - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - if format.colorspace == ZS: - if i == 3: - value = get_one(dst_channel) - elif i >= 1: - value = '0' - if dst_channel.type in (UNSIGNED, SIGNED): - if shift + dst_channel.size < depth: - value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) - if shift: - value = '(%s) << %u' % (value, shift) - if dst_channel.type == SIGNED: - # Cast to unsigned - value = '(uint%u_t)(%s) ' % (depth, value) - else: - value = None - if value is not None: - print ' value |= %s;' % (value) - - shift += dst_channel.size - - print '#ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print '#endif' - - print ' *(uint%u_t *)dst = value;' % depth - - else: - print ' union util_format_%s pixel;' % format.short_name() - - for i in range(4): - dst_channel = format.channels[i] - width = dst_channel.size - if inv_swizzle[i] is None: - continue - value ='src[%u]' % inv_swizzle[i] - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - if format.colorspace == ZS: - if i == 3: - value = get_one(dst_channel) - elif i >= 1: - value = '0' - print ' pixel.chan.%s = %s;' % (dst_channel.name, value) - - bswap_format(format) - print ' memcpy(dst, &pixel, sizeof pixel);' + generate_pack_kernel(format, src_channel, src_native_type) print ' src += 4;' print ' dst += %u;' % (format.block_size() / 8,) @@ -524,18 +539,20 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): print -def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix): - '''Generate the dispatch function to unpack pixels from any format''' +def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix): + '''Generate the function to unpack pixels from a particular format''' - for format in formats: - generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) + name = format.short_name() + print 'static INLINE void' + print 'util_format_%s_fetch_%s(%s *dst, const uint8_t *src, unsigned i, unsigned j)' % (name, dst_suffix, dst_native_type) + print '{' -def generate_pack(formats, src_channel, src_native_type, src_suffix): - '''Generate the dispatch function to pack pixels to any format''' + if is_format_supported(format): + generate_unpack_kernel(format, dst_channel, dst_native_type) - for format in formats: - generate_format_pack(format, src_channel, src_native_type, src_suffix) + print '}' + print def generate(formats): @@ -555,13 +572,16 @@ def generate(formats): native_type = 'float' suffix = 'float' - generate_unpack(formats, channel, native_type, suffix) - generate_pack(formats, channel, native_type, suffix) + for format in formats: + generate_format_unpack(format, channel, native_type, suffix) + generate_format_pack(format, channel, native_type, suffix) + generate_format_fetch(format, channel, native_type, suffix) channel = Channel(UNSIGNED, True, 8) native_type = 'uint8_t' suffix = '8unorm' - generate_unpack(formats, channel, native_type, suffix) - generate_pack(formats, channel, native_type, suffix) + for format in formats: + generate_format_unpack(format, channel, native_type, suffix) + generate_format_pack(format, channel, native_type, suffix) diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index fe910d9a77..6877bd6844 100755 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -106,6 +106,11 @@ util_format_none_unpack_float(float *dst, const uint8_t *src, unsigned length) static void util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length) { +} + +static void +util_format_none_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ } ''' print 'const struct util_format_description' @@ -125,7 +130,8 @@ util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length) print " &util_format_none_unpack_8unorm," print " &util_format_none_pack_8unorm," print " &util_format_none_unpack_float," - print " &util_format_none_pack_float" + print " &util_format_none_pack_float," + print " &util_format_none_fetch_float" print "};" print @@ -172,7 +178,8 @@ util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length) print " &util_format_%s_unpack_8unorm," % format.short_name() print " &util_format_%s_pack_8unorm," % format.short_name() print " &util_format_%s_unpack_float," % format.short_name() - print " &util_format_%s_pack_float" % format.short_name() + print " &util_format_%s_pack_float," % format.short_name() + print " &util_format_%s_fetch_float" % format.short_name() print "};" print -- cgit v1.2.3 From b8012643e1f5f6e49593ec8f04d3721df53e6afb Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Wed, 31 Mar 2010 21:54:54 +0200 Subject: util: First stab at half-float conversion. --- src/gallium/auxiliary/util/u_format_pack.py | 101 +++++++++++++++------------- 1 file changed, 55 insertions(+), 46 deletions(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index c74900ce63..26f8748604 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -43,6 +43,45 @@ import math from u_format_parse import * +def generate_f16_to_f32(): + '''Naive implementation, need something faster that operates on bits''' + + print ''' +static float +f16_to_f32(uint16_t h) +{ + unsigned mantissa = h & 0x3ff; + unsigned exponent = (h >> 10) & 0x1f; + float sign = (h & 0x8000) ? -1.0f : 1.0f; + + if (exponent == 0) { + if (mantissa == 0) { + return sign * 0.0f; + } + return sign * powf(2.0f, -14.0f) * (float)mantissa / 1024.0f; + } + if (exponent == 31) { + if (mantissa == 0) { + /* XXX: infinity */ + return sign * 100000.0f; + } + /* XXX: NaN */ + return 1000.0f; + } + return sign * powf(2.0f, (float)exponent - 15.0f) * (1.0f + (float)mantissa / 1024.0f); +} +''' + +def generate_f32_to_f16(): + print ''' +static uint16_t +f32_to_f16(float f) +{ + /* TODO */ + return 0; +} +''' + def generate_format_type(format): '''Generate a structure that describes the format.''' @@ -127,9 +166,6 @@ def is_format_supported(format): channel = format.channels[i] if channel.type not in (VOID, UNSIGNED, SIGNED, FLOAT): return False - if channel.type == FLOAT: - if channel.size not in (32, 64): - return False # We can only read a color from a depth/stencil format if the depth channel is present if format.colorspace == 'zs' and format.swizzles[0] == SWIZZLE_NONE: @@ -153,7 +189,9 @@ def native_type(format): elif channel.type == SIGNED: return 'int%u_t' % channel.size elif channel.type == FLOAT: - if channel.size == 32: + if channel.size == 16: + return 'uint16_t' + elif channel.size == 32: return 'float' elif channel.size == 64: return 'double' @@ -202,31 +240,6 @@ def get_one(type): return (1 << get_one_shift(type)) - 1 -def generate_clamp(): - '''Code generate the clamping functions for each type. - - We don't use a macro so that arguments with side effects, - like *src_pixel++ are correctly handled. - ''' - - for suffix, native_type in [ - ('', 'double'), - ('f', 'float'), - ('ui', 'unsigned int'), - ('si', 'int'), - ]: - print 'static INLINE %s' % native_type - print 'clamp%s(%s value, %s lbound, %s ubound)' % (suffix, native_type, native_type, native_type) - print '{' - print ' if(value < lbound)' - print ' return lbound;' - print ' if(value > ubound)' - print ' return ubound;' - print ' return value;' - print '}' - print - - def clamp_expr(src_channel, dst_channel, dst_native_type, value): '''Generate the expression to clamp the value in the source type to the destination type range.''' @@ -234,21 +247,6 @@ def clamp_expr(src_channel, dst_channel, dst_native_type, value): if src_channel == dst_channel: return value - # Pick the approriate clamp function - if src_channel.type == FLOAT: - if src_channel.size == 32: - func = 'clampf' - elif src_channel.size == 64: - func = 'clamp' - else: - assert False - elif src_channel.type == UNSIGNED: - func = 'clampui' - elif src_channel.type == SIGNED: - func = 'clampsi' - else: - assert False - src_min = src_channel.min() src_max = src_channel.max() dst_min = dst_channel.min() @@ -273,7 +271,17 @@ def conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=True return value if src_channel.type == FLOAT and dst_channel.type == FLOAT: - return '(%s)%s' % (dst_native_type, value) + if src_channel.size == dst_channel.size: + return value + if src_channel.size == 64: + value = '(float)%s' % (value) + elif src_channel.size == 16: + value = 'f16_to_f32(%s)' % (value) + if dst_channel.size == 16: + value = 'f32_to_f16(%s)' % (value) + elif dst_channel.size == 64: + value = '(double)%s' % (value) + return value if clamp: value = clamp_expr(src_channel, dst_channel, dst_native_type, value) @@ -562,7 +570,8 @@ def generate(formats): print '#include "u_format.h"' print - generate_clamp() + generate_f16_to_f32() + generate_f32_to_f16() for format in formats: if is_format_supported(format): -- cgit v1.2.3 From 018aae950df449a18d7d69de54d51af587be94c6 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 21:16:16 +0100 Subject: 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(-) (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index ba4e9fab66..54cb6b879e 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 11ef839ec1..7f16cf7d01 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 0fad81fe40..93818a3161 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 26f8748604..73309cca5c 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 -- cgit v1.2.3 From 9388ce41917fa4c706c5e284d960e1ca648ee935 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Mar 2010 22:46:42 +0100 Subject: util: Hook into libtxc_dxtn.so (WIP). --- src/gallium/auxiliary/Makefile | 1 + src/gallium/auxiliary/SConscript | 1 + src/gallium/auxiliary/util/u_format_pack.py | 12 +- src/gallium/auxiliary/util/u_format_s3tc.c | 510 +++++++++++++++++++++++++++ src/gallium/auxiliary/util/u_format_s3tc.h | 218 ++++++++++++ src/gallium/auxiliary/util/u_format_table.py | 1 + 6 files changed, 738 insertions(+), 5 deletions(-) create mode 100644 src/gallium/auxiliary/util/u_format_s3tc.c create mode 100644 src/gallium/auxiliary/util/u_format_s3tc.h (limited to 'src/gallium/auxiliary/util/u_format_pack.py') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 4df3fbd132..4c629924b9 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -106,6 +106,7 @@ C_SOURCES = \ util/u_dl.c \ util/u_draw_quad.c \ util/u_format.c \ + util/u_format_s3tc.c \ util/u_format_table.c \ util/u_format_tests.c \ util/u_gen_mipmap.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 0f1cc374c1..ed719f9f1a 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -140,6 +140,7 @@ source = [ 'util/u_dl.c', 'util/u_draw_quad.c', 'util/u_format.c', + 'util/u_format_s3tc.c', 'util/u_format_table.c', 'util/u_format_tests.c', 'util/u_gen_mipmap.c', diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 73309cca5c..95c0c79be9 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -596,15 +596,17 @@ def generate(formats): suffix = 'float' for format in formats: - generate_format_unpack(format, channel, native_type, suffix) - generate_format_pack(format, channel, native_type, suffix) - generate_format_fetch(format, channel, native_type, suffix) + if format.layout != 's3tc': + generate_format_unpack(format, channel, native_type, suffix) + generate_format_pack(format, channel, native_type, suffix) + generate_format_fetch(format, channel, native_type, suffix) channel = Channel(UNSIGNED, True, 8) native_type = 'uint8_t' suffix = '8unorm' for format in formats: - generate_format_unpack(format, channel, native_type, suffix) - generate_format_pack(format, channel, native_type, suffix) + if format.layout != 's3tc': + generate_format_unpack(format, channel, native_type, suffix) + generate_format_pack(format, channel, native_type, suffix) diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c new file mode 100644 index 0000000000..4fe00b0e43 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_s3tc.c @@ -0,0 +1,510 @@ +/************************************************************************** + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "u_dl.h" +#include "u_math.h" +#include "u_format.h" +#include "u_format_s3tc.h" + + +#if defined(_WIN32) || defined(WIN32) +#define DXTN_LIBNAME "dxtn.dll" +#else +#define DXTN_LIBNAME "libtxc_dxtn.so" +#endif + + +boolean util_format_s3tc_enabled = FALSE; + +util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = NULL; +util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = NULL; +util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = NULL; +util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = NULL; + +util_format_dxtn_pack_t util_format_dxtn_pack = NULL; + + +void +util_format_s3tc_init(void) +{ + static struct util_dl_library * + library = NULL; + + if (util_format_s3tc_enabled) + return; + + if (!library) { + library = util_dl_open(DXTN_LIBNAME); + if (!library) { + debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn " + "compression/decompression unavailable"); + } + else { + util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t) + util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1"); + util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t) + util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1"); + util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t) + util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3"); + util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t) + util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5"); + util_format_dxtn_pack = (util_format_dxtn_pack_t) + util_dl_get_proc_address(library, "tx_compress_dxtn"); + + if (util_format_dxt1_rgb_fetch || + util_format_dxt1_rgba_fetch || + util_format_dxt3_rgba_fetch || + util_format_dxt5_rgba_fetch || + util_format_dxtn_pack) { + util_format_s3tc_enabled = TRUE; + debug_printf("software DXTn compression/decompression available"); + + } else { + debug_printf("couldn't reference all symbols in " + DXTN_LIBNAME ", software DXTn compression/decompression " + "unavailable"); + } + } + } +} + + +/* + * Pixel fetch. + */ + +void +util_format_dxt1_rgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt1_rgb_fetch) { + util_format_dxt1_rgb_fetch(0, src, i, j, dst); + } +} + +void +util_format_dxt1_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt1_rgba_fetch) { + util_format_dxt1_rgba_fetch(0, src, i, j, dst); + } +} + +void +util_format_dxt3_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt3_rgba_fetch) { + util_format_dxt3_rgba_fetch(0, src, i, j, dst); + } +} + +void +util_format_dxt5_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt5_rgba_fetch) { + util_format_dxt5_rgba_fetch(0, src, i, j, dst); + } +} + +void +util_format_dxt1_rgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt1_rgb_fetch) { + uint8_t tmp[4]; + util_format_dxt1_rgb_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = 1.0; + } +} + +void +util_format_dxt1_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt1_rgba_fetch) { + uint8_t tmp[4]; + util_format_dxt1_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } +} + +void +util_format_dxt3_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt3_rgba_fetch) { + uint8_t tmp[4]; + util_format_dxt3_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } +} + +void +util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + if (util_format_dxt5_rgba_fetch) { + uint8_t tmp[4]; + util_format_dxt5_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } +} + + +/* + * Block decompression. + * + * FIXME + */ + +void +util_format_dxt1_rgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt1_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + +} + +void +util_format_dxt3_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt5_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt1_rgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + if (util_format_dxt1_rgb_fetch) { + unsigned x, y, i, j; + for(y = 0; y < height; y += 4) { + const uint8_t *src = src_row; + for(x = 0; x < width; x += 4) { + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4; + uint8_t tmp[4]; + util_format_dxt1_rgb_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = 1.0; + } + } + src += 8; + } + src_row += src_stride; + } + } +} + +void +util_format_dxt1_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + if (util_format_dxt1_rgba_fetch) { + unsigned x, y, i, j; + for(y = 0; y < height; y += 4) { + const uint8_t *src = src_row; + for(x = 0; x < width; x += 4) { + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4; + uint8_t tmp[4]; + util_format_dxt1_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } + } + src += 8; + } + src_row += src_stride; + } + } +} + +void +util_format_dxt3_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + if (util_format_dxt3_rgba_fetch) { + unsigned x, y, i, j; + for(y = 0; y < height; y += 4) { + const uint8_t *src = src_row; + for(x = 0; x < width; x += 4) { + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4; + uint8_t tmp[4]; + util_format_dxt3_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } + } + src += 16; + } + src_row += src_stride; + } + } +} + +void +util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + if (util_format_dxt5_rgba_fetch) { + unsigned x, y, i, j; + for(y = 0; y < height; y += 4) { + const uint8_t *src = src_row; + for(x = 0; x < width; x += 4) { + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4; + uint8_t tmp[4]; + util_format_dxt5_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } + } + src += 16; + } + src_row += src_stride; + } + } +} + + +/* + * Block compression. + * + * FIXME + */ + +void +util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt1_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt3_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt5_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt1_rgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt1_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt3_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + +void +util_format_dxt5_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ +} + + +/* + * SRGB variants. + * + * FIXME: shunts to RGB for now + */ + +void +util_format_dxt1_srgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgb_fetch_8unorm(dst, src, i, j); +} + +void +util_format_dxt1_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgba_fetch_8unorm(dst, src, i, j); +} + +void +util_format_dxt3_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt3_rgba_fetch_8unorm(dst, src, i, j); +} + +void +util_format_dxt5_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_unpack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_pack_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt5_rgba_fetch_8unorm(dst, src, i, j); +} + +void +util_format_dxt1_srgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_pack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgb_fetch_float(dst, src, i, j); +} + +void +util_format_dxt1_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_pack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgba_fetch_float(dst, src, i, j); +} + +void +util_format_dxt3_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_pack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt3_rgba_fetch_float(dst, src, i, j); +} + +void +util_format_dxt5_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_unpack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_pack_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt5_rgba_fetch_float(dst, src, i, j); +} + diff --git a/src/gallium/auxiliary/util/u_format_s3tc.h b/src/gallium/auxiliary/util/u_format_s3tc.h new file mode 100644 index 0000000000..5c3a9dd22c --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_s3tc.h @@ -0,0 +1,218 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef U_FORMAT_S3TC_H_ +#define U_FORMAT_S3TC_H_ + + +#include "pipe/p_compiler.h" + + +enum util_format_dxtn { + UTIL_FORMAT_DXT1_RGB = 0x83F0, + UTIL_FORMAT_DXT1_RGBA = 0x83F1, + UTIL_FORMAT_DXT3_RGBA = 0x83F2, + UTIL_FORMAT_DXT5_RGBA = 0x83F3 +}; + + +typedef void +(*util_format_dxtn_fetch_t)( int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst ); + +typedef void +(*util_format_dxtn_pack_t)( int src_comps, + int width, int height, + const uint8_t *src, + enum util_format_dxtn dst_format, + uint8_t *dst, + int dst_stride); + +extern boolean util_format_s3tc_enabled; + +extern util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch; +extern util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch; +extern util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch; +extern util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch; + +extern util_format_dxtn_pack_t util_format_dxtn_pack; + + +void +util_format_s3tc_init(void); + + +void +util_format_dxt1_rgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_srgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_dxt1_rgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_srgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +#endif /* U_FORMAT_S3TC_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index 1309044097..94a4331b15 100755 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -86,6 +86,7 @@ def write_format_table(formats): print __doc__.strip() print print '#include "u_format.h"' + print '#include "u_format_s3tc.h"' print u_format_pack.generate(formats) -- cgit v1.2.3