intel/blorp: Increase the presision of coordinate transform calculations
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 3 Sep 2016 16:49:24 +0000 (09:49 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 13 Sep 2016 02:42:57 +0000 (19:42 -0700)
The result of this calculation goes into an fma() in the shader and we
would like it to be as precise as possible.  The division in particular
was a source of imprecision whenever dst1 - dst0 was not a power of two.
This prevents regressions in some of the new Vulkan CTS tests for blitting
using a filtering of NEAREST.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/intel/blorp/blorp_blit.c

index 0898ed45faa4e0d86cb8e9ad51980d073108d803..af463890579132c57d37cb0d24b5b72737371002 100644 (file)
@@ -1263,7 +1263,7 @@ brw_blorp_setup_coord_transform(struct brw_blorp_coord_transform *xform,
                                 GLfloat dst0, GLfloat dst1,
                                 bool mirror)
 {
-   float scale = (src1 - src0) / (dst1 - dst0);
+   double scale = (double)(src1 - src0) / (double)(dst1 - dst0);
    if (!mirror) {
       /* When not mirroring a coordinate (say, X), we need:
        *   src_x - src_x0 = (dst_x - dst_x0 + 0.5) * scale
@@ -1276,7 +1276,7 @@ brw_blorp_setup_coord_transform(struct brw_blorp_coord_transform *xform,
        * so 0.5 provides the necessary correction.
        */
       xform->multiplier = scale;
-      xform->offset = src0 + (-dst0 + 0.5f) * scale;
+      xform->offset = src0 + (-(double)dst0 + 0.5) * scale;
    } else {
       /* When mirroring X we need:
        *   src_x - src_x0 = dst_x1 - dst_x - 0.5
@@ -1284,7 +1284,7 @@ brw_blorp_setup_coord_transform(struct brw_blorp_coord_transform *xform,
        *   src_x = src_x0 + (dst_x1 -dst_x - 0.5) * scale
        */
       xform->multiplier = -scale;
-      xform->offset = src0 + (dst1 - 0.5f) * scale;
+      xform->offset = src0 + ((double)dst1 - 0.5) * scale;
    }
 }