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;
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;
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);
}
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.
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.
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)
{
#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"
* 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;
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
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);
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;
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;
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,
}
}
+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;