Module: Mesa
Branch: staging/23.3
Commit: 955d7b3fa36baae45e7264ab3acf371648cc094f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=955d7b3fa36baae45e7264ab3acf371648cc094f

Author: Dave Airlie <airl...@redhat.com>
Date:   Tue Oct 10 16:41:21 2023 +1000

llvmpipe: fix caching for texture shaders.

caching only works if you check the size and store the result,
later the size is always set.

Fixes: f675e4ee8231 ("llvmpipe: Pre compile sample functions")
Reviewed-by: Konstantin Seurer <konstantin.seu...@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25648>
(cherry picked from commit c2f79d7fb1c3c4931bee8171750a67d867366fda)

---

 .pick_status.json                                |  2 +-
 src/gallium/drivers/llvmpipe/lp_texture_handle.c | 13 +++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index bf94bcbc9cf..93c694c9efb 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -334,7 +334,7 @@
         "description": "llvmpipe: fix caching for texture shaders.",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "f675e4ee82319db31a9a70d65063290e4f151b4f",
         "notes": null
diff --git a/src/gallium/drivers/llvmpipe/lp_texture_handle.c 
b/src/gallium/drivers/llvmpipe/lp_texture_handle.c
index ff69fa024a5..179b429b12d 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture_handle.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture_handle.c
@@ -202,6 +202,7 @@ llvmpipe_sampler_matrix_destroy(struct llvmpipe_context 
*ctx)
 
 static void *
 compile_function(struct llvmpipe_context *ctx, struct gallivm_state *gallivm, 
LLVMValueRef function,
+                 bool needs_caching,
                  uint8_t cache_key[SHA1_DIGEST_LENGTH])
 {
    gallivm_verify_function(gallivm, function);
@@ -209,7 +210,7 @@ compile_function(struct llvmpipe_context *ctx, struct 
gallivm_state *gallivm, LL
 
    void *function_ptr = func_to_pointer(gallivm_jit_function(gallivm, 
function));
 
-   if (!gallivm->cache->data_size)
+   if (needs_caching)
       lp_disk_cache_insert_shader(llvmpipe_screen(ctx->pipe.screen), 
gallivm->cache, cache_key);
 
    gallivm_free_ir(gallivm);
@@ -251,10 +252,12 @@ compile_image_function(struct llvmpipe_context *ctx, 
struct lp_static_texture_st
    _mesa_sha1_update(&hash_ctx, image_function_base_hash, 
strlen(image_function_base_hash));
    _mesa_sha1_update(&hash_ctx, texture, sizeof(*texture));
    _mesa_sha1_update(&hash_ctx, &op, sizeof(op));
+   _mesa_sha1_update(&hash_ctx, &ms, sizeof(ms));
    _mesa_sha1_final(&hash_ctx, cache_key);
 
    struct lp_cached_code cached = { 0 };
    lp_disk_cache_find_shader(llvmpipe_screen(ctx->pipe.screen), &cached, 
cache_key);
+   bool needs_caching = !cached.data_size;
 
    struct gallivm_state *gallivm = gallivm_create("sample_function", 
ctx->context, &cached);
 
@@ -333,7 +336,7 @@ compile_image_function(struct llvmpipe_context *ctx, struct 
lp_static_texture_st
 
    free(image_soa);
 
-   return compile_function(ctx, gallivm, function, cache_key);
+   return compile_function(ctx, gallivm, function, needs_caching, cache_key);
 }
 
 static void *
@@ -407,6 +410,7 @@ compile_sample_function(struct llvmpipe_context *ctx, 
struct lp_static_texture_s
 
    struct lp_cached_code cached = { 0 };
    lp_disk_cache_find_shader(llvmpipe_screen(ctx->pipe.screen), &cached, 
cache_key);
+   bool needs_caching = !cached.data_size;
 
    struct gallivm_state *gallivm = gallivm_create("sample_function", 
ctx->context, &cached);
 
@@ -480,7 +484,7 @@ compile_sample_function(struct llvmpipe_context *ctx, 
struct lp_static_texture_s
 
    free(sampler_soa);
 
-   return compile_function(ctx, gallivm, function, cache_key);
+   return compile_function(ctx, gallivm, function, needs_caching, cache_key);
 }
 
 static void *
@@ -496,6 +500,7 @@ compile_size_function(struct llvmpipe_context *ctx, struct 
lp_static_texture_sta
 
    struct lp_cached_code cached = { 0 };
    lp_disk_cache_find_shader(llvmpipe_screen(ctx->pipe.screen), &cached, 
cache_key);
+   bool needs_caching = !cached.data_size;
 
    struct gallivm_state *gallivm = gallivm_create("sample_function", 
ctx->context, &cached);
 
@@ -560,7 +565,7 @@ compile_size_function(struct llvmpipe_context *ctx, struct 
lp_static_texture_sta
 
    free(sampler_soa);
 
-   return compile_function(ctx, gallivm, function, cache_key);
+   return compile_function(ctx, gallivm, function, needs_caching, cache_key);
 }
 
 static void

Reply via email to