On Wed, Oct 18, 2017 at 10:32 PM, Jordan Justen
<jordan.l.jus...@intel.com> wrote:
> Double negative FTW!
>
> For now, the shader cache is disabled by default on i965 to allow us
> to verify its stability.
>
> In other words, to enable the shader cache on i965, set
> MESA_GLSL_CACHE_DISABLE to false or 0. If the variable is unset, then
> the shader cache will be disabled.
>
> We use the build-id of i965_dri.so for the timestamp, and the pci
> device id for the device name.
>
> v2:
>  * Simplify code by forcing link to include build id sha. (Matt)
>
> Signed-off-by: Jordan Justen <jordan.l.jus...@intel.com>
> ---
>  src/mesa/drivers/dri/i965/brw_context.c    |  2 ++
>  src/mesa/drivers/dri/i965/brw_disk_cache.c | 39 
> ++++++++++++++++++++++++++++++
>  src/mesa/drivers/dri/i965/brw_state.h      |  1 +
>  3 files changed, 42 insertions(+)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
> b/src/mesa/drivers/dri/i965/brw_context.c
> index 6a88d8bb48..1fdaf02022 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.c
> +++ b/src/mesa/drivers/dri/i965/brw_context.c
> @@ -1018,6 +1018,8 @@ brwCreateContext(gl_api api,
>                           brw->dri_config_options_sha1);
>     brw->ctx.Const.dri_config_options_sha1 = brw->dri_config_options_sha1;
>
> +   brw_disk_cache_init(brw);
> +
>     return true;
>  }
>
> diff --git a/src/mesa/drivers/dri/i965/brw_disk_cache.c 
> b/src/mesa/drivers/dri/i965/brw_disk_cache.c
> index 790fad6925..582c2cfbc7 100644
> --- a/src/mesa/drivers/dri/i965/brw_disk_cache.c
> +++ b/src/mesa/drivers/dri/i965/brw_disk_cache.c
> @@ -26,6 +26,8 @@
>  #include "compiler/glsl/shader_cache.h"
>  #include "compiler/nir/nir_serialize.h"
>  #include "main/mtypes.h"
> +#include "util/build_id.h"
> +#include "util/debug.h"
>  #include "util/disk_cache.h"
>  #include "util/macros.h"
>  #include "util/mesa-sha1.h"
> @@ -496,3 +498,40 @@ brw_disk_cache_write_compute_program(struct brw_context 
> *brw)
>                           MESA_SHADER_COMPUTE);
>     }
>  }
> +
> +void
> +brw_disk_cache_init(struct brw_context *brw)
> +{
> +#ifdef ENABLE_SHADER_CACHE
> +   if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", true))
> +      return;
> +
> +   char *renderer = NULL;
> +   int len = asprintf(&renderer, "i965_%04x", brw->screen->deviceID);
> +   if (len < 0) {
> +      renderer = strdup("i965");
> +   }
> +   if (renderer == NULL)
> +       return;
> +
> +   const struct build_id_note *note =
> +      build_id_find_nhdr_for_addr(brw_disk_cache_init);
> +   assert(note);
> +   int id_size = build_id_length(note);
> +   char *timestamp = malloc(2 * id_size + 1);
> +
> +   const uint8_t *data = build_id_data(note);
> +   int i;
> +   for (i = 0; i < id_size; i++)
> +      snprintf(&timestamp[2 * i], 3, "%02x", data[i]);

This is kind of trivial, but it bothered me. :)

Maybe just do

        static const char hex[] = "0123456789ABCDEF";
        for (int i = 0; i < id_size; i++) {
                str[i * 2 + 0] = hex[data[i] / 16];
                str[i * 2 + 1] = hex[data[i] % 16];
        }
        str[16] = '\0';

which doesn't call snprintf() 8 times (which overwrites the NUL byte
written by the previous call).
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to