llvmpipe: fix caching for texture shaders.
authorDave Airlie <airlied@redhat.com>
Tue, 10 Oct 2023 06:41:21 +0000 (16:41 +1000)
committerEric Engestrom <eric@engestrom.ch>
Thu, 4 Jan 2024 18:36:07 +0000 (18:36 +0000)
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.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25648>
(cherry picked from commit c2f79d7fb1c3c4931bee8171750a67d867366fda)

.pick_status.json
src/gallium/drivers/llvmpipe/lp_texture_handle.c

index bf94bcb..93c694c 100644 (file)
         "description": "llvmpipe: fix caching for texture shaders.",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "f675e4ee82319db31a9a70d65063290e4f151b4f",
         "notes": null
index ff69fa0..179b429 100644 (file)
@@ -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