[Mesa-dev] [PATCH 3/3] translate: implement translation of 10_10_10_2 types

Marek Olšák maraeo at gmail.com
Mon Jan 2 05:07:58 PST 2012


This is for GL_ARB_vertex_type_2_10_10_10_rev.
I just took the code from u_format_table.c. It's based on pack_rgba_float.
I had no other choice. The u_format hooks are not exactly compatible
with translate. The cleanup of it is left for future work.
---
 .../auxiliary/translate/translate_generic.c        |  148 ++++++++++++++++++++
 1 files changed, 148 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c
index 9df4aff..0b6ebf5 100644
--- a/src/gallium/auxiliary/translate/translate_generic.c
+++ b/src/gallium/auxiliary/translate/translate_generic.c
@@ -257,6 +257,126 @@ emit_B8G8R8A8_UNORM( const void *attrib, void *ptr)
    out[3] = TO_8_UNORM(in[3]);
 }
 
+static void
+emit_B10G10R10A2_UNORM( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= ((uint32_t)(CLAMP(src[2], 0, 1) * 0x3ff)) & 0x3ff;
+   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;
+}
+
+static void
+emit_B10G10R10A2_USCALED( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= ((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff;
+   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;
+}
+
+static void
+emit_B10G10R10A2_SNORM( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= (uint32_t)(((uint32_t)(CLAMP(src[2], -1, 1) * 0x1ff)) & 0x3ff) ;
+   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;
+}
+
+static void
+emit_B10G10R10A2_SSCALED( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= (uint32_t)(((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) ;
+   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;
+}
+
+static void
+emit_R10G10B10A2_UNORM( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= ((uint32_t)(CLAMP(src[0], 0, 1) * 0x3ff)) & 0x3ff;
+   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;
+}
+
+static void
+emit_R10G10B10A2_USCALED( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= ((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff;
+   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;
+}
+
+static void
+emit_R10G10B10A2_SNORM( const void *attrib, void *ptr )
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= (uint32_t)(((uint32_t)(CLAMP(src[0], -1, 1) * 0x1ff)) & 0x3ff) ;
+   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;
+}
+
+static void
+emit_R10G10B10A2_SSCALED( const void *attrib, void *ptr)
+{
+   float *src = (float *)ptr;
+   uint32_t value = 0;
+   value |= (uint32_t)(((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) ;
+   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;
+}
+
 static void 
 emit_NULL( const void *attrib, void *ptr )
 {
@@ -461,6 +581,24 @@ static emit_func get_emit_func( enum pipe_format format )
    case PIPE_FORMAT_R8G8B8A8_SINT:
       return &emit_R8G8B8A8_SINT;
 
+   case PIPE_FORMAT_B10G10R10A2_UNORM:
+      return &emit_B10G10R10A2_UNORM;
+   case PIPE_FORMAT_B10G10R10A2_USCALED:
+      return &emit_B10G10R10A2_USCALED;
+   case PIPE_FORMAT_B10G10R10A2_SNORM:
+      return &emit_B10G10R10A2_SNORM;
+   case PIPE_FORMAT_B10G10R10A2_SSCALED:
+      return &emit_B10G10R10A2_SSCALED;
+
+   case PIPE_FORMAT_R10G10B10A2_UNORM:
+      return &emit_R10G10B10A2_UNORM;
+   case PIPE_FORMAT_R10G10B10A2_USCALED:
+      return &emit_R10G10B10A2_USCALED;
+   case PIPE_FORMAT_R10G10B10A2_SNORM:
+      return &emit_R10G10B10A2_SNORM;
+   case PIPE_FORMAT_R10G10B10A2_SSCALED:
+      return &emit_R10G10B10A2_SSCALED;
+
    default:
       assert(0); 
       return &emit_NULL;
@@ -836,6 +974,16 @@ boolean translate_generic_is_output_format_supported(enum pipe_format format)
    case PIPE_FORMAT_R8G8_SINT: return TRUE;
    case PIPE_FORMAT_R8_SINT: return TRUE;
 
+   case PIPE_FORMAT_B10G10R10A2_UNORM: return TRUE;
+   case PIPE_FORMAT_B10G10R10A2_USCALED: return TRUE;
+   case PIPE_FORMAT_B10G10R10A2_SNORM: return TRUE;
+   case PIPE_FORMAT_B10G10R10A2_SSCALED: return TRUE;
+
+   case PIPE_FORMAT_R10G10B10A2_UNORM: return TRUE;
+   case PIPE_FORMAT_R10G10B10A2_USCALED: return TRUE;
+   case PIPE_FORMAT_R10G10B10A2_SNORM: return TRUE;
+   case PIPE_FORMAT_R10G10B10A2_SSCALED: return TRUE;
+
    default: return FALSE;
    }
 }
-- 
1.7.4.1



More information about the mesa-dev mailing list