[Mesa-dev] [PATCH] gallium/translate: implement converting into half floats in the generic path

Marek Olšák maraeo at gmail.com
Sun Jan 1 04:04:23 PST 2012


---
 .../auxiliary/translate/translate_generic.c        |   21 ++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c
index e4e1c86..516a1ef 100644
--- a/src/gallium/auxiliary/translate/translate_generic.c
+++ b/src/gallium/auxiliary/translate/translate_generic.c
@@ -32,6 +32,7 @@
 
 #include "util/u_memory.h"
 #include "util/u_format.h"
+#include "util/u_half.h"
 #include "util/u_math.h"
 #include "pipe/p_state.h"
 #include "translate.h"
@@ -105,6 +106,7 @@ emit_##NAME(const float *attrib, void *ptr)		\
 
 #define TO_64_FLOAT(x)   ((double) x)
 #define TO_32_FLOAT(x)   (x)
+#define TO_16_FLOAT(x)   util_float_to_half(x)
 
 #define TO_8_USCALED(x)  ((unsigned char) x)
 #define TO_16_USCALED(x) ((unsigned short) x)
@@ -135,6 +137,11 @@ ATTRIB( R32G32B32_FLOAT,      3, float, TO_32_FLOAT )
 ATTRIB( R32G32_FLOAT,         2, float, TO_32_FLOAT )
 ATTRIB( R32_FLOAT,            1, float, TO_32_FLOAT )
 
+ATTRIB( R16G16B16A16_FLOAT,   4, ushort, TO_16_FLOAT )
+ATTRIB( R16G16B16_FLOAT,      3, ushort, TO_16_FLOAT )
+ATTRIB( R16G16_FLOAT,         2, ushort, TO_16_FLOAT )
+ATTRIB( R16_FLOAT,            1, ushort, TO_16_FLOAT )
+
 ATTRIB( R32G32B32A32_USCALED, 4, unsigned, TO_32_USCALED )
 ATTRIB( R32G32B32_USCALED,    3, unsigned, TO_32_USCALED )
 ATTRIB( R32G32_USCALED,       2, unsigned, TO_32_USCALED )
@@ -242,6 +249,15 @@ static emit_func get_emit_func( enum pipe_format format )
    case PIPE_FORMAT_R32G32B32A32_FLOAT:
       return &emit_R32G32B32A32_FLOAT;
 
+   case PIPE_FORMAT_R16_FLOAT:
+      return &emit_R16_FLOAT;
+   case PIPE_FORMAT_R16G16_FLOAT:
+      return &emit_R16G16_FLOAT;
+   case PIPE_FORMAT_R16G16B16_FLOAT:
+      return &emit_R16G16B16_FLOAT;
+   case PIPE_FORMAT_R16G16B16A16_FLOAT:
+      return &emit_R16G16B16A16_FLOAT;
+
    case PIPE_FORMAT_R32_UNORM:
       return &emit_R32_UNORM;
    case PIPE_FORMAT_R32G32_UNORM:
@@ -595,6 +611,11 @@ boolean translate_generic_is_output_format_supported(enum pipe_format format)
    case PIPE_FORMAT_R32G32_FLOAT: return TRUE;
    case PIPE_FORMAT_R32_FLOAT: return TRUE;
 
+   case PIPE_FORMAT_R16G16B16A16_FLOAT: return TRUE;
+   case PIPE_FORMAT_R16G16B16_FLOAT: return TRUE;
+   case PIPE_FORMAT_R16G16_FLOAT: return TRUE;
+   case PIPE_FORMAT_R16_FLOAT: return TRUE;
+
    case PIPE_FORMAT_R32G32B32A32_USCALED: return TRUE;
    case PIPE_FORMAT_R32G32B32_USCALED: return TRUE;
    case PIPE_FORMAT_R32G32_USCALED: return TRUE;
-- 
1.7.4.1



More information about the mesa-dev mailing list