r300g: format handling cleanup
authorMarek Olšák <maraeo@gmail.com>
Wed, 31 Mar 2010 23:13:26 +0000 (01:13 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 31 Mar 2010 23:13:26 +0000 (01:13 +0200)
src/gallium/drivers/r300/r300_state_inlines.h
src/gallium/drivers/r300/r300_texture.c

index 02d09c008c8f27222017d786181cb6d937262dff..8a690039b6b437af6d373f0ec739a478db3914ae 100644 (file)
@@ -367,7 +367,6 @@ static INLINE uint16_t
 r300_translate_vertex_data_type(enum pipe_format format) {
     uint32_t result = 0;
     const struct util_format_description *desc;
-    unsigned components = util_format_get_nr_components(format);
 
     desc = util_format_description(format);
 
@@ -380,17 +379,17 @@ r300_translate_vertex_data_type(enum pipe_format format) {
     switch (desc->channel[0].type) {
         /* Half-floats, floats, doubles */
         case UTIL_FORMAT_TYPE_FLOAT:
-            switch (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)) {
+            switch (desc->channel[0].size) {
                 case 16:
                     /* XXX Supported only on RV350 and later. */
-                    if (components > 2) {
+                    if (desc->nr_channels > 2) {
                         result = R300_DATA_TYPE_FLT16_4;
                     } else {
                         result = R300_DATA_TYPE_FLT16_2;
                     }
                     break;
                 case 32:
-                    result = R300_DATA_TYPE_FLOAT_1 + (components - 1);
+                    result = R300_DATA_TYPE_FLOAT_1 + (desc->nr_channels - 1);
                     break;
                 default:
                     fprintf(stderr, "r300: Bad format %s in %s:%d\n",
@@ -402,12 +401,12 @@ r300_translate_vertex_data_type(enum pipe_format format) {
         case UTIL_FORMAT_TYPE_UNSIGNED:
         /* Signed ints */
         case UTIL_FORMAT_TYPE_SIGNED:
-            switch (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)) {
+            switch (desc->channel[0].size) {
                 case 8:
                     result = R300_DATA_TYPE_BYTE;
                     break;
                 case 16:
-                    if (components > 2) {
+                    if (desc->nr_channels > 2) {
                         result = R300_DATA_TYPE_SHORT_4;
                     } else {
                         result = R300_DATA_TYPE_SHORT_2;
@@ -416,8 +415,8 @@ r300_translate_vertex_data_type(enum pipe_format format) {
                 default:
                     fprintf(stderr, "r300: Bad format %s in %s:%d\n",
                         util_format_name(format), __FUNCTION__, __LINE__);
-                    fprintf(stderr, "r300: util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) == %d\n",
-                        util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0));
+                    fprintf(stderr, "r300: desc->channel[0].size == %d\n",
+                        desc->channel[0].size);
                     assert(0);
             }
             break;
index 28cc822b13df82ea6f17d9ab007a6bdb94633d22..92c29b53fd8205b5794005753577522425340a10 100644 (file)
@@ -73,7 +73,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
 {
     uint32_t result = 0;
     const struct util_format_description *desc;
-    unsigned components = 0, i;
+    unsigned i;
     boolean uniform = TRUE;
     const uint32_t swizzle_shift[4] = {
         R300_TX_FORMAT_R_SHIFT,
@@ -177,28 +177,21 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
         }
     }
 
-    /* Get the number of components. */
-    for (i = 0; i < 4; i++) {
-        if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
-            ++components;
-        }
-    }
-
     /* Add sign. */
-    for (i = 0; i < components; i++) {
+    for (i = 0; i < desc->nr_channels; i++) {
         if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) {
             result |= sign_bit[i];
         }
     }
 
     /* See whether the components are of the same size. */
-    for (i = 1; i < components; i++) {
+    for (i = 1; i < desc->nr_channels; i++) {
         uniform = uniform && desc->channel[0].size == desc->channel[i].size;
     }
 
     /* Non-uniform formats. */
     if (!uniform) {
-        switch (components) {
+        switch (desc->nr_channels) {
             case 3:
                 if (desc->channel[0].size == 5 &&
                     desc->channel[1].size == 6 &&
@@ -240,7 +233,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
 
             switch (desc->channel[0].size) {
                 case 4:
-                    switch (components) {
+                    switch (desc->nr_channels) {
                         case 2:
                             return R300_TX_FORMAT_Y4X4 | result;
                         case 4:
@@ -249,7 +242,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
                     return ~0;
 
                 case 8:
-                    switch (components) {
+                    switch (desc->nr_channels) {
                         case 1:
                             return R300_TX_FORMAT_X8 | result;
                         case 2:
@@ -260,7 +253,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
                     return ~0;
 
                 case 16:
-                    switch (components) {
+                    switch (desc->nr_channels) {
                         case 1:
                             return R300_TX_FORMAT_X16 | result;
                         case 2:
@@ -276,7 +269,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
         case UTIL_FORMAT_TYPE_FLOAT:
             switch (desc->channel[0].size) {
                 case 16:
-                    switch (components) {
+                    switch (desc->nr_channels) {
                         case 1:
                             return R300_TX_FORMAT_16F | result;
                         case 2:
@@ -287,7 +280,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format)
                     return ~0;
 
                 case 32:
-                    switch (components) {
+                    switch (desc->nr_channels) {
                         case 1:
                             return R300_TX_FORMAT_32F | result;
                         case 2: