softpipe: Include missing header in sp_flush.c.
[mesa.git] / src / gallium / drivers / r300 / r300_state_inlines.h
index 480d0f7c4ae0c110d9a0c85124bb1792c10a98b8..03ec127ff79c1b467a25bcbe0f7704806429ee13 100644 (file)
@@ -348,20 +348,17 @@ static INLINE uint32_t r300_translate_gb_pipes(int pipe_count)
     switch (pipe_count) {
         case 1:
             return R300_GB_TILE_PIPE_COUNT_RV300;
-            break;
         case 2:
             return R300_GB_TILE_PIPE_COUNT_R300;
-            break;
         case 3:
             return R300_GB_TILE_PIPE_COUNT_R420_3P;
-            break;
         case 4:
             return R300_GB_TILE_PIPE_COUNT_R420;
-            break;
     }
     return 0;
 }
 
+
 /* Translate pipe_formats into PSC vertex types. */
 static INLINE uint16_t
 r300_translate_vertex_data_type(enum pipe_format format) {
@@ -371,9 +368,7 @@ r300_translate_vertex_data_type(enum pipe_format format) {
     desc = util_format_description(format);
 
     if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
-        fprintf(stderr, "r300: Bad format %s in %s:%d\n", util_format_name(format),
-            __FUNCTION__, __LINE__);
-        assert(0);
+        return R300_INVALID_FORMAT;
     }
 
     switch (desc->channel[0].type) {
@@ -381,7 +376,7 @@ r300_translate_vertex_data_type(enum pipe_format format) {
         case UTIL_FORMAT_TYPE_FLOAT:
             switch (desc->channel[0].size) {
                 case 16:
-                    /* XXX Supported only on RV350 and later. */
+                    /* Supported only on RV350 and later. */
                     if (desc->nr_channels > 2) {
                         result = R300_DATA_TYPE_FLT16_4;
                     } else {
@@ -392,9 +387,7 @@ r300_translate_vertex_data_type(enum pipe_format format) {
                     result = R300_DATA_TYPE_FLOAT_1 + (desc->nr_channels - 1);
                     break;
                 default:
-                    fprintf(stderr, "r300: Bad format %s in %s:%d\n",
-                        util_format_name(format), __FUNCTION__, __LINE__);
-                    assert(0);
+                    return R300_INVALID_FORMAT;
             }
             break;
         /* Unsigned ints */
@@ -413,17 +406,11 @@ r300_translate_vertex_data_type(enum pipe_format format) {
                     }
                     break;
                 default:
-                    fprintf(stderr, "r300: Bad format %s in %s:%d\n",
-                        util_format_name(format), __FUNCTION__, __LINE__);
-                    fprintf(stderr, "r300: desc->channel[0].size == %d\n",
-                        desc->channel[0].size);
-                    assert(0);
+                    return R300_INVALID_FORMAT;
             }
             break;
         default:
-            fprintf(stderr, "r300: Bad format %s in %s:%d\n",
-                util_format_name(format), __FUNCTION__, __LINE__);
-            assert(0);
+            return R300_INVALID_FORMAT;
     }
 
     if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
@@ -439,20 +426,29 @@ r300_translate_vertex_data_type(enum pipe_format format) {
 static INLINE uint16_t
 r300_translate_vertex_data_swizzle(enum pipe_format format) {
     const struct util_format_description *desc = util_format_description(format);
+    unsigned i, swizzle = 0;
 
     assert(format);
 
     if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
         fprintf(stderr, "r300: Bad format %s in %s:%d\n",
-            util_format_name(format), __FUNCTION__, __LINE__);
+            util_format_short_name(format), __FUNCTION__, __LINE__);
         return 0;
     }
 
-    return ((desc->swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) |
-            (desc->swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) |
-            (desc->swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) |
-            (desc->swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) |
-            (0xf << R300_WRITE_ENA_SHIFT));
+    for (i = 0; i < desc->nr_channels; i++) {
+        swizzle |=
+            MIN2(desc->swizzle[i], R300_SWIZZLE_SELECT_FP_ONE) << (3*i);
+    }
+    /* Set (0,0,0,1) in unused components. */
+    for (; i < 3; i++) {
+        swizzle |= R300_SWIZZLE_SELECT_FP_ZERO << (3*i);
+    }
+    for (; i < 4; i++) {
+        swizzle |= R300_SWIZZLE_SELECT_FP_ONE << (3*i);
+    }
+
+    return swizzle | (0xf << R300_WRITE_ENA_SHIFT);
 }
 
 #endif /* R300_STATE_INLINES_H */