Mesa (master): gallivm: add support for a cache object

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 10 22:26:12 UTC 2020


Module: Mesa
Branch: master
Commit: 7b7c02d161df2f09fa06b8b0b42caf869a326dc9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7b7c02d161df2f09fa06b8b0b42caf869a326dc9

Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 13 09:30:44 2020 +1000

gallivm: add support for a cache object

This plumbs the cache object into the gallivm API, nothing uses
it yet.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5049>

---

 src/gallium/auxiliary/draw/draw_llvm.c        |  8 ++++----
 src/gallium/auxiliary/gallivm/lp_bld_init.c   | 14 ++++++++++----
 src/gallium/auxiliary/gallivm/lp_bld_init.h   |  5 ++++-
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp |  1 +
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   | 12 ++++++++++++
 src/gallium/drivers/llvmpipe/lp_state_cs.c    |  2 +-
 src/gallium/drivers/llvmpipe/lp_state_fs.c    |  2 +-
 src/gallium/drivers/llvmpipe/lp_state_setup.c |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_arit.c   |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_blend.c  |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_conv.c   |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_format.c |  4 ++--
 src/gallium/drivers/llvmpipe/lp_test_printf.c |  2 +-
 src/gallium/drivers/swr/swr_shader.cpp        |  2 +-
 14 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index db8e24f4306..445f2e11130 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -850,7 +850,7 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
    snprintf(module_name, sizeof(module_name), "draw_llvm_vs_variant%u",
             variant->shader->variants_cached);
 
-   variant->gallivm = gallivm_create(module_name, llvm->context);
+   variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
 
    create_jit_types(variant);
 
@@ -2848,7 +2848,7 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm,
    snprintf(module_name, sizeof(module_name), "draw_llvm_gs_variant%u",
             variant->shader->variants_cached);
 
-   variant->gallivm = gallivm_create(module_name, llvm->context);
+   variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
 
    create_gs_jit_types(variant);
 
@@ -3453,7 +3453,7 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm,
    snprintf(module_name, sizeof(module_name), "draw_llvm_tcs_variant%u",
             variant->shader->variants_cached);
 
-   variant->gallivm = gallivm_create(module_name, llvm->context);
+   variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
 
    create_tcs_jit_types(variant);
 
@@ -3928,7 +3928,7 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm,
    snprintf(module_name, sizeof(module_name), "draw_llvm_tes_variant%u",
             variant->shader->variants_cached);
 
-   variant->gallivm = gallivm_create(module_name, llvm->context);
+   variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
 
    create_tes_jit_types(variant);
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index ce522806669..06214014290 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -211,6 +211,9 @@ gallivm_free_ir(struct gallivm_state *gallivm)
       LLVMDisposeModule(gallivm->module);
    }
 
+   if (gallivm->cache) {
+      free(gallivm->cache->data);
+   }
    FREE(gallivm->module_name);
 
    if (gallivm->target) {
@@ -230,6 +233,7 @@ gallivm_free_ir(struct gallivm_state *gallivm)
    gallivm->passmgr = NULL;
    gallivm->context = NULL;
    gallivm->builder = NULL;
+   gallivm->cache = NULL;
 }
 
 
@@ -265,6 +269,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
 
       ret = lp_build_create_jit_compiler_for_module(&gallivm->engine,
                                                     &gallivm->code,
+                                                    gallivm->cache,
                                                     gallivm->module,
                                                     gallivm->memorymgr,
                                                     (unsigned) optlevel,
@@ -310,7 +315,7 @@ fail:
  */
 static boolean
 init_gallivm_state(struct gallivm_state *gallivm, const char *name,
-                   LLVMContextRef context)
+                   LLVMContextRef context, struct lp_cached_code *cache)
 {
    assert(!gallivm->context);
    assert(!gallivm->module);
@@ -319,7 +324,7 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name,
       return FALSE;
 
    gallivm->context = context;
-
+   gallivm->cache = cache;
    if (!gallivm->context)
       goto fail;
 
@@ -496,13 +501,14 @@ lp_build_init(void)
  * Create a new gallivm_state object.
  */
 struct gallivm_state *
-gallivm_create(const char *name, LLVMContextRef context)
+gallivm_create(const char *name, LLVMContextRef context,
+               struct lp_cached_code *cache)
 {
    struct gallivm_state *gallivm;
 
    gallivm = CALLOC_STRUCT(gallivm_state);
    if (gallivm) {
-      if (!init_gallivm_state(gallivm, name, context)) {
+      if (!init_gallivm_state(gallivm, name, context, cache)) {
          FREE(gallivm);
          gallivm = NULL;
       }
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index cebf6a793d5..4b00cebaef5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -39,6 +39,7 @@
 extern "C" {
 #endif
 
+struct lp_cached_code;
 struct gallivm_state
 {
    char *module_name;
@@ -51,6 +52,7 @@ struct gallivm_state
    LLVMBuilderRef builder;
    LLVMMCJITMemoryManagerRef memorymgr;
    struct lp_generated_code *code;
+   struct lp_cached_code *cache;
    unsigned compiled;
    LLVMValueRef coro_malloc_hook;
    LLVMValueRef coro_free_hook;
@@ -63,7 +65,8 @@ lp_build_init(void);
 
 
 struct gallivm_state *
-gallivm_create(const char *name, LLVMContextRef context);
+gallivm_create(const char *name, LLVMContextRef context,
+               struct lp_cached_code *cache);
 
 void
 gallivm_destroy(struct gallivm_state *gallivm);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index b079b96b6de..186965f32bb 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -304,6 +304,7 @@ extern "C"
 LLVMBool
 lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
                                         lp_generated_code **OutCode,
+                                        struct lp_cached_code *cache_out,
                                         LLVMModuleRef M,
                                         LLVMMCJITMemoryManagerRef CMM,
                                         unsigned OptLevel,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
index 363fbded728..f3be195554b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
@@ -40,6 +40,17 @@
 extern "C" {
 #endif
 
+/*
+ * some shaders use function pointers incorrectly so can't be relinked
+ * properly. (mostly the fallback fetch shaders).
+ * We should fix them, but the dont_cache flag can be set for now,
+ * so they don't end up getting cached at all.
+ */
+struct lp_cached_code {
+   void *data;
+   size_t data_size;
+   bool dont_cache;
+};
 
 struct lp_generated_code;
 
@@ -56,6 +67,7 @@ lp_set_target_options(void);
 extern int
 lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
                                         struct lp_generated_code **OutCode,
+                                        struct lp_cached_code *cache_out,
                                         LLVMModuleRef M,
                                         LLVMMCJITMemoryManagerRef MM,
                                         unsigned OptLevel,
diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c
index 97c479ef455..9270761acd6 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c
@@ -688,7 +688,7 @@ generate_variant(struct llvmpipe_context *lp,
    snprintf(module_name, sizeof(module_name), "cs%u_variant%u",
             shader->no, shader->variants_created);
 
-   variant->gallivm = gallivm_create(module_name, lp->context);
+   variant->gallivm = gallivm_create(module_name, lp->context, NULL);
    if (!variant->gallivm) {
       FREE(variant);
       return NULL;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index d7b77d51eb1..4bd201de581 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -3270,7 +3270,7 @@ generate_variant(struct llvmpipe_context *lp,
    snprintf(module_name, sizeof(module_name), "fs%u_variant%u",
             shader->no, shader->variants_created);
 
-   variant->gallivm = gallivm_create(module_name, lp->context);
+   variant->gallivm = gallivm_create(module_name, lp->context, NULL);
    if (!variant->gallivm) {
       FREE(variant);
       return NULL;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c
index 8e46013a028..a2f70681c00 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c
@@ -730,7 +730,7 @@ generate_setup_variant(struct lp_setup_variant_key *key,
    snprintf(func_name, sizeof(func_name), "setup_variant_%u",
             variant->no);
 
-   variant->gallivm = gallivm = gallivm_create(func_name, lp->context);
+   variant->gallivm = gallivm = gallivm_create(func_name, lp->context, NULL);
    if (!variant->gallivm) {
       goto fail;
    }
diff --git a/src/gallium/drivers/llvmpipe/lp_test_arit.c b/src/gallium/drivers/llvmpipe/lp_test_arit.c
index be8cb0afb48..873dcf37fac 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_arit.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_arit.c
@@ -417,7 +417,7 @@ test_unary(unsigned verbose, FILE *fp, const struct unary_test_t *test, unsigned
    }
 
    context = LLVMContextCreate();
-   gallivm = gallivm_create("test_module", context);
+   gallivm = gallivm_create("test_module", context, NULL);
 
    test_func = build_unary_test_func(gallivm, test, length, test_name);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c b/src/gallium/drivers/llvmpipe/lp_test_blend.c
index 98d6bbe50d4..a549b0a22ff 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_blend.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c
@@ -452,7 +452,7 @@ test_one(unsigned verbose,
       dump_blend_type(stdout, blend, type);
 
    context = LLVMContextCreate();
-   gallivm = gallivm_create("test_module", context);
+   gallivm = gallivm_create("test_module", context, NULL);
 
    func = add_blend_test(gallivm, blend, type);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_test_conv.c b/src/gallium/drivers/llvmpipe/lp_test_conv.c
index a4f313a0bb3..9f928973be9 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_conv.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_conv.c
@@ -221,7 +221,7 @@ test_one(unsigned verbose,
    }
 
    context = LLVMContextCreate();
-   gallivm = gallivm_create("test_module", context);
+   gallivm = gallivm_create("test_module", context, NULL);
 
    func = add_conv_test(gallivm, src_type, num_srcs, dst_type, num_dsts);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c
index 9877a219c48..f18db724bb9 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_format.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_format.c
@@ -150,7 +150,7 @@ test_format_float(unsigned verbose, FILE *fp,
    unsigned i, j, k, l;
 
    context = LLVMContextCreate();
-   gallivm = gallivm_create("test_module_float", context);
+   gallivm = gallivm_create("test_module_float", context, NULL);
 
    fetch = add_fetch_rgba_test(gallivm, verbose, desc,
                                lp_float32_vec4_type(), use_cache);
@@ -251,7 +251,7 @@ test_format_unorm8(unsigned verbose, FILE *fp,
    unsigned i, j, k, l;
 
    context = LLVMContextCreate();
-   gallivm = gallivm_create("test_module_unorm8", context);
+   gallivm = gallivm_create("test_module_unorm8", context, NULL);
 
    fetch = add_fetch_rgba_test(gallivm, verbose, desc,
                                lp_unorm8_vec4_type(), use_cache);
diff --git a/src/gallium/drivers/llvmpipe/lp_test_printf.c b/src/gallium/drivers/llvmpipe/lp_test_printf.c
index 3d3dc5838dc..85ce1cda695 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_printf.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_printf.c
@@ -96,7 +96,7 @@ test_printf(unsigned verbose, FILE *fp,
    boolean success = TRUE;
 
    context = LLVMContextCreate();
-   gallivm = gallivm_create("test_module", context);
+   gallivm = gallivm_create("test_module", context, NULL);
 
    test = add_printf_test(gallivm);
 
diff --git a/src/gallium/drivers/swr/swr_shader.cpp b/src/gallium/drivers/swr/swr_shader.cpp
index 90333536421..5f4ba348629 100644
--- a/src/gallium/drivers/swr/swr_shader.cpp
+++ b/src/gallium/drivers/swr/swr_shader.cpp
@@ -327,7 +327,7 @@ struct BuilderSWR : public Builder {
       : Builder(pJitMgr)
    {
       pJitMgr->SetupNewModule();
-      gallivm = gallivm_create(pName, wrap(&JM()->mContext));
+      gallivm = gallivm_create(pName, wrap(&JM()->mContext), NULL);
       pJitMgr->mpCurrentModule = unwrap(gallivm->module);
    }
 



More information about the mesa-commit mailing list