mesa/uniform_query: add IROUNDD and use for doubles->ints (v2)
authorDave Airlie <airlied@redhat.com>
Thu, 15 Oct 2015 04:07:40 +0000 (05:07 +0100)
committerDave Airlie <airlied@redhat.com>
Mon, 11 Jan 2016 02:27:51 +0000 (02:27 +0000)
For the case where we convert a double to an int, we should
round the same as we do for floats.

This fixes GL41-CTS.gpu_shader_fp64.state_query

v2: add IROUNDD (Ilia)

Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/mesa/main/imports.h
src/mesa/main/uniform_query.cpp

index 042147fd8bba07bb441e384cd000c2a0cb9ddc57..ad7af5c1d8cba5103676b82a70de26ea05a7e28a 100644 (file)
@@ -151,6 +151,13 @@ static inline int IROUND(float f)
    return (int) ((f >= 0.0F) ? (f + 0.5F) : (f - 0.5F));
 }
 
+/**
+ * Convert double to int by rounding to nearest integer, away from zero.
+ */
+static inline int IROUNDD(double d)
+{
+   return (int) ((d >= 0.0) ? (d + 0.5) : (d - 0.5));
+}
 
 /**
  * Convert float to int64 by rounding to nearest integer.
index b2ac65fd68f069004f470303e35166679fa0ef26..766a465cb11dd46bbd742e0699067bcbf721f48a 100644 (file)
@@ -437,7 +437,7 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
                  dst[didx].i = src[sidx].i ? 1 : 0;
                  break;
               case GLSL_TYPE_DOUBLE:
-                 dst[didx].i = *(double *)&src[sidx].f;
+                 dst[didx].i = IROUNDD(*(double *)&src[sidx].f);
                  break;
               default:
                  assert(!"Should not get here.");