Mesa (master): util: Fix rounding of unpack_unorm8 from small unorm formats.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021


Module: Mesa
Branch: master
Commit: b938b488f68118ddefae797b364ffde55f877e1b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b938b488f68118ddefae797b364ffde55f877e1b

Author: Eric Anholt <eric at anholt.net>
Date:   Mon Nov 11 15:29:37 2019 -0800

util: Fix rounding of unpack_unorm8 from small unorm formats.

The code was doing the bit-shift trick, but not accounting for the
rounding necessary which the Mesa unpack code was previously doing.
Using the helpers prevents a regression in
KHR-GL46.copy_image.smoke_test on iris as we consolidate the
pack/unpack code.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>

---

 src/util/format/u_format_pack.py | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/util/format/u_format_pack.py b/src/util/format/u_format_pack.py
index 3545f9a0eae..b59630934dc 100644
--- a/src/util/format/u_format_pack.py
+++ b/src/util/format/u_format_pack.py
@@ -379,21 +379,19 @@ def conversion_expr(src_channel,
             # neither is normalized -- just cast
             return '(%s)%s' % (dst_native_type, value)
 
-        src_one = get_one(src_channel)
-        dst_one = get_one(dst_channel)
-
-        if src_one > dst_one and src_norm and dst_channel.norm:
-            # We can just bitshift
-            src_shift = get_one_shift(src_channel)
-            dst_shift = get_one_shift(dst_channel)
-            value = '(%s >> %s)' % (value, src_shift - dst_shift)
+        if src_norm and dst_channel.norm:
+            return "_mesa_%snorm_to_%snorm(%s, %d, %d)" % ("s" if src_type == SIGNED else "u",
+                                                           "s" if dst_channel.type == SIGNED else "u",
+                                                           value, src_channel.size, dst_channel.size)
         else:
             # We need to rescale using an intermediate type big enough to hold the multiplication of both
+            src_one = get_one(src_channel)
+            dst_one = get_one(dst_channel)
             tmp_native_type = intermediate_native_type(src_size + dst_channel.size, src_channel.sign and dst_channel.sign)
             value = '((%s)%s)' % (tmp_native_type, value)
-            value = '(%s * 0x%x / 0x%x)' % (value, dst_one, src_one)
-        value = '(%s)%s' % (dst_native_type, value)
-        return value
+            value = '(%s)(%s * 0x%x / 0x%x)' % (dst_native_type, value, dst_one, src_one)
+            return value
+
 
     # Promote to either float or double
     if src_type != FLOAT:
@@ -719,6 +717,7 @@ def generate(formats):
     print('#include "u_format.h"')
     print('#include "u_format_other.h"')
     print('#include "util/format_srgb.h"')
+    print('#include "format_utils.h"')
     print('#include "u_format_yuv.h"')
     print('#include "u_format_zs.h"')
     print('#include "u_format_pack.h"')



More information about the mesa-commit mailing list