freedreno: Move the ir3 linked shader cache to the context.

The other ir3 backends would love to have it to reduce lookups and to be
able to cache linked-program state.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9698>
This commit is contained in:
Eric Anholt 2021-03-18 12:01:05 -07:00 committed by Marge Bot
parent cd1d8b4371
commit 6941cd5c98
8 changed files with 22 additions and 42 deletions

View File

@ -60,8 +60,6 @@ fd6_context_destroy(struct pipe_context *pctx)
fd_context_cleanup_common_vbos(&fd6_ctx->base);
ir3_cache_destroy(fd6_ctx->shader_cache);
fd6_texture_fini(pctx);
free(fd6_ctx);

View File

@ -79,11 +79,6 @@ struct fd6_context {
/* number of active samples-passed queries: */
int samples_passed_queries;
/* maps per-shader-stage state plus variant key to hw
* program stateobj:
*/
struct ir3_cache *shader_cache;
/* cached stateobjs to avoid hashtable lookup when not dirty: */
const struct fd6_program_state *prog;

View File

@ -118,9 +118,8 @@ static inline const struct fd6_program_state *
fd6_emit_get_prog(struct fd6_emit *emit)
{
if (!emit->prog) {
struct fd6_context *fd6_ctx = fd6_context(emit->ctx);
struct ir3_program_state *s =
ir3_cache_lookup(fd6_ctx->shader_cache, &emit->key, &emit->ctx->debug);
ir3_cache_lookup(emit->ctx->shader_cache, &emit->key, &emit->ctx->debug);
emit->prog = fd6_program_state(s);
}
return emit->prog;

View File

@ -1119,44 +1119,14 @@ static const struct ir3_cache_funcs cache_funcs = {
.destroy_state = fd6_program_destroy,
};
static void *
fd6_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso)
{
return ir3_shader_state_create(pctx, cso);
}
static void
fd6_shader_state_delete(struct pipe_context *pctx, void *hwcso)
{
struct fd_context *ctx = fd_context(pctx);
ir3_cache_invalidate(fd6_context(ctx)->shader_cache, hwcso);
ir3_shader_state_delete(pctx, hwcso);
}
void
fd6_prog_init(struct pipe_context *pctx)
{
struct fd_context *ctx = fd_context(pctx);
fd6_context(ctx)->shader_cache = ir3_cache_create(&cache_funcs, ctx);
ctx->shader_cache = ir3_cache_create(&cache_funcs, ctx);
pctx->create_vs_state = fd6_shader_state_create;
pctx->delete_vs_state = fd6_shader_state_delete;
pctx->create_tcs_state = fd6_shader_state_create;
pctx->delete_tcs_state = fd6_shader_state_delete;
pctx->create_tes_state = fd6_shader_state_create;
pctx->delete_tes_state = fd6_shader_state_delete;
pctx->create_gs_state = fd6_shader_state_create;
pctx->delete_gs_state = fd6_shader_state_delete;
pctx->create_gs_state = fd6_shader_state_create;
pctx->delete_gs_state = fd6_shader_state_delete;
pctx->create_fs_state = fd6_shader_state_create;
pctx->delete_fs_state = fd6_shader_state_delete;
ir3_prog_init(pctx);
fd_prog_init(pctx);
}

View File

@ -36,6 +36,7 @@
#include "freedreno_query.h"
#include "freedreno_query_hw.h"
#include "freedreno_util.h"
#include "ir3/ir3_cache.h"
#include "util/u_upload_mgr.h"
static void
@ -373,6 +374,8 @@ fd_context_destroy(struct pipe_context *pctx)
fd_autotune_fini(&ctx->autotune);
ir3_cache_destroy(ctx->shader_cache);
if (FD_DBG(BSTAT) || FD_DBG(MSGS)) {
mesa_logi("batch_total=%u, batch_sysmem=%u, batch_gmem=%u, batch_nondraw=%u, batch_restore=%u\n",
(uint32_t)ctx->stats.batch_total, (uint32_t)ctx->stats.batch_sysmem,

View File

@ -416,6 +416,11 @@ struct fd_context {
uint32_t per_fiber_size;
} pvtmem[2] dt;
/* maps per-shader-stage state plus variant key to hw
* program stateobj:
*/
struct ir3_cache *shader_cache;
struct pipe_debug_callback debug;
struct u_trace_context trace_context dt;

View File

@ -73,6 +73,9 @@ struct ir3_cache * ir3_cache_create(const struct ir3_cache_funcs *funcs, void *d
void ir3_cache_destroy(struct ir3_cache *cache)
{
if (!cache)
return;
/* _mesa_hash_table_destroy is so *almost* useful.. */
hash_table_foreach(cache->ht, entry) {
cache->funcs->destroy_state(cache->data, entry->data);
@ -167,6 +170,9 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct ir3_cache_key *key,
*/
void ir3_cache_invalidate(struct ir3_cache *cache, void *stobj)
{
if (!cache)
return;
hash_table_foreach(cache->ht, entry) {
const struct ir3_cache_key *key = entry->key;
if ((key->fs == stobj) || (key->vs == stobj) ||

View File

@ -38,6 +38,7 @@
#include "freedreno_context.h"
#include "freedreno_util.h"
#include "ir3/ir3_cache.h"
#include "ir3/ir3_shader.h"
#include "ir3/ir3_gallium.h"
#include "ir3/ir3_compiler.h"
@ -389,10 +390,13 @@ ir3_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_stat
void
ir3_shader_state_delete(struct pipe_context *pctx, void *_hwcso)
{
struct fd_screen *screen = fd_context(pctx)->screen;
struct fd_context *ctx = fd_context(pctx);
struct fd_screen *screen = ctx->screen;
struct ir3_shader_state *hwcso = _hwcso;
struct ir3_shader *so = hwcso->shader;
ir3_cache_invalidate(ctx->shader_cache, hwcso);
/* util_queue_drop_job() guarantees that either:
* 1) job did not execute
* 2) job completed