r300g: report vertex format support in is_format_supported
authorMarek Olšák <maraeo@gmail.com>
Fri, 28 May 2010 00:53:47 +0000 (02:53 +0200)
committerMarek Olšák <maraeo@gmail.com>
Fri, 28 May 2010 01:30:11 +0000 (03:30 +0200)
src/gallium/drivers/r300/r300_defines.h
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r300/r300_state_inlines.h

index 98ee3c1edecaa51dad8d9a0ba3f54617479a307a..4b1c37072688e0981360fb77fe1b8a6eeac2ea34 100644 (file)
@@ -30,6 +30,8 @@
 
 #define R300_RESOURCE_FLAG_TRANSFER     PIPE_RESOURCE_FLAG_DRV_PRIV
 
+#define R300_INVALID_FORMAT (~0)
+
 /* XXX: this is just a bandaid on larger problems in
  * r300_screen_buffer.h which doesn't seem to be fully ported to
  * gallium-resources.
index 4859db523a52e48f0f58af7ed1e03620853dad29..0be11ad017f3ec58741658751e9b11946540c8e0 100644 (file)
@@ -28,6 +28,7 @@
 #include "r300_context.h"
 #include "r300_texture.h"
 #include "r300_screen_buffer.h"
+#include "r300_state_inlines.h"
 #include "r300_winsys.h"
 
 /* Return the identifier behind whom the brave coders responsible for this
@@ -248,6 +249,7 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
     uint32_t retval = 0;
     boolean is_r500 = r300_screen(screen)->caps.is_r500;
     boolean is_r400 = r300_screen(screen)->caps.is_r400;
+    boolean is_rv350 = r300_screen(screen)->caps.is_rv350;
     boolean is_z24 = format == PIPE_FORMAT_X8Z24_UNORM ||
                      format == PIPE_FORMAT_S8_USCALED_Z24_UNORM;
     boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM ||
@@ -258,6 +260,10 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
                        format == PIPE_FORMAT_RGTC1_SNORM;
     boolean is_ati2n = format == PIPE_FORMAT_RGTC2_UNORM ||
                        format == PIPE_FORMAT_RGTC2_SNORM;
+    boolean is_half_float = format == PIPE_FORMAT_R16_FLOAT ||
+                            format == PIPE_FORMAT_R16G16_FLOAT ||
+                            format == PIPE_FORMAT_R16G16B16_FLOAT ||
+                            format == PIPE_FORMAT_R16G16B16A16_FLOAT;
 
     if (target >= PIPE_MAX_TEXTURE_TYPES) {
         fprintf(stderr, "r300: Implementation error: Received bogus texture "
@@ -301,6 +307,14 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
         retval |= PIPE_BIND_DEPTH_STENCIL;
     }
 
+    /* Check vertex buffer format support. */
+    if (usage & PIPE_BIND_VERTEX_BUFFER &&
+        /* Half float is supported on >= RV350. */
+        (is_rv350 || !is_half_float) &&
+        r300_translate_vertex_data_type(format) != R300_INVALID_FORMAT) {
+        retval |= PIPE_BIND_VERTEX_BUFFER;
+    }
+
     return retval == usage;
 }
 
index d7657218270b3cf92d526d77436802b5024012e7..d68f4039ca4647ef47b48f3b4b5565fae44389c5 100644 (file)
@@ -1250,8 +1250,15 @@ static void r300_vertex_psc(struct r300_vertex_element_state *velems)
     for (i = 0; i < velems->count; i++) {
         format = velems->velem[i].src_format;
 
-        type = r300_translate_vertex_data_type(format) |
-            (i << R300_DST_VEC_LOC_SHIFT);
+        type = r300_translate_vertex_data_type(format);
+        if (type == R300_INVALID_FORMAT) {
+            fprintf(stderr, "r300: Bad vertex format %s.\n",
+                    util_format_short_name(format));
+            assert(0);
+            abort();
+        }
+
+        type |= i << R300_DST_VEC_LOC_SHIFT;
         swizzle = r300_translate_vertex_data_swizzle(format);
 
         if (i & 1) {
index 20f24e8b04b44570ef174d49a6d8530fd5013f3f..cc75fad3bb928a39d8054500bd82a3a7ea0eefb1 100644 (file)
@@ -154,8 +154,15 @@ static void r300_swtcl_vertex_psc(struct r300_context *r300)
         format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
 
         /* Obtain the type of data in this attribute. */
-        type = r300_translate_vertex_data_type(format) |
-            vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT;
+        type = r300_translate_vertex_data_type(format);
+        if (type == R300_INVALID_FORMAT) {
+            fprintf(stderr, "r300: Bad vertex format %s.\n",
+                    util_format_short_name(format));
+            assert(0);
+            abort();
+        }
+
+        type |= vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT;
 
         /* Obtain the swizzle for this attribute. Note that the default
          * swizzle in the hardware is not XYZW! */
index 715601042fa41b07e1fc90b9ee9b6d70634e9c46..d1806dab12735c6f290e41ff09ef53e41cd635c7 100644 (file)
@@ -371,10 +371,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_short_name(format),
-            __FUNCTION__, __LINE__);
-        assert(0);
-        abort();
+        return R300_INVALID_FORMAT;
     }
 
     switch (desc->channel[0].type) {
@@ -382,7 +379,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 {
@@ -393,10 +390,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_short_name(format), __FUNCTION__, __LINE__);
-                    assert(0);
-                    abort();
+                    return R300_INVALID_FORMAT;
             }
             break;
         /* Unsigned ints */
@@ -415,19 +409,11 @@ r300_translate_vertex_data_type(enum pipe_format format) {
                     }
                     break;
                 default:
-                    fprintf(stderr, "r300: Bad format %s in %s:%d\n",
-                        util_format_short_name(format), __FUNCTION__, __LINE__);
-                    fprintf(stderr, "r300: desc->channel[0].size == %d\n",
-                        desc->channel[0].size);
-                    assert(0);
-                    abort();
+                    return R300_INVALID_FORMAT;
             }
             break;
         default:
-            fprintf(stderr, "r300: Bad format %s in %s:%d\n",
-                util_format_short_name(format), __FUNCTION__, __LINE__);
-            assert(0);
-            abort();
+            return R300_INVALID_FORMAT;
     }
 
     if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {