On Fri, 2018-10-26 at 14:52 +1100, Timothy Arceri wrote:
> Pushed. Thanks again!
> 
> Ccing stable in case the Fixes tag isnt enough for this to get picked up 
> (since the previous cache fix this fixes was also backported)
> 

Enqueued for 18.2. I didn't apply cleanly, so I've fixed the conflicts. You can
check the fixed commit here:


https://gitlab.freedesktop.org/mesa/mesa/commit/37ba112d0772cb21ccbf1dd9abcdd3eefe692db7


        J.A.
> On 24/10/18 11:51 am, David McFarland wrote:
> > After discussion with Timothy Arceri. disk_cache_get_function_identifier
> > was using only the first byte of the sha1 build-id.  Replace
> > disk_cache_get_function_identifier with implementation from
> > radv_get_build_id.  Instead of writing a uint32_t it now writes to a
> > mesa_sha1.  All drivers using disk_cache_get_function_identifier are
> > updated accordingly.
> > 
> > Reviewed-by: Timothy Arceri <tarc...@itsqueeze.com>
> > Fixes: 83ea8dd99bb1 ("util: add disk_cache_get_function_identifier()")
> > ---
> >   src/amd/vulkan/radv_device.c                 | 22 +------
> >   src/gallium/drivers/nouveau/nouveau_screen.c | 29 ++++-----
> >   src/gallium/drivers/r600/r600_pipe_common.c  | 43 ++++++-------
> >   src/gallium/drivers/radeonsi/si_pipe.c       | 64 ++++++++++----------
> >   src/util/disk_cache.h                        | 16 +++--
> >   5 files changed, 81 insertions(+), 93 deletions(-)
> > 
> > diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
> > index cf1132098d..81b558b91c 100644
> > --- a/src/amd/vulkan/radv_device.c
> > +++ b/src/amd/vulkan/radv_device.c
> > @@ -49,24 +49,6 @@
> >   #include "util/debug.h"
> >   #include "util/mesa-sha1.h"
> >   
> > -static bool
> > -radv_get_build_id(void *ptr, struct mesa_sha1 *ctx)
> > -{
> > -   uint32_t timestamp;
> > -
> > -#ifdef HAVE_DL_ITERATE_PHDR
> > -   const struct build_id_note *note = NULL;
> > -   if ((note = build_id_find_nhdr_for_addr(ptr))) {
> > -           _mesa_sha1_update(ctx, build_id_data(note), 
> > build_id_length(note));
> > -   } else
> > -#endif
> > -   if (disk_cache_get_function_timestamp(ptr, &timestamp)) {
> > -           _mesa_sha1_update(ctx, &timestamp, sizeof(timestamp));
> > -   } else
> > -           return false;
> > -   return true;
> > -}
> > -
> >   static int
> >   radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
> >   {
> > @@ -77,8 +59,8 @@ radv_device_get_cache_uuid(enum radeon_family family, 
> > void *uuid)
> >     memset(uuid, 0, VK_UUID_SIZE);
> >     _mesa_sha1_init(&ctx);
> >   
> > -   if (!radv_get_build_id(radv_device_get_cache_uuid, &ctx) ||
> > -       !radv_get_build_id(LLVMInitializeAMDGPUTargetInfo, &ctx))
> > +   if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid, 
> > &ctx) ||
> > +       !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, 
> > &ctx))
> >             return -1;
> >   
> >     _mesa_sha1_update(&ctx, &family, sizeof(family));
> > diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c 
> > b/src/gallium/drivers/nouveau/nouveau_screen.c
> > index eb184d3559..d7898ed58f 100644
> > --- a/src/gallium/drivers/nouveau/nouveau_screen.c
> > +++ b/src/gallium/drivers/nouveau/nouveau_screen.c
> > @@ -148,20 +148,21 @@ nouveau_screen_bo_get_handle(struct pipe_screen 
> > *pscreen,
> >   static void
> >   nouveau_disk_cache_create(struct nouveau_screen *screen)
> >   {
> > -   uint32_t mesa_id;
> > -   char *mesa_id_str;
> > -   int res;
> > -
> > -   if (disk_cache_get_function_identifier(nouveau_disk_cache_create,
> > -                                          &mesa_id)) {
> > -      res = asprintf(&mesa_id_str, "%u", mesa_id);
> > -      if (res != -1) {
> > -         screen->disk_shader_cache =
> > -            disk_cache_create(nouveau_screen_get_name(&screen->base),
> > -                              mesa_id_str, 0);
> > -         free(mesa_id_str);
> > -      }
> > -   }
> > +   struct mesa_sha1 ctx;
> > +   unsigned char sha1[20];
> > +   char cache_id[20 * 2 + 1];
> > +
> > +   _mesa_sha1_init(&ctx);
> > +   if (!disk_cache_get_function_identifier(nouveau_disk_cache_create,
> > +                                           &ctx))
> > +      return;
> > +
> > +   _mesa_sha1_final(&ctx, sha1);
> > +   disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
> > +
> > +   screen->disk_shader_cache =
> > +      disk_cache_create(nouveau_screen_get_name(&screen->base),
> > +                        cache_id, 0);
> >   }
> >   
> >   int
> > diff --git a/src/gallium/drivers/r600/r600_pipe_common.c 
> > b/src/gallium/drivers/r600/r600_pipe_common.c
> > index 6b581242a1..e7c645611d 100644
> > --- a/src/gallium/drivers/r600/r600_pipe_common.c
> > +++ b/src/gallium/drivers/r600/r600_pipe_common.c
> > @@ -854,27 +854,28 @@ static void r600_disk_cache_create(struct 
> > r600_common_screen *rscreen)
> >     if (rscreen->debug_flags & DBG_ALL_SHADERS)
> >             return;
> >   
> > -   uint32_t mesa_id;
> > -   if (disk_cache_get_function_identifier(r600_disk_cache_create,
> > -                                          &mesa_id)) {
> > -           char *mesa_id_str;
> > -           int res = -1;
> > -
> > -           res = asprintf(&mesa_id_str, "%u", mesa_id);
> > -           if (res != -1) {
> > -                   /* These flags affect shader compilation. */
> > -                   uint64_t shader_debug_flags =
> > -                           rscreen->debug_flags &
> > -                           (DBG_FS_CORRECT_DERIVS_AFTER_KILL |
> > -                            DBG_UNSAFE_MATH);
> > -
> > -                   rscreen->disk_shader_cache =
> > -                           disk_cache_create(r600_get_family_name(rscreen),
> > -                                             mesa_id_str,
> > -                                             shader_debug_flags);
> > -                   free(mesa_id_str);
> > -           }
> > -   }
> > +   struct mesa_sha1 ctx;
> > +   unsigned char sha1[20];
> > +   char cache_id[20 * 2 + 1];
> > +
> > +   _mesa_sha1_init(&ctx);
> > +   if (!disk_cache_get_function_identifier(r600_disk_cache_create,
> > +                                           &ctx))
> > +           return;
> > +
> > +   _mesa_sha1_final(&ctx, sha1);
> > +   disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
> > +
> > +   /* These flags affect shader compilation. */
> > +   uint64_t shader_debug_flags =
> > +           rscreen->debug_flags &
> > +           (DBG_FS_CORRECT_DERIVS_AFTER_KILL |
> > +            DBG_UNSAFE_MATH);
> > +
> > +   rscreen->disk_shader_cache =
> > +           disk_cache_create(r600_get_family_name(rscreen),
> > +                             cache_id,
> > +                             shader_debug_flags);
> >   }
> >   
> >   static struct disk_cache *r600_get_disk_shader_cache(struct pipe_screen 
> > *pscreen)
> > diff --git a/src/gallium/drivers/radeonsi/si_pipe.c 
> > b/src/gallium/drivers/radeonsi/si_pipe.c
> > index 7bc34498cf..6118b8076f 100644
> > --- a/src/gallium/drivers/radeonsi/si_pipe.c
> > +++ b/src/gallium/drivers/radeonsi/si_pipe.c
> > @@ -793,39 +793,39 @@ static void si_disk_cache_create(struct si_screen 
> > *sscreen)
> >     if (sscreen->debug_flags & DBG_ALL_SHADERS)
> >             return;
> >   
> > -   uint32_t mesa_id;
> > -   if (disk_cache_get_function_identifier(si_disk_cache_create, &mesa_id)) 
> > {
> > -           char *driver_id_str;
> > -           int res = -1;
> > -           uint32_t llvm_id;
> > -           if 
> > (disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo,
> > -                                                  &llvm_id)) {
> > -                   res = asprintf(&driver_id_str, "%u_%u", mesa_id, 
> > llvm_id);
> > -           }
> > +   struct mesa_sha1 ctx;
> > +   unsigned char sha1[20];
> > +   char cache_id[20 * 2 + 1];
> >   
> > -           if (res != -1) {
> > -                   /* These flags affect shader compilation. */
> > -                   #define ALL_FLAGS (DBG(FS_CORRECT_DERIVS_AFTER_KILL) | \
> > -                                      DBG(SI_SCHED) | \
> > -                                      DBG(GISEL) | \
> > -                                      DBG(UNSAFE_MATH) | \
> > -                                      DBG(NIR))
> > -                   uint64_t shader_debug_flags = sscreen->debug_flags &
> > -                                                 ALL_FLAGS;
> > -
> > -                   /* Add the high bits of 32-bit addresses, which affects
> > -                    * how 32-bit addresses are expanded to 64 bits.
> > -                    */
> > -                   STATIC_ASSERT(ALL_FLAGS <= UINT_MAX);
> > -                   shader_debug_flags |= 
> > (uint64_t)sscreen->info.address32_hi << 32;
> > -
> > -                   sscreen->disk_shader_cache =
> > -                           disk_cache_create(sscreen->info.name,
> > -                                             driver_id_str,
> > -                                             shader_debug_flags);
> > -                   free(driver_id_str);
> > -           }
> > -   }
> > +   _mesa_sha1_init(&ctx);
> > +
> > +   if (!disk_cache_get_function_identifier(si_disk_cache_create, &ctx) ||
> > +       !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo,
> > +                                           &ctx))
> > +           return;
> > +
> > +   _mesa_sha1_final(&ctx, sha1);
> > +   disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
> > +
> > +   /* These flags affect shader compilation. */
> > +   #define ALL_FLAGS (DBG(FS_CORRECT_DERIVS_AFTER_KILL) |  \
> > +                      DBG(SI_SCHED) |                      \
> > +                      DBG(GISEL) |                         \
> > +                      DBG(UNSAFE_MATH) |                   \
> > +                      DBG(NIR))
> > +   uint64_t shader_debug_flags = sscreen->debug_flags &
> > +           ALL_FLAGS;
> > +
> > +   /* Add the high bits of 32-bit addresses, which affects
> > +    * how 32-bit addresses are expanded to 64 bits.
> > +    */
> > +   STATIC_ASSERT(ALL_FLAGS <= UINT_MAX);
> > +   shader_debug_flags |= (uint64_t)sscreen->info.address32_hi << 32;
> > +
> > +   sscreen->disk_shader_cache =
> > +           disk_cache_create(sscreen->info.name,
> > +                             cache_id,
> > +                             shader_debug_flags);
> >   }
> >   
> >   struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
> > diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
> > index 3129de8ec9..2a147cba61 100644
> > --- a/src/util/disk_cache.h
> > +++ b/src/util/disk_cache.h
> > @@ -33,6 +33,7 @@
> >   #include <stdint.h>
> >   #include <stdbool.h>
> >   #include <sys/stat.h>
> > +#include "util/mesa-sha1.h"
> >   
> >   #ifdef __cplusplus
> >   extern "C" {
> > @@ -115,18 +116,21 @@ disk_cache_get_function_timestamp(void *ptr, 
> > uint32_t* timestamp)
> >   }
> >   
> >   static inline bool
> > -disk_cache_get_function_identifier(void *ptr, uint32_t *id)
> > +disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx)
> >   {
> > +   uint32_t timestamp;
> > +
> >   #ifdef HAVE_DL_ITERATE_PHDR
> >      const struct build_id_note *note = NULL;
> >      if ((note = build_id_find_nhdr_for_addr(ptr))) {
> > -      const uint8_t *id_sha1 = build_id_data(note);
> > -      assert(id_sha1);
> > -      *id = *id_sha1;
> > -      return true;
> > +      _mesa_sha1_update(ctx, build_id_data(note), build_id_length(note));
> >      } else
> >   #endif
> > -   return disk_cache_get_function_timestamp(ptr, id);
> > +   if (disk_cache_get_function_timestamp(ptr, &timestamp)) {
> > +      _mesa_sha1_update(ctx, &timestamp, sizeof(timestamp));
> > +   } else
> > +      return false;
> > +   return true;
> >   }
> >   #endif
> >   
> > 
> 
> _______________________________________________
> mesa-stable mailing list
> mesa-sta...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-stable

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to