st/mesa: don't choose DXT formats if we can't do DXT compression
authorBrian Paul <brianp@vmware.com>
Fri, 1 Feb 2013 01:52:57 +0000 (18:52 -0700)
committerBrian Paul <brianp@vmware.com>
Mon, 4 Feb 2013 14:58:21 +0000 (07:58 -0700)
If we call gl[Copy]TexImage2D() with a generic compression format
(e.g. intFormat=GL_COMPRESSED_RGBA) we can't choose a DXT format if
we don't have the external DXT compression library.

We weren't actually enforcing this before since the
pipe_screen::is_format_supported(DXT) query has no dependency on
the DXT compression library.

Now if we're given a generic compressed format and we can't do DXT
compression we'll fall back to a non-compressed format.

v2: use util_format_is_s3tc() function and add more comments about
the allow_dxt parameter.

Note: This is a candidate for the stable branches.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_format.c
src/mesa/state_tracker/st_format.h
src/mesa/state_tracker/st_texture.c

index 9c05572d482790f509dae5d88e48fc4a3e792e8f..ec44a4359d11ba8b3283e9cf942f941a52f60781 100644 (file)
@@ -1499,14 +1499,16 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
       if (type == GL_DEPTH) {
          texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
                                       GL_NONE, GL_NONE, st->internal_target,
-                                     sample_count, PIPE_BIND_DEPTH_STENCIL);
+                                      sample_count, PIPE_BIND_DEPTH_STENCIL,
+                                      FALSE);
          assert(texFormat != PIPE_FORMAT_NONE);
       }
       else {
          /* default color format */
          texFormat = st_choose_format(screen, GL_RGBA,
                                       GL_NONE, GL_NONE, st->internal_target,
-                                      sample_count, PIPE_BIND_SAMPLER_VIEW);
+                                      sample_count, PIPE_BIND_SAMPLER_VIEW,
+                                      FALSE);
          assert(texFormat != PIPE_FORMAT_NONE);
       }
    }
index 3cea2df07d9462a850d6049332a79ec6ed160205..80a440d18eb8edd9a43e0b99a5942df642f02e07 100644 (file)
@@ -597,7 +597,7 @@ decompress_with_blit(struct gl_context * ctx,
 
    /* Find the best match for the format+type combo. */
    pipe_format = st_choose_format(pipe->screen, GL_RGBA8, format, type,
-                                  pipe_target, 0, bind);
+                                  pipe_target, 0, bind, FALSE);
    if (pipe_format == PIPE_FORMAT_NONE) {
       /* unable to get an rgba format!?! */
       _mesa_problem(ctx, "%s: cannot find a supported format", __func__);
index 7ef063953c3de61d19b64b784c1e7954bb353cf8..15fe0556de709271e88c244182bb497d59aa07f8 100644 (file)
@@ -1398,18 +1398,25 @@ static const struct format_mapping format_map[] = {
 
 /**
  * Return first supported format from the given list.
+ * \param allow_dxt  indicates whether it's OK to return a DXT format.
  */
 static enum pipe_format
 find_supported_format(struct pipe_screen *screen,
                       const enum pipe_format formats[],
                       enum pipe_texture_target target,
                       unsigned sample_count,
-                      unsigned tex_usage)
+                      unsigned tex_usage,
+                      boolean allow_dxt)
 {
    uint i;
    for (i = 0; formats[i]; i++) {
       if (screen->is_format_supported(screen, formats[i], target,
                                       sample_count, tex_usage)) {
+         if (!allow_dxt && util_format_is_s3tc(formats[i])) {
+            /* we can't return a dxt format, continue searching */
+            continue;
+         }
+
          return formats[i];
       }
    }
@@ -1514,12 +1521,16 @@ find_exact_format(GLint internalFormat, GLenum format, GLenum type)
  * \param internalFormat  the user value passed to glTexImage2D
  * \param target  one of PIPE_TEXTURE_x
  * \param bindings  bitmask of PIPE_BIND_x flags.
+ * \param allow_dxt  indicates whether it's OK to return a DXT format.  This
+ *                   only matters when internalFormat names a generic or
+ *                   specific compressed format.  And that should only happen
+ *                   when we're getting called from gl[Copy]TexImage().
  */
 enum pipe_format
 st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
                  GLenum format, GLenum type,
                  enum pipe_texture_target target, unsigned sample_count,
-                 unsigned bindings)
+                 unsigned bindings, boolean allow_dxt)
 {
    GET_CURRENT_CONTEXT(ctx); /* XXX this should be a function parameter */
    int i, j;
@@ -1547,7 +1558,8 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
              * which is supported by the driver.
              */
             return find_supported_format(screen, mapping->pipeFormats,
-                                         target, sample_count, bindings);
+                                         target, sample_count, bindings,
+                                         allow_dxt);
          }
       }
    }
@@ -1569,8 +1581,8 @@ st_choose_renderbuffer_format(struct pipe_screen *screen,
       usage = PIPE_BIND_DEPTH_STENCIL;
    else
       usage = PIPE_BIND_RENDER_TARGET;
-   return st_choose_format(screen, internalFormat, GL_NONE, GL_NONE, PIPE_TEXTURE_2D,
-                           sample_count, usage);
+   return st_choose_format(screen, internalFormat, GL_NONE, GL_NONE,
+                           PIPE_TEXTURE_2D, sample_count, usage, FALSE);
 }
 
 
@@ -1597,12 +1609,13 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
    }
 
    pFormat = st_choose_format(screen, internalFormat, format, type,
-                              PIPE_TEXTURE_2D, 0, bindings);
+                              PIPE_TEXTURE_2D, 0, bindings, ctx->Mesa_DXTn);
 
    if (pFormat == PIPE_FORMAT_NONE) {
       /* try choosing format again, this time without render target bindings */
       pFormat = st_choose_format(screen, internalFormat, format, type,
-                                 PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
+                                 PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW,
+                                 ctx->Mesa_DXTn);
    }
 
    if (pFormat == PIPE_FORMAT_NONE) {
@@ -1661,7 +1674,7 @@ st_QuerySamplesForFormat(struct gl_context *ctx, GLenum internalFormat,
    /* Set sample counts in descending order. */
    for (i = 16; i > 1; i--) {
       format = st_choose_format(screen, internalFormat, GL_NONE, GL_NONE,
-                                PIPE_TEXTURE_2D, i, bind);
+                                PIPE_TEXTURE_2D, i, bind, FALSE);
 
       if (format != PIPE_FORMAT_NONE) {
          samples[num_sample_counts++] = i;
index cb6e5bc9687fb3818110ff13c51f1c8bc7b55845..eac3cfb3376cf20a21671960c30f5c0a60998cd5 100644 (file)
@@ -51,7 +51,7 @@ extern enum pipe_format
 st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
                  GLenum format, GLenum type,
                  enum pipe_texture_target target, unsigned sample_count,
-                 unsigned bindings);
+                 unsigned bindings, boolean allow_dxt);
 
 extern enum pipe_format
 st_choose_renderbuffer_format(struct pipe_screen *screen,
index ee4d7622d27d222b714f566ed62fee49181ea721..584eaa9817a794072bc7bbe6a59e82f24392bfe4 100644 (file)
@@ -398,7 +398,8 @@ st_create_color_map_texture(struct gl_context *ctx)
 
    /* find an RGBA texture format */
    format = st_choose_format(pipe->screen, GL_RGBA, GL_NONE, GL_NONE,
-                             PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
+                             PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW,
+                             FALSE);
 
    /* create texture for color map/table */
    pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,