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: f675e4ee82 ("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 c2f79d7fb1)
This commit is contained in:
Dave Airlie
2023-10-10 16:41:21 +10:00
committed by Eric Engestrom
parent 4ea8f20b19
commit 955d7b3fa3
2 changed files with 10 additions and 5 deletions

View File

@@ -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

View 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