st/dri: implement the driconf option force_s3tc_enable properly
authorMarek Olšák <marek.olsak@amd.com>
Tue, 30 Jul 2013 20:29:18 +0000 (22:29 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 30 Jul 2013 21:31:24 +0000 (23:31 +0200)
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/util/u_format_s3tc.c
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/dri/common/dri_context.c
src/gallium/state_trackers/dri/common/dri_screen.c
src/gallium/state_trackers/osmesa/osmesa.c
src/mesa/state_tracker/st_extensions.c

index fd628157b60cf0d6fba8e28f6197725d9140cb89..11b46020bc3aee0315c34b5912d46b57c2c6848a 100644 (file)
@@ -111,7 +111,6 @@ util_format_s3tc_init(void)
    util_dl_proc fetch_2d_texel_rgba_dxt3;
    util_dl_proc fetch_2d_texel_rgba_dxt5;
    util_dl_proc tx_compress_dxtn;
-   char *force_s3tc_enable;
 
    if (!first_time)
       return;
@@ -122,15 +121,8 @@ util_format_s3tc_init(void)
 
    library = util_dl_open(DXTN_LIBNAME);
    if (!library) {
-      if ((force_s3tc_enable = getenv("force_s3tc_enable")) &&
-          !strcmp(force_s3tc_enable, "true")) {
-         debug_printf("couldn't open " DXTN_LIBNAME ", enabling DXTn due to "
-            "force_s3tc_enable=true environment variable\n");
-         util_format_s3tc_enabled = TRUE;
-      } else {
-         debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
-            "compression/decompression unavailable\n");
-      }
+      debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
+                   "compression/decompression unavailable\n");
       return;
    }
 
index fd6d04c4a3d2f658ba346bd688e2a8a5adbb4ae0..2c178b6951d61a2f6ab017ff2bc5ef7ef122f11e 100644 (file)
@@ -242,6 +242,7 @@ struct st_config_options
    boolean force_glsl_extensions_warn;
    boolean disable_glsl_line_continuations;
    boolean disable_blend_func_extended;
+   boolean force_s3tc_enable;
 };
 
 /**
index 5794e487158ed8514ea50161e786b56c0197f01f..ab80fc75bd4187e2b8d9b34c5e29f9bbb454a36a 100644 (file)
@@ -58,6 +58,8 @@ static void dri_fill_st_options(struct st_config_options *options,
       driQueryOptionb(optionCache, "disable_glsl_line_continuations");
    options->disable_blend_func_extended =
       driQueryOptionb(optionCache, "disable_blend_func_extended");
+   options->force_s3tc_enable =
+      driQueryOptionb(optionCache, "force_s3tc_enable");
 }
 
 GLboolean
index c8aed63f1d39bb5021f37890837d782a1f24d450..ca17742eb5bc332da2dac703f8c5f8672259a9e9 100644 (file)
@@ -41,6 +41,7 @@
 #include "state_tracker/drm_driver.h"
 
 #include "util/u_debug.h"
+#include "util/u_format_s3tc.h"
 
 #define MSAA_VISUAL_MAX_SAMPLES 32
 
@@ -54,7 +55,7 @@ PUBLIC const char __driConfigOptions[] =
       DRI_CONF_SECTION_END
 
       DRI_CONF_SECTION_QUALITY
-/*       DRI_CONF_FORCE_S3TC_ENABLE("false") */
+         DRI_CONF_FORCE_S3TC_ENABLE("false")
          DRI_CONF_PP_CELSHADE(0)
          DRI_CONF_PP_NORED(0)
          DRI_CONF_PP_NOGREEN(0)
@@ -76,7 +77,7 @@ PUBLIC const char __driConfigOptions[] =
 
 #define false 0
 
-static const uint __driNConfigOptions = 12;
+static const uint __driNConfigOptions = 13;
 
 static const __DRIconfig **
 dri_fill_in_modes(struct dri_screen *screen)
@@ -416,6 +417,20 @@ dri_init_screen_helper(struct dri_screen *screen,
                        screen->sPriv->myNum,
                        driver_descriptor.name);
 
+   /* Handle force_s3tc_enable. */
+   if (!util_format_s3tc_enabled &&
+       driQueryOptionb(&screen->optionCache, "force_s3tc_enable")) {
+      /* Ensure libtxc_dxtn has been loaded if available.
+       * Forcing S3TC on before calling this would prevent loading
+       * the library.
+       * This is just a precaution, the driver should have called it
+       * already.
+       */
+      util_format_s3tc_init();
+
+      util_format_s3tc_enabled = TRUE;
+   }
+
    return dri_fill_in_modes(screen);
 }
 
index 5908316dc815ae96e9f96e23f10fac8cf8b88dab..594372bd7258e2f7d0974470787da6582dbca9f7 100644 (file)
@@ -545,6 +545,7 @@ OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits,
    attribs.options.force_glsl_extensions_warn = FALSE;
    attribs.options.disable_blend_func_extended = FALSE;
    attribs.options.disable_glsl_line_continuations = FALSE;
+   attribs.options.force_s3tc_enable = FALSE;
 
    osmesa_init_st_visual(&attribs.visual,
                          PIPE_FORMAT_R8G8B8A8_UNORM,
index b201012f9d2edc05474cfc2e50644fc5a68fae59..6bc1284f82699f41fd40223a92c1527a86219646 100644 (file)
@@ -289,14 +289,6 @@ void st_init_limits(struct st_context *st)
 }
 
 
-static GLboolean st_get_s3tc_override(void)
-{
-   const char *override = _mesa_getenv("force_s3tc_enable");
-   if (override && !strcmp(override, "true"))
-      return GL_TRUE;
-   return GL_FALSE;
-}
-
 /**
  * Given a member \c x of struct gl_extensions, return offset of
  * \c x in bytes.
@@ -628,7 +620,7 @@ void st_init_extensions(struct st_context *st)
 
    /* Below are the cases which cannot be moved into tables easily. */
 
-   if (!ctx->Mesa_DXTn && !st_get_s3tc_override()) {
+   if (!ctx->Mesa_DXTn && !st->options.force_s3tc_enable) {
       ctx->Extensions.EXT_texture_compression_s3tc = GL_FALSE;
       ctx->Extensions.ANGLE_texture_compression_dxt = GL_FALSE;
    }