draw: Use translate function instead of switch cases
authorJakob Bornecrantz <wallbraker@gmail.com>
Wed, 24 Mar 2010 23:18:30 +0000 (00:18 +0100)
committerJakob Bornecrantz <wallbraker@gmail.com>
Fri, 26 Mar 2010 00:21:52 +0000 (01:21 +0100)
src/gallium/auxiliary/draw/draw_pipe_vbuf.c
src/gallium/auxiliary/draw/draw_pt_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
src/gallium/auxiliary/draw/draw_vertex.c
src/gallium/auxiliary/draw/draw_vertex.h

index 27099579618f2ccf367a86b88bd9249f7207549c..1c7db0005a95099a87044e164213e2a06d551ccf 100644 (file)
@@ -238,38 +238,15 @@ vbuf_start_prim( struct vbuf_stage *vbuf, uint prim )
       unsigned output_format;
       unsigned src_offset = (vbuf->vinfo->attrib[i].src_index * 4 * sizeof(float) );
 
-      switch (vbuf->vinfo->attrib[i].emit) {
-      case EMIT_4F:
-        output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
-        emit_sz = 4 * sizeof(float);
-        break;
-      case EMIT_3F:
-        output_format = PIPE_FORMAT_R32G32B32_FLOAT;
-        emit_sz = 3 * sizeof(float);
-        break;
-      case EMIT_2F:
-        output_format = PIPE_FORMAT_R32G32_FLOAT;
-        emit_sz = 2 * sizeof(float);
-        break;
-      case EMIT_1F:
-        output_format = PIPE_FORMAT_R32_FLOAT;
-        emit_sz = 1 * sizeof(float);
-        break;
-      case EMIT_1F_PSIZE:
-        output_format = PIPE_FORMAT_R32_FLOAT;
-        emit_sz = 1 * sizeof(float);
+      output_format = draw_translate_vinfo_format(vbuf->vinfo->attrib[i].emit);
+      emit_sz = draw_translate_vinfo_size(vbuf->vinfo->attrib[i].emit);
+
+      /* doesn't handle EMIT_OMIT */
+      assert(emit_sz != 0);
+
+      if (vbuf->vinfo->attrib[i].emit == EMIT_1F_PSIZE) {
         src_buffer = 1;
         src_offset = 0;
-        break;
-      case EMIT_4UB:
-        output_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-        emit_sz = 4 * sizeof(ubyte);
-         break;
-      default:
-        assert(0);
-        output_format = PIPE_FORMAT_NONE;
-        emit_sz = 0;
-        break;
       }
 
       hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL;
index ae357b512262ccf08584a6eb7fdda863766e2553..a7917f54b048257be04dcbe1aa6cda69d6bcff2d 100644 (file)
@@ -86,40 +86,15 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
       unsigned output_format;
       unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) );
 
+      output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
+      emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit);
 
-         
-      switch (vinfo->attrib[i].emit) {
-      case EMIT_4F:
-        output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
-        emit_sz = 4 * sizeof(float);
-        break;
-      case EMIT_3F:
-        output_format = PIPE_FORMAT_R32G32B32_FLOAT;
-        emit_sz = 3 * sizeof(float);
-        break;
-      case EMIT_2F:
-        output_format = PIPE_FORMAT_R32G32_FLOAT;
-        emit_sz = 2 * sizeof(float);
-        break;
-      case EMIT_1F:
-        output_format = PIPE_FORMAT_R32_FLOAT;
-        emit_sz = 1 * sizeof(float);
-        break;
-      case EMIT_1F_PSIZE:
-        output_format = PIPE_FORMAT_R32_FLOAT;
-        emit_sz = 1 * sizeof(float);
+      /* doesn't handle EMIT_OMIT */
+      assert(emit_sz != 0);
+
+      if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) {
         src_buffer = 1;
         src_offset = 0;
-        break;
-      case EMIT_4UB:
-        output_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-        emit_sz = 4 * sizeof(ubyte);
-         break;
-      default:
-        assert(0);
-        output_format = PIPE_FORMAT_NONE;
-        emit_sz = 0;
-        break;
       }
 
       hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL;
index 2a604470e9afadac15f21ab9141a68138822c9d2..1994ddf2bcc45c0e7d81fdcab75e3d9d02b04dea 100644 (file)
@@ -129,41 +129,16 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
       unsigned input_offset = src->src_offset;
       unsigned output_format;
 
-      switch (vinfo->attrib[i].emit) {
-      case EMIT_4UB:
-        output_format = PIPE_FORMAT_R8G8B8A8_UNORM;
-        emit_sz = 4 * sizeof(unsigned char);
-         break;
-      case EMIT_4F:
-        output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
-        emit_sz = 4 * sizeof(float);
-         break;
-      case EMIT_3F:
-        output_format = PIPE_FORMAT_R32G32B32_FLOAT;
-        emit_sz = 3 * sizeof(float);
-         break;
-      case EMIT_2F:
-        output_format = PIPE_FORMAT_R32G32_FLOAT;
-        emit_sz = 2 * sizeof(float);
-         break;
-      case EMIT_1F:
-        output_format = PIPE_FORMAT_R32_FLOAT;
-        emit_sz = 1 * sizeof(float);
-         break;
-      case EMIT_1F_PSIZE:
+      output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
+      emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit);
+
+      if (vinfo->attrib[i].emit == EMIT_OMIT)
+        continue;
+
+      if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) {
         input_format = PIPE_FORMAT_R32_FLOAT;
         input_buffer = draw->pt.nr_vertex_buffers;
         input_offset = 0;
-        output_format = PIPE_FORMAT_R32_FLOAT;
-        emit_sz = 1 * sizeof(float);
-         break;
-      case EMIT_OMIT:
-         continue;
-      default:
-         assert(0);
-        output_format = PIPE_FORMAT_NONE;
-        emit_sz = 0;
-        continue;
       }
 
       key.element[i].type = TRANSLATE_ELEMENT_NORMAL;
index 1aecb510777330e04a042433601e73c16c151e7f..389e2b105e56aa962c4730d995f48f49c94e232e 100644 (file)
@@ -130,31 +130,10 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
       unsigned dst_offset = 0;
 
       for (i = 0; i < vinfo->num_attribs; i++) {
-         unsigned emit_sz = 0;
-
-         switch (vinfo->attrib[i].emit) {
-         case EMIT_4F:
-            emit_sz = 4 * sizeof(float);
-            break;
-         case EMIT_3F:
-            emit_sz = 3 * sizeof(float);
-            break;
-         case EMIT_2F:
-            emit_sz = 2 * sizeof(float);
-            break;
-         case EMIT_1F:
-            emit_sz = 1 * sizeof(float);
-            break;
-         case EMIT_1F_PSIZE:
-            emit_sz = 1 * sizeof(float);
-            break;
-         case EMIT_4UB:
-            emit_sz = 4 * sizeof(ubyte);
-            break;
-         default:
-            assert(0);
-            break;
-         }
+         unsigned emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit);
+
+         /* doesn't handle EMIT_OMIT */
+         assert(emit_sz != 0);
 
          /* The elements in the key correspond to vertex shader output
           * numbers, not to positions in the hw vertex description --
index 3214213e44526e27063b9c62b1fc0b3b01cedd1f..18921ad71793a31bd6d3e1d5ea6f2a93e971d990 100644 (file)
@@ -48,30 +48,12 @@ draw_compute_vertex_size(struct vertex_info *vinfo)
    uint i;
 
    vinfo->size = 0;
-   for (i = 0; i < vinfo->num_attribs; i++) {
-      switch (vinfo->attrib[i].emit) {
-      case EMIT_OMIT:
-         break;
-      case EMIT_4UB:
-         /* fall-through */
-      case EMIT_1F_PSIZE:
-         /* fall-through */
-      case EMIT_1F:
-         vinfo->size += 1;
-         break;
-      case EMIT_2F:
-         vinfo->size += 2;
-         break;
-      case EMIT_3F:
-         vinfo->size += 3;
-         break;
-      case EMIT_4F:
-         vinfo->size += 4;
-         break;
-      default:
-         assert(0);
-      }
-   }
+   for (i = 0; i < vinfo->num_attribs; i++)
+      vinfo->size += draw_translate_vinfo_size(vinfo->attrib[i].emit);
+
+   assert(vinfo->size % 4 == 0);
+   /* in dwords */
+   vinfo->size /= 4;
 }
 
 
index 8c3c7befbc76795d3030637092e35df99245ec41..24c5a48b2ef4642bb9e6d12f38689c16ffdf2838 100644 (file)
@@ -141,9 +141,11 @@ void draw_dump_emitted_vertex(const struct vertex_info *vinfo,
                               const uint8_t *data);
 
 
-static INLINE unsigned draw_translate_vinfo_format(unsigned format )
+static INLINE unsigned draw_translate_vinfo_format(enum attrib_emit emit)
 {
-   switch (format) {
+   switch (emit) {
+   case EMIT_OMIT:
+      return PIPE_FORMAT_NONE;
    case EMIT_1F:
    case EMIT_1F_PSIZE:
       return PIPE_FORMAT_R32_FLOAT;
@@ -156,9 +158,31 @@ static INLINE unsigned draw_translate_vinfo_format(unsigned format )
    case EMIT_4UB:
       return PIPE_FORMAT_R8G8B8A8_UNORM;
    default:
+      assert(!"unexpected format");
       return PIPE_FORMAT_NONE;
    }
 }
 
+static INLINE unsigned draw_translate_vinfo_size(enum attrib_emit emit)
+{
+   switch (emit) {
+   case EMIT_OMIT:
+      return 0;
+   case EMIT_1F:
+   case EMIT_1F_PSIZE:
+      return 1 * sizeof(float);
+   case EMIT_2F:
+      return 2 * sizeof(float);
+   case EMIT_3F:
+      return 3 * sizeof(float);
+   case EMIT_4F:
+      return 4 * sizeof(float);
+   case EMIT_4UB:
+      return 4 * sizeof(unsigned char);
+   default:
+      assert(!"unexpected format");
+      return 0;
+   }
+}
 
 #endif /* DRAW_VERTEX_H */