radeonsi: use the live shader cache
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2929>
This commit is contained in:
@@ -213,7 +213,7 @@ static void *si_create_compute_state(
|
||||
struct si_compute *program = CALLOC_STRUCT(si_compute);
|
||||
struct si_shader_selector *sel = &program->sel;
|
||||
|
||||
pipe_reference_init(&sel->reference, 1);
|
||||
pipe_reference_init(&sel->base.reference, 1);
|
||||
sel->type = PIPE_SHADER_COMPUTE;
|
||||
sel->screen = sscreen;
|
||||
program->shader.selector = &program->sel;
|
||||
|
@@ -50,7 +50,7 @@ void si_destroy_compute(struct si_compute *program);
|
||||
static inline void
|
||||
si_compute_reference(struct si_compute **dst, struct si_compute *src)
|
||||
{
|
||||
if (pipe_reference(&(*dst)->sel.reference, &src->sel.reference))
|
||||
if (pipe_reference(&(*dst)->sel.base.reference, &src->sel.base.reference))
|
||||
si_destroy_compute(*dst);
|
||||
|
||||
*dst = src;
|
||||
|
@@ -815,6 +815,7 @@ static void si_destroy_screen(struct pipe_screen* pscreen)
|
||||
slab_destroy_parent(&sscreen->pool_transfers);
|
||||
|
||||
disk_cache_destroy(sscreen->disk_shader_cache);
|
||||
util_live_shader_cache_deinit(&sscreen->live_shader_cache);
|
||||
sscreen->ws->destroy(sscreen->ws);
|
||||
FREE(sscreen);
|
||||
}
|
||||
@@ -1002,6 +1003,7 @@ radeonsi_screen_create_impl(struct radeon_winsys *ws,
|
||||
si_init_screen_state_functions(sscreen);
|
||||
si_init_screen_texture_functions(sscreen);
|
||||
si_init_screen_query_functions(sscreen);
|
||||
si_init_screen_live_shader_cache(sscreen);
|
||||
|
||||
/* Set these flags in debug_flags early, so that the shader cache takes
|
||||
* them into account.
|
||||
|
@@ -601,6 +601,9 @@ struct si_screen {
|
||||
simple_mtx_t shader_cache_mutex;
|
||||
struct hash_table *shader_cache;
|
||||
|
||||
/* Shader cache of live shaders. */
|
||||
struct util_live_shader_cache live_shader_cache;
|
||||
|
||||
/* Shader compiler queue for multithreaded compilation. */
|
||||
struct util_queue shader_compiler_queue;
|
||||
/* Use at most 3 normal compiler threads on quadcore and better.
|
||||
@@ -1587,6 +1590,19 @@ si_texture_reference(struct si_texture **ptr, struct si_texture *res)
|
||||
pipe_resource_reference((struct pipe_resource **)ptr, &res->buffer.b.b);
|
||||
}
|
||||
|
||||
static inline void
|
||||
si_shader_selector_reference(struct si_context *sctx, /* sctx can optionally be NULL */
|
||||
struct si_shader_selector **dst,
|
||||
struct si_shader_selector *src)
|
||||
{
|
||||
if (*dst == src)
|
||||
return;
|
||||
|
||||
struct si_screen *sscreen = src ? src->screen : (*dst)->screen;
|
||||
util_shader_reference(&sctx->b, &sscreen->live_shader_cache,
|
||||
(void**)dst, src);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
vi_dcc_enabled(struct si_texture *tex, unsigned level)
|
||||
{
|
||||
|
@@ -132,6 +132,7 @@
|
||||
#define SI_SHADER_H
|
||||
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_live_shader_cache.h"
|
||||
#include "util/u_queue.h"
|
||||
#include "util/simple_mtx.h"
|
||||
|
||||
@@ -404,7 +405,7 @@ struct si_shader_info {
|
||||
* binaries for one NIR program. This can be shared by multiple contexts.
|
||||
*/
|
||||
struct si_shader_selector {
|
||||
struct pipe_reference reference;
|
||||
struct util_live_shader base;
|
||||
struct si_screen *screen;
|
||||
struct util_queue_fence ready;
|
||||
struct si_compiler_ctx_state compiler_ctx_state;
|
||||
@@ -918,18 +919,4 @@ si_shader_uses_bindless_images(struct si_shader_selector *selector)
|
||||
return selector ? selector->info.uses_bindless_images : false;
|
||||
}
|
||||
|
||||
void si_destroy_shader_selector(struct si_context *sctx,
|
||||
struct si_shader_selector *sel);
|
||||
|
||||
static inline void
|
||||
si_shader_selector_reference(struct si_context *sctx,
|
||||
struct si_shader_selector **dst,
|
||||
struct si_shader_selector *src)
|
||||
{
|
||||
if (pipe_reference(&(*dst)->reference, &src->reference))
|
||||
si_destroy_shader_selector(sctx, *dst);
|
||||
|
||||
*dst = src;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -599,6 +599,7 @@ void si_shader_cache_insert_shader(struct si_screen *sscreen,
|
||||
struct si_shader *shader,
|
||||
bool insert_into_disk_cache);
|
||||
bool si_update_shaders(struct si_context *sctx);
|
||||
void si_init_screen_live_shader_cache(struct si_screen *sscreen);
|
||||
void si_init_shader_functions(struct si_context *sctx);
|
||||
bool si_init_shader_cache(struct si_screen *sscreen);
|
||||
void si_destroy_shader_cache(struct si_screen *sscreen);
|
||||
|
@@ -2788,7 +2788,6 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
|
||||
if (!sel)
|
||||
return NULL;
|
||||
|
||||
pipe_reference_init(&sel->reference, 1);
|
||||
sel->screen = sscreen;
|
||||
sel->compiler_ctx_state.debug = sctx->debug;
|
||||
sel->compiler_ctx_state.is_debug_context = sctx->is_debug;
|
||||
@@ -3055,6 +3054,14 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
|
||||
return sel;
|
||||
}
|
||||
|
||||
static void *si_create_shader(struct pipe_context *ctx,
|
||||
const struct pipe_shader_state *state)
|
||||
{
|
||||
struct si_screen *sscreen = (struct si_screen *)ctx->screen;
|
||||
|
||||
return util_live_shader_cache_get(ctx, &sscreen->live_shader_cache, state);
|
||||
}
|
||||
|
||||
static void si_update_streamout_state(struct si_context *sctx)
|
||||
{
|
||||
struct si_shader_selector *shader_with_so = si_get_vs(sctx)->cso;
|
||||
@@ -3358,9 +3365,10 @@ static void si_delete_shader(struct si_context *sctx, struct si_shader *shader)
|
||||
free(shader);
|
||||
}
|
||||
|
||||
void si_destroy_shader_selector(struct si_context *sctx,
|
||||
struct si_shader_selector *sel)
|
||||
static void si_destroy_shader_selector(struct pipe_context *ctx, void *cso)
|
||||
{
|
||||
struct si_context *sctx = (struct si_context*)ctx;
|
||||
struct si_shader_selector *sel = (struct si_shader_selector *)cso;
|
||||
struct si_shader *p = sel->first_variant, *c;
|
||||
struct si_shader_ctx_state *current_shader[SI_NUM_SHADERS] = {
|
||||
[PIPE_SHADER_VERTEX] = &sctx->vs_shader,
|
||||
@@ -4242,16 +4250,23 @@ static void si_emit_scratch_state(struct si_context *sctx)
|
||||
}
|
||||
}
|
||||
|
||||
void si_init_screen_live_shader_cache(struct si_screen *sscreen)
|
||||
{
|
||||
util_live_shader_cache_init(&sscreen->live_shader_cache,
|
||||
si_create_shader_selector,
|
||||
si_destroy_shader_selector);
|
||||
}
|
||||
|
||||
void si_init_shader_functions(struct si_context *sctx)
|
||||
{
|
||||
sctx->atoms.s.spi_map.emit = si_emit_spi_map;
|
||||
sctx->atoms.s.scratch_state.emit = si_emit_scratch_state;
|
||||
|
||||
sctx->b.create_vs_state = si_create_shader_selector;
|
||||
sctx->b.create_tcs_state = si_create_shader_selector;
|
||||
sctx->b.create_tes_state = si_create_shader_selector;
|
||||
sctx->b.create_gs_state = si_create_shader_selector;
|
||||
sctx->b.create_fs_state = si_create_shader_selector;
|
||||
sctx->b.create_vs_state = si_create_shader;
|
||||
sctx->b.create_tcs_state = si_create_shader;
|
||||
sctx->b.create_tes_state = si_create_shader;
|
||||
sctx->b.create_gs_state = si_create_shader;
|
||||
sctx->b.create_fs_state = si_create_shader;
|
||||
|
||||
sctx->b.bind_vs_state = si_bind_vs_shader;
|
||||
sctx->b.bind_tcs_state = si_bind_tcs_shader;
|
||||
|
Reference in New Issue
Block a user