From 6c0c61cb48e87d9b0fc545cf30016d3947a47b6a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 21 Apr 2020 13:14:20 +1000 Subject: [PATCH] llvmpipe: add infrastructure for disk cache support This hooks up the gallium API and adds the APIs needed for shader stages to search and add things to the cache. It also adds cache stats debug printing. Reviewed-by: Roland Scheidegger Part-of: --- .gitlab-ci/piglit/quick_gl.txt | 10 ++-- .gitlab-ci/piglit/quick_shader.txt | 5 +- src/gallium/drivers/llvmpipe/lp_debug.h | 1 + src/gallium/drivers/llvmpipe/lp_screen.c | 67 +++++++++++++++++++++++- src/gallium/drivers/llvmpipe/lp_screen.h | 13 ++++- 5 files changed, 83 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci/piglit/quick_gl.txt b/.gitlab-ci/piglit/quick_gl.txt index 4c507de3a6c..a870a007206 100644 --- a/.gitlab-ci/piglit/quick_gl.txt +++ b/.gitlab-ci/piglit/quick_gl.txt @@ -499,10 +499,6 @@ spec/arb_geometry_shader4/arb_geometry_shader4-program-parameter-vertices-out ma spec/arb_geometry_shader4/arb_geometry_shader4-program-parameter-vertices-out tf 1: skip spec/arb_geometry_shader4/arb_geometry_shader4-program-parameter-vertices-out tf max: skip spec/arb_geometry_shader4/arb_geometry_shader4-vertices-in: skip -spec/arb_get_program_binary/reset-uniform: skip -spec/arb_get_program_binary/restore-implicit-use-program: skip -spec/arb_get_program_binary/restore-sso-program: fail -spec/arb_get_program_binary/xfb-varyings: skip spec/arb_gpu_shader_fp64/execution/arb_gpu_shader_fp64-dlist-uniforms: skip spec/arb_gpu_shader_fp64/execution/arb_gpu_shader_fp64-fs-non-uniform-control-flow-ssbo: skip spec/arb_gpu_shader_fp64/execution/arb_gpu_shader_fp64-vs-non-uniform-control-flow-ssbo: skip @@ -1762,10 +1758,10 @@ wgl/wgl-sanity: skip summary: name: results ---- -------- - pass: 21749 - fail: 226 + pass: 21753 + fail: 225 crash: 0 - skip: 1511 + skip: 1508 timeout: 0 warn: 6 incomplete: 0 diff --git a/.gitlab-ci/piglit/quick_shader.txt b/.gitlab-ci/piglit/quick_shader.txt index e8c6bc33804..281e752e420 100644 --- a/.gitlab-ci/piglit/quick_shader.txt +++ b/.gitlab-ci/piglit/quick_shader.txt @@ -114,7 +114,6 @@ spec/arb_geometry_shader4/linker/no-vertex-shader-only-built-in-input-varyings-e spec/arb_geometry_shader4/linker/no-vertex-shader-user-defined-input-varying: skip spec/arb_geometry_shader4/linker/varying-mismatch: skip spec/arb_geometry_shader4/linker/verticesin-const: skip -spec/arb_get_program_binary/execution/uniform-after-restore: skip spec/arb_gl_spirv/execution/ssbo/aoa: skip spec/arb_gl_spirv/execution/ssbo/aoa-2: skip spec/arb_gl_spirv/execution/ssbo/array: skip @@ -5151,10 +5150,10 @@ spec/oes_viewport_array/viewport-gs-writes-out-of-range: skip summary: name: results ---- -------- - pass: 11218 + pass: 11219 fail: 54 crash: 120 - skip: 4976 + skip: 4975 timeout: 0 warn: 0 incomplete: 0 diff --git a/src/gallium/drivers/llvmpipe/lp_debug.h b/src/gallium/drivers/llvmpipe/lp_debug.h index 4e17f41cd9d..41047fbc754 100644 --- a/src/gallium/drivers/llvmpipe/lp_debug.h +++ b/src/gallium/drivers/llvmpipe/lp_debug.h @@ -47,6 +47,7 @@ #define DEBUG_CS 0x10000 #define DEBUG_TGSI_IR 0x20000 #define DEBUG_CL 0x40000 +#define DEBUG_CACHE_STATS 0x80000 /* Performance flags. These are active even on release builds. */ diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index 61aac82d0d8..643121a04c1 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -38,7 +38,7 @@ #include "draw/draw_context.h" #include "gallivm/lp_bld_type.h" #include "gallivm/lp_bld_nir.h" - +#include "util/disk_cache.h" #include "util/os_misc.h" #include "util/os_time.h" #include "lp_texture.h" @@ -75,6 +75,7 @@ static const struct debug_named_value lp_debug_flags[] = { { "cs", DEBUG_CS, NULL }, { "tgsi_ir", DEBUG_TGSI_IR, NULL }, { "cl", DEBUG_CL, NULL }, + { "cache_stats", DEBUG_CACHE_STATS, NULL }, DEBUG_NAMED_VALUE_END }; #endif @@ -787,6 +788,10 @@ llvmpipe_destroy_screen( struct pipe_screen *_screen ) lp_jit_screen_cleanup(screen); + if (LP_DEBUG & DEBUG_CACHE_STATS) + printf("disk shader cache: hits = %u, misses = %u\n", screen->num_disk_shader_cache_hits, + screen->num_disk_shader_cache_misses); + disk_cache_destroy(screen->disk_shader_cache); if(winsys->destroy) winsys->destroy(winsys); @@ -844,6 +849,63 @@ llvmpipe_get_timestamp(struct pipe_screen *_screen) return os_time_get_nano(); } +static void lp_disk_cache_create(struct llvmpipe_screen *screen) +{ + struct mesa_sha1 ctx; + unsigned char sha1[20]; + char cache_id[20 * 2 + 1]; + _mesa_sha1_init(&ctx); + + if (!disk_cache_get_function_identifier(lp_disk_cache_create, &ctx) || + !disk_cache_get_function_identifier(LLVMLinkInMCJIT, &ctx)) + return; + + _mesa_sha1_final(&ctx, sha1); + disk_cache_format_hex_id(cache_id, sha1, 20 * 2); + + screen->disk_shader_cache = disk_cache_create("llvmpipe", cache_id, 0); +} + +static struct disk_cache *lp_get_disk_shader_cache(struct pipe_screen *_screen) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(_screen); + + return screen->disk_shader_cache; +} + +void lp_disk_cache_find_shader(struct llvmpipe_screen *screen, + struct lp_cached_code *cache, + unsigned char ir_sha1_cache_key[20]) +{ + unsigned char sha1[CACHE_KEY_SIZE]; + + if (!screen->disk_shader_cache) + return; + disk_cache_compute_key(screen->disk_shader_cache, ir_sha1_cache_key, 20, sha1); + + size_t binary_size; + uint8_t *buffer = disk_cache_get(screen->disk_shader_cache, sha1, &binary_size); + if (!buffer) { + cache->data_size = 0; + p_atomic_inc(&screen->num_disk_shader_cache_misses); + return; + } + cache->data_size = binary_size; + cache->data = buffer; + p_atomic_inc(&screen->num_disk_shader_cache_hits); +} + +void lp_disk_cache_insert_shader(struct llvmpipe_screen *screen, + struct lp_cached_code *cache, + unsigned char ir_sha1_cache_key[20]) +{ + unsigned char sha1[CACHE_KEY_SIZE]; + + if (!screen->disk_shader_cache || !cache->data_size || cache->dont_cache) + return; + disk_cache_compute_key(screen->disk_shader_cache, ir_sha1_cache_key, 20, sha1); + disk_cache_put(screen->disk_shader_cache, sha1, cache->data, cache->data_size, NULL); +} /** * Create a new pipe_screen object * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen). @@ -894,6 +956,8 @@ llvmpipe_create_screen(struct sw_winsys *winsys) screen->base.get_timestamp = llvmpipe_get_timestamp; screen->base.finalize_nir = llvmpipe_finalize_nir; + + screen->base.get_disk_shader_cache = lp_get_disk_shader_cache; llvmpipe_init_screen_resource_funcs(&screen->base); screen->use_tgsi = (LP_DEBUG & DEBUG_TGSI_IR); @@ -921,5 +985,6 @@ llvmpipe_create_screen(struct sw_winsys *winsys) } (void) mtx_init(&screen->cs_mutex, mtx_plain); + lp_disk_cache_create(screen); return &screen->base; } diff --git a/src/gallium/drivers/llvmpipe/lp_screen.h b/src/gallium/drivers/llvmpipe/lp_screen.h index 7c57f3ec1fc..88f87f9dcbd 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.h +++ b/src/gallium/drivers/llvmpipe/lp_screen.h @@ -38,7 +38,7 @@ #include "pipe/p_defines.h" #include "os/os_thread.h" #include "gallivm/lp_bld.h" - +#include "gallivm/lp_bld_misc.h" struct sw_winsys; struct lp_cs_tpool; @@ -62,9 +62,18 @@ struct llvmpipe_screen mtx_t cs_mutex; bool use_tgsi; -}; + struct disk_cache *disk_shader_cache; + unsigned num_disk_shader_cache_hits; + unsigned num_disk_shader_cache_misses; +}; +void lp_disk_cache_find_shader(struct llvmpipe_screen *screen, + struct lp_cached_code *cache, + unsigned char ir_sha1_cache_key[20]); +void lp_disk_cache_insert_shader(struct llvmpipe_screen *screen, + struct lp_cached_code *cache, + unsigned char ir_sha1_cache_key[20]); static inline struct llvmpipe_screen * -- 2.30.2