mesa/src
Neil Roberts a4ab08bf45 format_utils: Use a more precise conversion when decreasing bits
When converting to a format that has fewer bits the previous code was just
shifting off the bits. This doesn't provide very accurate results. For example
when converting from 8 bits to 5 bits it is equivalent to doing this:

x * 32 / 256

This works as if it's taking a value from a range where 256 represents 1.0 and
scaling it down to a range where 32 represents 1.0. However this is not
correct because it is actually 255 and 31 that represent 1.0.

We can do better with a formula like this:

(x * 31 + 127) / 255

The +127 is to make it round correctly.

The new code has a special case to use uint64_t when the result of the
multiplication would overflow an unsigned int. This function is inline and
only ever called with constant values so hopefully the if statements will be
folded.

The main incentive to do this is to make the CPU conversion path pick the same
values as the hardware would if it did the conversion. This fixes failures
with the ‘texsubimage pbo’ test when using the patches from here:

http://lists.freedesktop.org/archives/mesa-dev/2015-January/074312.html

v2: Use 64-bit arithmetic when src_bits+dst_bits > 32

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
2015-01-16 13:53:15 +00:00
..
egl egl/wayland: Fix unused variable warnings 2015-01-13 11:33:23 -08:00
gallium vc4: Add some dumping for STORE_TILE_BUFFER_GENERAL. 2015-01-15 22:21:29 +13:00
gbm gbm: remove support for GCC older than 4.1.0 2014-12-17 08:37:29 +11:00
getopt
glsl nir/live_variables: Use a worklist 2015-01-15 16:54:21 -08:00
glx mesa: remove support for GCC older than 3.3.0 2014-12-17 08:37:05 +11:00
gtest gtest: Add headers to distribution. 2014-12-12 12:11:46 -08:00
hgl hgl: traverse add-on entries 2014-12-10 14:01:01 +00:00
loader mesa: Add scons files to distribution. 2014-12-12 12:11:50 -08:00
mapi mesa/glsl/glapi: enable GL_EXT_draw_buffers extension 2015-01-14 07:48:51 +02:00
mesa format_utils: Use a more precise conversion when decreasing bits 2015-01-16 13:53:15 +00:00
util util/hash_set: Rework the API to know about hashing 2015-01-15 13:21:27 -08:00
Makefile.am mesa: Add scons files to distribution. 2014-12-12 12:11:50 -08:00
SConscript egl: Fix non-dri SCons builds re #87657 2014-12-25 10:34:49 -05:00