gallium: add and use generic function for querying patented format support (v2)
authorMarek Olšák <maraeo@gmail.com>
Mon, 11 Apr 2011 04:23:00 +0000 (06:23 +0200)
committerMarek Olšák <maraeo@gmail.com>
Fri, 15 Apr 2011 03:08:00 +0000 (05:08 +0200)
v2: Unsigned floats are allowed regardless of the configure switch.

src/gallium/auxiliary/util/u_format.c
src/gallium/auxiliary/util/u_format.h
src/gallium/drivers/i915/i915_screen.c
src/gallium/drivers/i965/brw_screen.c
src/gallium/drivers/nv50/nv50_screen.c
src/gallium/drivers/nvc0/nvc0_screen.c
src/gallium/drivers/nvfx/nvfx_screen.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r600/r600_pipe.c

index 4896faa12bf95cce66dd4b21229c5733e9509995..9cbdd0a5b99cc99994b465e63b613b615788f535 100644 (file)
 #include "u_memory.h"
 #include "u_rect.h"
 #include "u_format.h"
+#include "u_format_s3tc.h"
+
+#include "pipe/p_defines.h"
+
+
+boolean
+util_format_is_float(enum pipe_format format)
+{
+   const struct util_format_description *desc = util_format_description(format);
+   unsigned i;
+
+   assert(desc);
+   if (!desc) {
+      return FALSE;
+   }
+
+   /* Find the first non-void channel. */
+   for (i = 0; i < 4; i++) {
+      if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
+         break;
+      }
+   }
+
+   if (i == 4) {
+      return FALSE;
+   }
+
+   return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE;
+}
+
+
+boolean
+util_format_is_supported(enum pipe_format format, unsigned bind)
+{
+   if (util_format_is_s3tc(format) && !util_format_s3tc_enabled) {
+      return FALSE;
+   }
+
+#ifndef TEXTURE_FLOAT_ENABLED
+   if ((bind & PIPE_BIND_RENDER_TARGET) &&
+       format != PIPE_FORMAT_R9G9B9E5_FLOAT &&
+       format != PIPE_FORMAT_R11G11B10_FLOAT &&
+       util_format_is_float(format)) {
+      return FALSE;
+   }
+#endif
+
+   return TRUE;
+}
 
 
 void
index 7659a802a41605fdc1fed38cb8717db03750be8c..bb3ed72e93256500ccac6fa98a3e62f7e6fb9e16 100644 (file)
@@ -473,6 +473,10 @@ util_format_colormask(const struct util_format_description *desc)
 }
 
 
+boolean
+util_format_is_float(enum pipe_format format);
+
+
 /**
  * Whether the src format can be blitted to destation format with a simple
  * memcpy.
@@ -481,6 +485,12 @@ boolean
 util_is_format_compatible(const struct util_format_description *src_desc,
                           const struct util_format_description *dst_desc);
 
+/**
+ * Whether the format is supported by Gallium for the given bindings.
+ * This covers S3TC textures and floating-point render targets.
+ */
+boolean
+util_format_is_supported(enum pipe_format format, unsigned bind);
 
 /**
  * Whether this format is a rgab8 variant.
index e62b609eb5a66588d6fc6a36ca5fe471eb9db491..6f6a342791a893c9039c2e8a31706dcc9ed9fd52 100644 (file)
@@ -285,6 +285,9 @@ i915_is_format_supported(struct pipe_screen *screen,
    const enum pipe_format *list;
    uint i;
 
+   if (!util_format_is_supported(format, tex_usage))
+      return FALSE;
+
    if (sample_count > 1)
       return FALSE;
 
index 25204fd088d0be557221b87686a3ec9436b96809..5353ae23250462837694311d5e35eb7401d0b0a7 100644 (file)
@@ -333,6 +333,9 @@ brw_is_format_supported(struct pipe_screen *screen,
    const enum pipe_format *list;
    uint i;
 
+   if (!util_format_is_supported(format, tex_usage))
+      return FALSE;
+
    if (sample_count > 1)
       return FALSE;
 
index 46622b4be7635e46078651cec9fb4a68d39a8785..e0eea3ed750d073dd1995c980bc835cbd999a32a 100644 (file)
@@ -45,17 +45,8 @@ nv50_screen_is_format_supported(struct pipe_screen *pscreen,
    if (sample_count > 1)
       return FALSE;
 
-   if (!util_format_s3tc_enabled) {
-      switch (format) {
-      case PIPE_FORMAT_DXT1_RGB:
-      case PIPE_FORMAT_DXT1_RGBA:
-      case PIPE_FORMAT_DXT3_RGBA:
-      case PIPE_FORMAT_DXT5_RGBA:
-         return FALSE;
-      default:
-         break;
-      }
-   }
+   if (!util_format_is_supported(format, bindings))
+      return FALSE;
 
    switch (format) {
    case PIPE_FORMAT_Z16_UNORM:
index 31133f0cc6c1dcc80fbc48e531e102f0756014bb..c4cdface5021a61fc38a79d4794dd15f1db01bc9 100644 (file)
@@ -39,17 +39,8 @@ nvc0_screen_is_format_supported(struct pipe_screen *pscreen,
    if (sample_count > 1)
       return FALSE;
 
-   if (!util_format_s3tc_enabled) {
-      switch (format) {
-      case PIPE_FORMAT_DXT1_RGB:
-      case PIPE_FORMAT_DXT1_RGBA:
-      case PIPE_FORMAT_DXT3_RGBA:
-      case PIPE_FORMAT_DXT5_RGBA:
-         return FALSE;
-      default:
-         break;
-      }
-   }
+   if (!util_format_is_supported(format, bindings))
+      return FALSE;
 
    /* transfers & shared are always supported */
    bindings &= ~(PIPE_BIND_TRANSFER_READ |
index 0c8d33fb0aa2ed5f1f3bdf108a57a87536091e31..abbed9651eea18a1deb6adb987fbb191d990a5a0 100644 (file)
@@ -208,6 +208,9 @@ nvfx_screen_is_format_supported(struct pipe_screen *pscreen,
 {
        struct nvfx_screen *screen = nvfx_screen(pscreen);
 
+        if (!util_format_is_supported(format, bind))
+                return FALSE;
+
         if (sample_count > 1)
                return FALSE;
 
index e1f5a9fd2219b7dd556b897a7fd39549f9981abc..acb7d9f02d2c72f5f261530d503110ce5c25328f 100644 (file)
@@ -334,6 +334,9 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
                             format == PIPE_FORMAT_R16G16B16_FLOAT ||
                             format == PIPE_FORMAT_R16G16B16A16_FLOAT;
 
+    if (!util_format_is_supported(format, usage))
+       return FALSE;
+
     /* Check multisampling support. */
     switch (sample_count) {
         case 0:
index b4d45f5eee08db51b66a8b463d1b5c81ac6b28b8..afc1451183d63e5e494de0533e710af857bda8fb 100644 (file)
@@ -741,25 +741,6 @@ static uint32_t r300_get_border_color(enum pipe_format format,
     return uc.ui;
 }
 
-static boolean util_format_is_float(enum pipe_format format)
-{
-    const struct util_format_description *desc = util_format_description(format);
-    unsigned i;
-
-    if (!format)
-       return FALSE;
-
-    /* Find the first non-void channel. */
-    for (i = 0; i < 4; i++)
-        if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
-            break;
-
-    if (i == 4)
-        return FALSE;
-
-    return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE;
-}
-
 static void r300_merge_textures_and_samplers(struct r300_context* r300)
 {
     struct r300_textures_state *state =
index 5f95540a4795f3f7e1fa89274ddadae3611f69e9..066768f9c380bc21835eb2715982ca377f10bf18 100644 (file)
@@ -523,6 +523,9 @@ static boolean r600_is_format_supported(struct pipe_screen* screen,
                return FALSE;
        }
 
+        if (!util_format_is_supported(format, usage))
+                return FALSE;
+
        /* Multisample */
        if (sample_count > 1)
                return FALSE;