r300g: advertise S3TC only when it's available in Gallium
[mesa.git] / src / gallium / drivers / r300 / r300_texture.c
index 3e3cf33bde2524fa547a0b21849f627147cfc3f3..a6f65fce2161519d0ee84d717ae10e7f803d3ea1 100644 (file)
@@ -24,6 +24,7 @@
 #include "pipe/p_screen.h"
 
 #include "util/u_format.h"
+#include "util/u_format_s3tc.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
@@ -46,18 +47,6 @@ static const unsigned microblock_table[5][3][2] = {
     {{ 2, 1}, {0, 0}, {0, 0}}  /* 128 bits per pixel */
 };
 
-/* Return true for non-compressed and non-YUV formats. */
-static boolean r300_format_is_plain(enum pipe_format format)
-{
-    const struct util_format_description *desc = util_format_description(format);
-
-    if (!format) {
-        return FALSE;
-    }
-
-    return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN;
-}
-
 /* Translate a pipe_format into a useful texture format for sampling.
  *
  * Some special formats are translated directly using R300_EASY_TX_FORMAT,
@@ -182,6 +171,10 @@ uint32_t r300_translate_texformat(enum pipe_format format,
 
     /* S3TC formats. */
     if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
+        if (!util_format_s3tc_enabled) {
+            return ~0; /* Unsupported. */
+        }
+
         switch (format) {
             case PIPE_FORMAT_DXT1_RGB:
             case PIPE_FORMAT_DXT1_RGBA:
@@ -620,7 +613,7 @@ void r300_texture_reinterpret_format(struct pipe_screen *screen,
     struct r300_screen *r300screen = r300_screen(screen);
 
     SCREEN_DBG(r300screen, DBG_TEX, "r300: texture_reinterpret_format: %s -> %s\n",
-               util_format_name(tex->format), util_format_name(new_format));
+               util_format_short_name(tex->format), util_format_short_name(new_format));
 
     tex->format = new_format;
 
@@ -711,7 +704,7 @@ unsigned r300_texture_get_stride(struct r300_screen* screen,
 
     width = u_minify(tex->b.b.width0, level);
 
-    if (r300_format_is_plain(tex->b.b.format)) {
+    if (util_format_is_plain(tex->b.b.format)) {
         tile_width = r300_texture_get_tile_size(tex, TILE_WIDTH,
                                                 tex->mip_macrotile[level]);
         width = align(width, tile_width);
@@ -729,7 +722,7 @@ static unsigned r300_texture_get_nblocksy(struct r300_texture* tex,
 
     height = u_minify(tex->b.b.height0, level);
 
-    if (r300_format_is_plain(tex->b.b.format)) {
+    if (util_format_is_plain(tex->b.b.format)) {
         tile_height = r300_texture_get_tile_size(tex, TILE_HEIGHT,
                                                  tex->mip_macrotile[level]);
         height = align(height, tile_height);
@@ -772,7 +765,7 @@ static void r300_setup_miptree(struct r300_screen* screen,
     boolean rv350_mode = screen->caps.is_rv350;
 
     SCREEN_DBG(screen, DBG_TEXALLOC, "r300: Making miptree for texture, format %s\n",
-               util_format_name(base->format));
+               util_format_short_name(base->format));
 
     for (i = 0; i <= base->last_level; i++) {
         /* Let's see if this miplevel can be macrotiled. */
@@ -822,7 +815,7 @@ static void r300_setup_tiling(struct pipe_screen *screen,
     boolean is_zb = util_format_is_depth_or_stencil(format);
     boolean dbg_no_tiling = SCREEN_DBG_ON(r300_screen(screen), DBG_NO_TILING);
 
-    if (!r300_format_is_plain(format)) {
+    if (!util_format_is_plain(format)) {
         return;
     }
 
@@ -924,6 +917,17 @@ struct pipe_resource* r300_texture_create(struct pipe_screen* screen,
         return NULL;
     }
 
+    /* Refuse to create a texture with size 0. */
+    if (!base->width0 ||
+        (!base->height0 && (base->target == PIPE_TEXTURE_2D ||
+                            base->target == PIPE_TEXTURE_CUBE)) ||
+        (!base->depth0 && base->target == PIPE_TEXTURE_3D)) {
+        fprintf(stderr, "r300: texture_create: "
+                "Got invalid texture dimensions: %ix%ix%i\n",
+                base->width0, base->height0, base->depth0);
+        return NULL;
+    }
+
     tex->b.b = *base;
     tex->b.vtbl = &r300_texture_vtbl;
     pipe_reference_init(&tex->b.b.reference, 1);
@@ -946,7 +950,7 @@ struct pipe_resource* r300_texture_create(struct pipe_screen* screen,
                tex->microtile ? "YES" : " NO",
                tex->hwpitch[0],
                base->width0, base->height0, base->depth0, base->last_level,
-               util_format_name(base->format));
+               util_format_short_name(base->format));
 
     tex->buffer = rws->buffer_create(rws, 2048,
                                     PIPE_BIND_SAMPLER_VIEW, /* XXX */
@@ -1052,7 +1056,7 @@ r300_texture_from_handle(struct pipe_screen* screen,
                tex->microtile ? "YES" : " NO",
                stride / util_format_get_blocksize(base->format),
                base->width0, base->height0,
-               util_format_name(base->format));
+               util_format_short_name(base->format));
 
     /* Enforce microtiled zbuffer. */
     override_zb_flags = util_format_is_depth_or_stencil(base->format) &&