llvmpipe: fix race between draw and setting fragment shader.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_test_main.c
index 7a0d06ae2c8cd1a45fbf748e17b9e915d34d7b9b..5ec0dd347bd3edb1938718ea674ad5866dbf449e 100644 (file)
 
 
 #include "util/u_cpu_detect.h"
+#include "util/u_math.h"
 
 #include "gallivm/lp_bld_const.h"
 #include "gallivm/lp_bld_init.h"
+#include "gallivm/lp_bld_debug.h"
 #include "lp_test.h"
 
 
-#ifdef PIPE_CC_MSVC
-static INLINE double
-round(double x)
-{
-   if (x >= 0.0)
-      return floor(x + 0.5);
-   else
-      return ceil(x - 0.5);
-}
-#endif
-
-
 void
 dump_type(FILE *fp,
           struct lp_type type)
@@ -157,6 +147,7 @@ write_elem(struct lp_type type, void *dst, unsigned index, double value)
       if(type.sign) {
          long long lvalue = (long long)value;
          lvalue = MIN2(lvalue, ((long long)1 << (type.width - 1)) - 1);
+         lvalue = MAX2(lvalue, -((long long)1 << (type.width - 1)));
          switch(type.width) {
          case 8:
             *((int8_t *)dst + index) = (int8_t)lvalue;
@@ -210,16 +201,24 @@ random_elem(struct lp_type type, void *dst, unsigned index)
       }
       else {
          unsigned long long mask;
-        if (type.fixed)
+         if (type.fixed)
             mask = ((unsigned long long)1 << (type.width / 2)) - 1;
          else if (type.sign)
             mask = ((unsigned long long)1 << (type.width - 1)) - 1;
          else
             mask = ((unsigned long long)1 << type.width) - 1;
          value += (double)(mask & rand());
+         if (!type.fixed && !type.sign && type.width == 32) {
+            /*
+             * rand only returns half the possible range
+             * XXX 64bit values...
+             */
+            if(rand() & 1)
+               value += (double)0x80000000;
+         }
       }
    }
-   if(!type.sign)
+   if(type.sign)
       if(rand() & 1)
          value = -value;
    write_elem(type, dst, index, value);
@@ -380,6 +379,14 @@ int main(int argc, char **argv)
    unsigned i;
    boolean success;
    boolean single = FALSE;
+   unsigned fpstate;
+
+   util_cpu_detect();
+   fpstate = util_fpstate_get();
+   util_fpstate_set_denorms_to_zero(fpstate);
+
+   if (!lp_build_init())
+      return 1;
 
    for(i = 1; i < argc; ++i) {
       if(strcmp(argv[i], "-v") == 0)
@@ -392,11 +399,14 @@ int main(int argc, char **argv)
          n = atoi(argv[i]);
    }
 
-   lp_build_init();
-
-   util_cpu_detect();
+#ifdef DEBUG
+   if (verbose >= 2) {
+      gallivm_debug |= GALLIVM_DEBUG_IR;
+      gallivm_debug |= GALLIVM_DEBUG_ASM;
+   }
+#endif
 
-   if(fp) {
+   if (fp) {
       /* Warm up the caches */
       test_some(0, NULL, 100);
 
@@ -410,8 +420,10 @@ int main(int argc, char **argv)
    else
       success = test_all(verbose, fp);
 
-   if(fp)
+   if (fp)
       fclose(fp);
 
+   LLVMShutdown();
+
    return success ? 0 : 1;
 }