r300g: implement GLSL disk shader caching
authorRui Salvaterra <rsalvaterra@gmail.com>
Fri, 7 Jun 2019 11:19:23 +0000 (12:19 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 12 Jun 2019 00:49:34 +0000 (20:49 -0400)
This implements GLSL disk shader caching for the R300-R500 series of AMD GPUs.

Signed-off-by: Rui Salvaterra <rsalvaterra@gmail.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_screen.h

index d26cf901a7b5b7bf33c9eb074bfe13f21794fdf2..b9df321de867d8373b3b59d26de5afb5a0ee3b7f 100644 (file)
@@ -80,11 +80,42 @@ static const char* chip_families[] = {
     "ATI RV570"
 };
 
+static const char* r300_get_family_name(struct r300_screen* r300screen)
+{
+    return chip_families[r300screen->caps.family];
+}
+
 static const char* r300_get_name(struct pipe_screen* pscreen)
 {
     struct r300_screen* r300screen = r300_screen(pscreen);
 
-    return chip_families[r300screen->caps.family];
+    return r300_get_family_name(r300screen);
+}
+
+static void r300_disk_cache_create(struct r300_screen* r300screen)
+{
+    struct mesa_sha1 ctx;
+    unsigned char sha1[20];
+    char cache_id[20 * 2 + 1];
+
+    _mesa_sha1_init(&ctx);
+    if (!disk_cache_get_function_identifier(r300_disk_cache_create,
+                                            &ctx))
+        return;
+
+    _mesa_sha1_final(&ctx, sha1);
+    disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
+
+    r300screen->disk_shader_cache =
+                    disk_cache_create(r300_get_family_name(r300screen),
+                                      cache_id,
+                                      r300screen->debug);
+}
+
+static struct disk_cache* r300_get_disk_shader_cache(struct pipe_screen* pscreen)
+{
+       struct r300_screen* r300screen = r300_screen(pscreen);
+       return r300screen->disk_shader_cache;
 }
 
 static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
@@ -745,6 +776,8 @@ static void r300_destroy_screen(struct pipe_screen* pscreen)
     mtx_destroy(&r300screen->cmask_mutex);
     slab_destroy_parent(&r300screen->pool_transfers);
 
+    disk_cache_destroy(r300screen->disk_shader_cache);
+
     if (rws)
       rws->destroy(rws);
 
@@ -795,6 +828,7 @@ struct pipe_screen* r300_screen_create(struct radeon_winsys *rws,
     r300screen->screen.get_name = r300_get_name;
     r300screen->screen.get_vendor = r300_get_vendor;
     r300screen->screen.get_device_vendor = r300_get_device_vendor;
+    r300screen->screen.get_disk_shader_cache = r300_get_disk_shader_cache;
     r300screen->screen.get_param = r300_get_param;
     r300screen->screen.get_shader_param = r300_get_shader_param;
     r300screen->screen.get_paramf = r300_get_paramf;
@@ -807,6 +841,8 @@ struct pipe_screen* r300_screen_create(struct radeon_winsys *rws,
 
     r300_init_screen_resource_functions(r300screen);
 
+    r300_disk_cache_create(r300screen);
+
     slab_create_parent(&r300screen->pool_transfers, sizeof(struct pipe_transfer), 64);
 
     (void) mtx_init(&r300screen->cmask_mutex, mtx_plain);
index 952dc341ab7ec7394625f7ac20387fa676599eed..b28de008304a70b5c2f026b876901e27394f2093 100644 (file)
@@ -27,6 +27,7 @@
 #include "r300_chipset.h"
 #include "radeon/radeon_winsys.h"
 #include "pipe/p_screen.h"
+#include "util/disk_cache.h"
 #include "util/slab.h"
 #include "os/os_thread.h"
 #include <stdio.h>
@@ -44,6 +45,8 @@ struct r300_screen {
     /** Combination of DBG_xxx flags */
     unsigned debug;
 
+    struct disk_cache *disk_shader_cache;
+
     struct slab_parent_pool pool_transfers;
 
     /* The MSAA texture with CMASK access; */