etnaviv: Make contexts track resources
Currently, the screen tracks all resources for all contexts, but this is not correct. Each context should track the resources it uses. This also allows a context to detect whether a resource is used by another context and to notify another context using a resource that the current context is done using the resource. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Christian Gmeiner <christian.gmeiner@gmail.com> Cc: Guido Günther <guido.gunther@puri.sm> Cc: Lucas Stach <l.stach@pengutronix.de>
This commit is contained in:
parent
2946bd6628
commit
90e223646b
|
@ -48,6 +48,7 @@
|
|||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_state.h"
|
||||
#include "util/hash_table.h"
|
||||
#include "util/u_blitter.h"
|
||||
#include "util/u_helpers.h"
|
||||
#include "util/u_memory.h"
|
||||
|
@ -60,6 +61,25 @@ static void
|
|||
etna_context_destroy(struct pipe_context *pctx)
|
||||
{
|
||||
struct etna_context *ctx = etna_context(pctx);
|
||||
struct etna_screen *screen = ctx->screen;
|
||||
|
||||
if (ctx->used_resources) {
|
||||
mtx_lock(&screen->lock);
|
||||
|
||||
/*
|
||||
* There should be no resources tracked in the context when it's being
|
||||
* destroyed. Be sure there are none to avoid memory leaks on buggy
|
||||
* programs.
|
||||
*/
|
||||
set_foreach(ctx->used_resources, entry) {
|
||||
struct etna_resource *rsc = (struct etna_resource *)entry->key;
|
||||
|
||||
_mesa_set_remove_key(rsc->pending_ctx, ctx);
|
||||
}
|
||||
_mesa_set_destroy(ctx->used_resources, NULL);
|
||||
|
||||
mtx_unlock(&screen->lock);
|
||||
}
|
||||
|
||||
if (ctx->dummy_rt)
|
||||
etna_bo_del(ctx->dummy_rt);
|
||||
|
@ -399,16 +419,18 @@ etna_cmd_stream_reset_notify(struct etna_cmd_stream *stream, void *priv)
|
|||
ctx->dirty_sampler_views = ~0L;
|
||||
|
||||
/*
|
||||
* Go through all _resources_ associated with this _screen_, pending
|
||||
* in this _context_ and mark them as not pending in this _context_
|
||||
* anymore, since they were just flushed.
|
||||
* Go through all _resources_ pending in this _context_ and mark them as
|
||||
* not pending in this _context_ anymore, since they were just flushed.
|
||||
*/
|
||||
mtx_lock(&screen->lock);
|
||||
set_foreach(screen->used_resources, entry) {
|
||||
set_foreach(ctx->used_resources, entry) {
|
||||
struct etna_resource *rsc = (struct etna_resource *)entry->key;
|
||||
|
||||
rsc->status = 0;
|
||||
|
||||
_mesa_set_remove_key(rsc->pending_ctx, ctx);
|
||||
}
|
||||
_mesa_set_clear(ctx->used_resources, NULL);
|
||||
mtx_unlock(&screen->lock);
|
||||
}
|
||||
|
||||
|
@ -447,6 +469,11 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
|
|||
if (ctx->stream == NULL)
|
||||
goto fail;
|
||||
|
||||
ctx->used_resources = _mesa_set_create(NULL, _mesa_hash_pointer,
|
||||
_mesa_key_pointer_equal);
|
||||
if (!ctx->used_resources)
|
||||
goto fail;
|
||||
|
||||
/* context ctxate setup */
|
||||
ctx->specs = screen->specs;
|
||||
ctx->screen = screen;
|
||||
|
|
|
@ -190,6 +190,9 @@ struct etna_context {
|
|||
|
||||
struct etna_bo *dummy_rt;
|
||||
struct etna_reloc dummy_rt_reloc;
|
||||
|
||||
/* set of resources used by currently-unsubmitted renders */
|
||||
struct set *used_resources;
|
||||
};
|
||||
|
||||
static inline struct etna_context *
|
||||
|
|
|
@ -468,7 +468,11 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
|
|||
struct etna_resource *rsc = etna_resource(prsc);
|
||||
|
||||
mtx_lock(&screen->lock);
|
||||
_mesa_set_remove_key(screen->used_resources, rsc);
|
||||
set_foreach(rsc->pending_ctx, entry) {
|
||||
struct etna_context *ctx = (struct etna_context *)entry->key;
|
||||
|
||||
_mesa_set_remove_key(rsc->pending_ctx, ctx);
|
||||
}
|
||||
_mesa_set_destroy(rsc->pending_ctx, NULL);
|
||||
mtx_unlock(&screen->lock);
|
||||
|
||||
|
@ -650,7 +654,7 @@ etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc,
|
|||
|
||||
rsc->status |= status;
|
||||
|
||||
_mesa_set_add(screen->used_resources, rsc);
|
||||
_mesa_set_add(ctx->used_resources, rsc);
|
||||
_mesa_set_add(rsc->pending_ctx, ctx);
|
||||
|
||||
mtx_unlock(&screen->lock);
|
||||
|
|
|
@ -84,7 +84,6 @@ etna_screen_destroy(struct pipe_screen *pscreen)
|
|||
{
|
||||
struct etna_screen *screen = etna_screen(pscreen);
|
||||
|
||||
_mesa_set_destroy(screen->used_resources, NULL);
|
||||
mtx_destroy(&screen->lock);
|
||||
|
||||
if (screen->perfmon)
|
||||
|
@ -958,15 +957,9 @@ etna_screen_create(struct etna_device *dev, struct etna_gpu *gpu,
|
|||
etna_pm_query_setup(screen);
|
||||
|
||||
mtx_init(&screen->lock, mtx_recursive);
|
||||
screen->used_resources = _mesa_set_create(NULL, _mesa_hash_pointer,
|
||||
_mesa_key_pointer_equal);
|
||||
if (!screen->used_resources)
|
||||
goto fail2;
|
||||
|
||||
return pscreen;
|
||||
|
||||
fail2:
|
||||
mtx_destroy(&screen->lock);
|
||||
fail:
|
||||
etna_screen_destroy(pscreen);
|
||||
return NULL;
|
||||
|
|
|
@ -85,9 +85,7 @@ struct etna_screen {
|
|||
|
||||
uint32_t drm_version;
|
||||
|
||||
/* set of resources used by currently-unsubmitted renders */
|
||||
mtx_t lock;
|
||||
struct set *used_resources;
|
||||
|
||||
nir_shader_compiler_options options;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue