virgl: Add simple disk cache

Since virgl has no backend compilation, this is just a disk cache for the
frontend. As such it is very simple and only implements enough for
get_disk_shader_cache() to work.

With portal2 apitrace:
Before: 100.65 fps
After: 129.051 fps

Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10200>
This commit is contained in:
Stéphane Marchesin 2021-04-13 06:26:26 +02:00 committed by Marge Bot
parent a86450e00a
commit d6db4d2e08
2 changed files with 30 additions and 0 deletions

View File

@ -824,6 +824,9 @@ virgl_destroy_screen(struct pipe_screen *screen)
if (vws)
vws->destroy(vws);
disk_cache_destroy(vscreen->disk_cache);
FREE(vscreen);
}
@ -881,6 +884,28 @@ static void virgl_query_memory_info(struct pipe_screen *screen, struct pipe_memo
ctx->destroy(ctx);
}
static struct disk_cache *virgl_get_disk_shader_cache (struct pipe_screen *pscreen)
{
struct virgl_screen *screen = virgl_screen(pscreen);
return screen->disk_cache;
}
static void virgl_disk_cache_create(struct virgl_screen *screen)
{
const struct build_id_note *note =
build_id_find_nhdr_for_addr(virgl_disk_cache_create);
assert(note && build_id_length(note) == 20); /* sha1 */
const uint8_t *id_sha1 = build_id_data(note);
assert(id_sha1);
char timestamp[41];
_mesa_sha1_format(timestamp, id_sha1);
screen->disk_cache = disk_cache_create("virgl", timestamp, 0);
}
struct pipe_screen *
virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *config)
{
@ -923,6 +948,7 @@ virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *c
screen->base.fence_finish = virgl_fence_finish;
screen->base.fence_get_fd = virgl_fence_get_fd;
screen->base.query_memory_info = virgl_query_memory_info;
screen->base.get_disk_shader_cache = virgl_get_disk_shader_cache;
virgl_init_screen_resource_functions(&screen->base);
@ -937,5 +963,6 @@ virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *c
slab_create_parent(&screen->transfer_pool, sizeof(struct virgl_transfer), 16);
virgl_disk_cache_create(screen);
return &screen->base;
}

View File

@ -25,6 +25,7 @@
#include "pipe/p_screen.h"
#include "util/slab.h"
#include "util/disk_cache.h"
#include "virgl_winsys.h"
enum virgl_debug_flags {
@ -56,6 +57,8 @@ struct virgl_screen {
bool tweak_gles_emulate_bgra;
bool tweak_gles_apply_bgra_dest_swizzle;
int32_t tweak_gles_tf3_value;
struct disk_cache *disk_cache;
};