radeonsi: move VGT_GS_MODE to the VS state
[mesa.git] / src / gallium / auxiliary / translate / translate_generic.c
index 96e35b0eb41f1431217b4102423c81c852725c24..45eb63231e3446ca4f49e8a48d9b3a7b31fba76c 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -27,7 +27,7 @@
 
  /*
   * Authors:
-  *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Keith Whitwell <keithw@vmware.com>
   */
 
 #include "util/u_memory.h"
@@ -73,7 +73,7 @@ struct translate_generic {
        */
       int copy_size;
 
-   } attrib[PIPE_MAX_ATTRIBS];
+   } attrib[TRANSLATE_MAX_ATTRIBS];
 
    unsigned nr_attrib;
 };
@@ -266,10 +266,7 @@ emit_B10G10R10A2_UNORM( const void *attrib, void *ptr )
    value |= (((uint32_t)(CLAMP(src[1], 0, 1) * 0x3ff)) & 0x3ff) << 10;
    value |= (((uint32_t)(CLAMP(src[0], 0, 1) * 0x3ff)) & 0x3ff) << 20;
    value |= ((uint32_t)(CLAMP(src[3], 0, 1) * 0x3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -281,10 +278,7 @@ emit_B10G10R10A2_USCALED( const void *attrib, void *ptr )
    value |= (((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
    value |= (((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff) << 20;
    value |= ((uint32_t)CLAMP(src[3], 0, 3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -296,10 +290,7 @@ emit_B10G10R10A2_SNORM( const void *attrib, void *ptr )
    value |= (uint32_t)((((uint32_t)(CLAMP(src[1], -1, 1) * 0x1ff)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)(CLAMP(src[0], -1, 1) * 0x1ff)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)(CLAMP(src[3], -1, 1) * 0x1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -311,10 +302,7 @@ emit_B10G10R10A2_SSCALED( const void *attrib, void *ptr )
    value |= (uint32_t)((((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -326,10 +314,7 @@ emit_R10G10B10A2_UNORM( const void *attrib, void *ptr )
    value |= (((uint32_t)(CLAMP(src[1], 0, 1) * 0x3ff)) & 0x3ff) << 10;
    value |= (((uint32_t)(CLAMP(src[2], 0, 1) * 0x3ff)) & 0x3ff) << 20;
    value |= ((uint32_t)(CLAMP(src[3], 0, 1) * 0x3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -341,10 +326,7 @@ emit_R10G10B10A2_USCALED( const void *attrib, void *ptr )
    value |= (((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
    value |= (((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff) << 20;
    value |= ((uint32_t)CLAMP(src[3], 0, 3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -356,10 +338,7 @@ emit_R10G10B10A2_SNORM( const void *attrib, void *ptr )
    value |= (uint32_t)((((uint32_t)(CLAMP(src[1], -1, 1) * 0x1ff)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)(CLAMP(src[2], -1, 1) * 0x1ff)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)(CLAMP(src[3], -1, 1) * 0x1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -371,10 +350,7 @@ emit_R10G10B10A2_SSCALED( const void *attrib, void *ptr)
    value |= (uint32_t)((((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void 
@@ -625,8 +601,7 @@ static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic *
 
          if (tg->attrib[attr].instance_divisor) {
             index = start_instance;
-            index += (instance_id - start_instance) /
-               tg->attrib[attr].instance_divisor;
+            index += (instance_id  / tg->attrib[attr].instance_divisor);
             /* XXX we need to clamp the index here too, but to a
              * per-array max value, not the draw->pt.max_index value
              * that's being given to us via translate->set_buffer().
@@ -639,7 +614,7 @@ static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic *
          }
 
          src = tg->attrib[attr].input_ptr +
-               tg->attrib[attr].input_stride * index;
+               (ptrdiff_t)tg->attrib[attr].input_stride * index;
 
          copy_size = tg->attrib[attr].copy_size;
          if(likely(copy_size >= 0))
@@ -800,6 +775,8 @@ struct translate *translate_generic_create( const struct translate_key *key )
    if (tg == NULL)
       return NULL;
 
+   assert(key->nr_elements <= TRANSLATE_MAX_ATTRIBS);
+
    tg->translate.key = *key;
    tg->translate.release = generic_release;
    tg->translate.set_buffer = generic_set_buffer;