iris: Ref count the uncompiled shaders

I tried /just/ ref counting the uncompiled shaders, but that is not
sufficient.  At the very least, it's a problem for blorp shaders that
only have variants (and no uncompiled shader).

This is in prepartion for using the live shader cache.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11229>
This commit is contained in:
Ian Romanick
2021-05-25 12:41:14 -07:00
committed by Marge Bot
parent d5ec4716de
commit d0fac4e4f8
2 changed files with 52 additions and 13 deletions

View File

@@ -2282,6 +2282,7 @@ iris_create_uncompiled_shader(struct iris_screen *screen,
if (!ish)
return NULL;
pipe_reference_init(&ish->ref, 1);
list_inithead(&ish->variants);
simple_mtx_init(&ish->lock, mtx_plain);
@@ -2537,9 +2538,35 @@ iris_create_shader_state(struct pipe_context *ctx,
}
/**
* The pipe->delete_[stage]_state() driver hooks.
* Called when the refcount on the iris_uncompiled_shader reaches 0.
*
* Frees the iris_uncompiled_shader.
*
* \sa iris_delete_shader_state
*/
void
iris_destroy_shader_state(struct pipe_context *ctx, void *state)
{
struct iris_uncompiled_shader *ish = state;
/* No need to take ish->lock; we hold the last reference to ish */
list_for_each_entry_safe(struct iris_compiled_shader, shader,
&ish->variants, link) {
list_del(&shader->link);
iris_shader_variant_reference(&shader, NULL);
}
simple_mtx_destroy(&ish->lock);
ralloc_free(ish->nir);
free(ish);
}
/**
* The pipe->delete_[stage]_state() driver hooks.
*
* \sa iris_destroy_shader_state
*/
static void
iris_delete_shader_state(struct pipe_context *ctx, void *state)
@@ -2554,18 +2581,8 @@ iris_delete_shader_state(struct pipe_context *ctx, void *state)
ice->state.stage_dirty |= IRIS_STAGE_DIRTY_UNCOMPILED_VS << stage;
}
/* No need to take ish->lock; we hold the last reference to ish */
list_for_each_entry_safe(struct iris_compiled_shader, shader,
&ish->variants, link) {
list_del(&shader->link);
iris_shader_variant_reference(&shader, NULL);
}
simple_mtx_destroy(&ish->lock);
ralloc_free(ish->nir);
free(ish);
if (pipe_reference(&ish->ref, NULL))
iris_destroy_shader_state(ctx, state);
}
/**