[Mesa-dev] [PATCH 3/4] radv: make use of on-disk cache

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Wed Oct 11 11:01:05 UTC 2017


Thanks!

On Wed, Oct 11, 2017 at 12:11 AM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> If the app provided in-memory pipeline cache doesn't yet contain
> what we are looking for, or it doesn't provide one at all then we
> fallback to the on-disk cache.
> ---
>  src/amd/vulkan/radv_pipeline_cache.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
> index 625c58e66c..bced425966 100644
> --- a/src/amd/vulkan/radv_pipeline_cache.c
> +++ b/src/amd/vulkan/radv_pipeline_cache.c
> @@ -16,20 +16,21 @@
>   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
>   * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
>   * IN THE SOFTWARE.
>   */
>
>  #include "util/mesa-sha1.h"
>  #include "util/debug.h"
> +#include "util/disk_cache.h"
>  #include "util/u_atomic.h"
>  #include "radv_debug.h"
>  #include "radv_private.h"
>  #include "radv_shader.h"
>
>  #include "ac_nir_to_llvm.h"
>
>  struct cache_entry {
>         union {
>                 unsigned char sha1[20];
> @@ -158,22 +159,32 @@ radv_create_shader_variant_from_pipeline_cache(struct radv_device *device,
>                                                struct radv_pipeline_cache *cache,
>                                                const unsigned char *sha1)
>  {
>         struct cache_entry *entry = NULL;
>
>         if (cache)
>                 entry = radv_pipeline_cache_search(cache, sha1);
>         else
>                 entry = radv_pipeline_cache_search(device->mem_cache, sha1);
>
> -       if (!entry)
> -               return NULL;
> +       if (!entry) {
> +               uint8_t disk_sha1[20];
> +               disk_cache_compute_key(device->physical_device->disk_cache,
> +                                      sha1, 20, disk_sha1);
> +               entry = (struct cache_entry *)
> +                       disk_cache_get(device->physical_device->disk_cache,
> +                                      disk_sha1, NULL);
> +               if (!entry)
> +                       return NULL;
> +
> +               entry->variant = NULL;
> +       }
>
>         if (!entry->variant) {
>                 struct radv_shader_variant *variant;
>
>                 variant = calloc(1, sizeof(struct radv_shader_variant));
>                 if (!variant)
>                         return NULL;
>
>                 variant->code_size = entry->code_size;
>                 variant->config = entry->config;
> @@ -299,20 +310,30 @@ radv_pipeline_cache_insert_shader(struct radv_device *device,
>         entry->config = variant->config;
>         entry->variant_info = variant->info;
>         entry->rsrc1 = variant->rsrc1;
>         entry->rsrc2 = variant->rsrc2;
>         entry->code_size = code_size;
>         entry->variant = variant;
>         p_atomic_inc(&variant->ref_count);
>
>         radv_pipeline_cache_add_entry(cache, entry);
>
> +       /* Always add cache items to disk. This will allow collection of
> +        * compiled shaders by third parties such as steam, even if the app
> +        * implements its own pipeline cache.
> +        */
> +       uint8_t disk_sha1[20];
> +       disk_cache_compute_key(device->physical_device->disk_cache, sha1, 20,
> +                              disk_sha1);
> +       disk_cache_put(device->physical_device->disk_cache,
> +                      disk_sha1, entry, entry_size(entry), NULL);
> +

You'll probably want to insert this hunk before the entry->variant =
variant line, as that is a pointer and hence  will give variation in
the compiled shaders.

Otherwise, this series is

Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

>         cache->modified = true;
>         pthread_mutex_unlock(&cache->mutex);
>         return variant;
>  }
>
>  struct cache_header {
>         uint32_t header_size;
>         uint32_t header_version;
>         uint32_t vendor_id;
>         uint32_t device_id;
> --
> 2.13.6
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list