mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
aux/trace: move trace_sample_view logic
it's defined in tr_texture, so it makes sense and is more re-usable to have it's logic there. Also documented the magic number used for private refcounting Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24482>
This commit is contained in:
parent
9ff20e23fe
commit
713437b2fc
3 changed files with 58 additions and 27 deletions
|
|
@ -1096,7 +1096,6 @@ trace_context_create_sampler_view(struct pipe_context *_pipe,
|
|||
struct trace_context *tr_ctx = trace_context(_pipe);
|
||||
struct pipe_context *pipe = tr_ctx->pipe;
|
||||
struct pipe_sampler_view *result;
|
||||
struct trace_sampler_view *tr_view;
|
||||
|
||||
trace_dump_call_begin("pipe_context", "create_sampler_view");
|
||||
|
||||
|
|
@ -1113,19 +1112,7 @@ trace_context_create_sampler_view(struct pipe_context *_pipe,
|
|||
|
||||
trace_dump_call_end();
|
||||
|
||||
/*
|
||||
* Wrap pipe_sampler_view
|
||||
*/
|
||||
tr_view = CALLOC_STRUCT(trace_sampler_view);
|
||||
tr_view->base = *templ;
|
||||
tr_view->base.reference.count = 1;
|
||||
tr_view->base.texture = NULL;
|
||||
pipe_resource_reference(&tr_view->base.texture, resource);
|
||||
tr_view->base.context = _pipe;
|
||||
tr_view->sampler_view = result;
|
||||
result->reference.count += 100000000;
|
||||
tr_view->refcount = 100000000;
|
||||
result = &tr_view->base;
|
||||
result = trace_sampler_view_create(tr_ctx, resource, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1145,13 +1132,9 @@ trace_context_sampler_view_destroy(struct pipe_context *_pipe,
|
|||
trace_dump_arg(ptr, pipe);
|
||||
trace_dump_arg(ptr, view);
|
||||
|
||||
p_atomic_add(&tr_view->sampler_view->reference.count, -tr_view->refcount);
|
||||
pipe_sampler_view_reference(&tr_view->sampler_view, NULL);
|
||||
trace_sampler_view_destroy(tr_view);
|
||||
|
||||
trace_dump_call_end();
|
||||
|
||||
pipe_resource_reference(&_view->texture, NULL);
|
||||
FREE(_view);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
|
|
@ -1230,14 +1213,7 @@ trace_context_set_sampler_views(struct pipe_context *_pipe,
|
|||
|
||||
for (i = 0; i < num; ++i) {
|
||||
tr_view = trace_sampler_view(views[i]);
|
||||
if (tr_view) {
|
||||
tr_view->refcount--;
|
||||
if (!tr_view->refcount) {
|
||||
tr_view->refcount = 100000000;
|
||||
p_atomic_add(&tr_view->sampler_view->reference.count, tr_view->refcount);
|
||||
}
|
||||
}
|
||||
unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL;
|
||||
unwrapped_views[i] = trace_sampler_view_unwrap(tr_view);
|
||||
}
|
||||
views = unwrapped_views;
|
||||
|
||||
|
|
|
|||
|
|
@ -116,3 +116,48 @@ trace_transfer_destroy(struct trace_context *tr_context,
|
|||
FREE(tr_trans);
|
||||
}
|
||||
|
||||
/* Arbitrarily large refcount to "avoid having the driver bypass the samplerview wrapper and destroying
|
||||
the samplerview prematurely" see 7f5a3530125 ("aux/trace: use private refcounts for samplerviews") */
|
||||
#define SAMPLER_VIEW_PRIVATE_REFCOUNT 100000000
|
||||
|
||||
struct pipe_sampler_view *
|
||||
trace_sampler_view_create(struct trace_context *tr_ctx,
|
||||
struct pipe_resource *tr_res,
|
||||
struct pipe_sampler_view *view)
|
||||
{
|
||||
assert(tr_res == view->texture);
|
||||
struct trace_sampler_view *tr_view = CALLOC_STRUCT(trace_sampler_view);
|
||||
memcpy(&tr_view->base, view, sizeof(struct pipe_sampler_view));
|
||||
tr_view->base.reference.count = 1;
|
||||
tr_view->base.texture = NULL;
|
||||
pipe_resource_reference(&tr_view->base.texture, tr_res);
|
||||
tr_view->base.context = &tr_ctx->base;
|
||||
tr_view->sampler_view = view;
|
||||
view->reference.count += SAMPLER_VIEW_PRIVATE_REFCOUNT;
|
||||
tr_view->refcount = SAMPLER_VIEW_PRIVATE_REFCOUNT;
|
||||
return &tr_view->base;
|
||||
}
|
||||
|
||||
void
|
||||
trace_sampler_view_destroy(struct trace_sampler_view *tr_view)
|
||||
{
|
||||
p_atomic_add(&tr_view->sampler_view->reference.count, -tr_view->refcount);
|
||||
pipe_sampler_view_reference(&tr_view->sampler_view, NULL);
|
||||
pipe_resource_reference(&tr_view->base.texture, NULL);
|
||||
FREE(tr_view);
|
||||
}
|
||||
|
||||
struct pipe_sampler_view *
|
||||
trace_sampler_view_unwrap(struct trace_sampler_view *tr_view)
|
||||
{
|
||||
if (!tr_view)
|
||||
return NULL;
|
||||
tr_view->refcount--;
|
||||
if (!tr_view->refcount) {
|
||||
tr_view->refcount = SAMPLER_VIEW_PRIVATE_REFCOUNT;
|
||||
p_atomic_add(&tr_view->sampler_view->reference.count, tr_view->refcount);
|
||||
}
|
||||
return tr_view->sampler_view;
|
||||
}
|
||||
|
||||
#undef SAMPLER_VIEW_PRIVATE_REFCOUNT
|
||||
|
|
|
|||
|
|
@ -120,5 +120,15 @@ void
|
|||
trace_transfer_destroy(struct trace_context *tr_ctx,
|
||||
struct trace_transfer *tr_trans);
|
||||
|
||||
struct pipe_sampler_view *
|
||||
trace_sampler_view_create(struct trace_context *tr_ctx,
|
||||
struct pipe_resource *tr_res,
|
||||
struct pipe_sampler_view *sampler_view);
|
||||
|
||||
void
|
||||
trace_sampler_view_destroy(struct trace_sampler_view *tr_view);
|
||||
|
||||
struct pipe_sampler_view *
|
||||
trace_sampler_view_unwrap(struct trace_sampler_view *tr_view);
|
||||
|
||||
#endif /* TR_TEXTURE_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue