summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2021-03-28 12:50:05 -0400
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2021-06-15 20:15:58 -0400
commit4487825f0b426426690074b1d67a580e842fe400 (patch)
treed65442f498ed2316f084f8e517d35e2cbf004270
parentff692d042bb8267ffbbdbbf2501f8f452475754a (diff)
zink: move samplerview descset refs to base objects
this further extends the lifetimes for sets Reviewed-by: Hoe Hao Cheng <haochengho12907@gmail.com> Acked-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11188>
-rw-r--r--src/gallium/drivers/zink/zink_context.c13
-rw-r--r--src/gallium/drivers/zink/zink_context.h1
-rw-r--r--src/gallium/drivers/zink/zink_descriptors.c43
3 files changed, 22 insertions, 35 deletions
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index bc53d280235..e60703d6b30 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -727,7 +727,6 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres,
FREE(sampler_view);
return NULL;
}
- util_dynarray_init(&sampler_view->desc_set_refs.refs, NULL);
return &sampler_view->base;
}
@@ -749,7 +748,6 @@ zink_sampler_view_destroy(struct pipe_context *pctx,
struct pipe_sampler_view *pview)
{
struct zink_sampler_view *view = zink_sampler_view(pview);
- zink_descriptor_set_refs_clear(&view->desc_set_refs, view);
if (pview->texture->target == PIPE_BUFFER)
zink_buffer_view_reference(zink_screen(pctx->screen), &view->buffer_view, NULL);
else {
@@ -1259,13 +1257,6 @@ zink_set_shader_images(struct pipe_context *pctx,
}
static void
-sampler_view_buffer_clear(struct zink_context *ctx, struct zink_sampler_view *sampler_view)
-{
- zink_descriptor_set_refs_clear(&sampler_view->desc_set_refs, sampler_view);
- zink_buffer_view_reference(zink_screen(ctx->base.screen), &sampler_view->buffer_view, NULL);
-}
-
-static void
unbind_samplerview(struct zink_context *ctx, enum pipe_shader_type stage, unsigned slot)
{
struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[stage][slot]);
@@ -1305,7 +1296,7 @@ zink_set_sampler_views(struct pipe_context *pctx,
if (buffer_view == b->buffer_view)
p_atomic_dec(&buffer_view->reference.count);
else {
- sampler_view_buffer_clear(ctx, b);
+ zink_buffer_view_reference(zink_screen(ctx->base.screen), &b->buffer_view, NULL);
b->buffer_view = buffer_view;
update = true;
}
@@ -3042,7 +3033,7 @@ check_and_rebind_buffer(struct zink_context *ctx, struct zink_resource *res, uns
}
case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW: {
struct zink_sampler_view *sampler_view = zink_sampler_view(ctx->sampler_views[shader][i]);
- sampler_view_buffer_clear(ctx, sampler_view);
+ zink_buffer_view_reference(zink_screen(ctx->base.screen), &sampler_view->buffer_view, NULL);
sampler_view->buffer_view = get_buffer_view(ctx, res, sampler_view->base.format,
sampler_view->base.u.buf.offset, sampler_view->base.u.buf.size);
break;
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index db132c72e1b..43e41adf3f4 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -83,7 +83,6 @@ struct zink_buffer_view {
struct zink_sampler_view {
struct pipe_sampler_view base;
- struct zink_descriptor_refs desc_set_refs;
union {
struct zink_surface *image_view;
struct zink_buffer_view *buffer_view;
diff --git a/src/gallium/drivers/zink/zink_descriptors.c b/src/gallium/drivers/zink/zink_descriptors.c
index 6f59a4085a6..fe80d640d53 100644
--- a/src/gallium/drivers/zink/zink_descriptors.c
+++ b/src/gallium/drivers/zink/zink_descriptors.c
@@ -67,9 +67,8 @@ struct zink_descriptor_set {
#endif
union {
struct zink_resource_object **res_objs;
- struct zink_descriptor_surface *surfaces;
struct {
- struct zink_sampler_view **sampler_views;
+ struct zink_descriptor_surface *surfaces;
struct zink_sampler_state **sampler_states;
};
};
@@ -219,9 +218,15 @@ descriptor_set_invalidate(struct zink_descriptor_set *zds)
}
break;
case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:
- if (zds->sampler_views[i])
- pop_desc_set_ref(zds, &zds->sampler_views[i]->desc_set_refs.refs);
- zds->sampler_views[i] = NULL;
+ if (zds->surfaces[i].is_buffer) {
+ if (zds->surfaces[i].bufferview)
+ pop_desc_set_ref(zds, &zds->surfaces[i].bufferview->desc_set_refs.refs);
+ zds->surfaces[i].bufferview = NULL;
+ } else {
+ if (zds->surfaces[i].surface)
+ pop_desc_set_ref(zds, &zds->surfaces[i].surface->desc_set_refs.refs);
+ zds->surfaces[i].surface = NULL;
+ }
if (zds->sampler_states[i])
pop_desc_set_ref(zds, &zds->sampler_states[i]->desc_set_refs.refs);
zds->sampler_states[i] = NULL;
@@ -597,14 +602,14 @@ allocate_desc_set(struct zink_context *ctx, struct zink_program *pg, enum zink_d
void **samplers = NULL;
struct zink_descriptor_surface *surfaces = NULL;
switch (type) {
- case ZINK_DESCRIPTOR_TYPE_IMAGE:
- surfaces = rzalloc_array(pool, struct zink_descriptor_surface, num_resources * bucket_size);
- assert(surfaces);
- break;
case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:
samplers = rzalloc_array(pool, void*, num_resources * bucket_size);
assert(samplers);
FALLTHROUGH;
+ case ZINK_DESCRIPTOR_TYPE_IMAGE:
+ surfaces = rzalloc_array(pool, struct zink_descriptor_surface, num_resources * bucket_size);
+ assert(surfaces);
+ break;
default:
res_objs = rzalloc_array(pool, struct zink_resource_object*, num_resources * bucket_size);
assert(res_objs);
@@ -623,9 +628,8 @@ allocate_desc_set(struct zink_context *ctx, struct zink_program *pg, enum zink_d
#endif
switch (type) {
case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:
- zds->sampler_views = (struct zink_sampler_view**)&res_objs[i * pool->key.layout->num_descriptors];
zds->sampler_states = (struct zink_sampler_state**)&samplers[i * pool->key.layout->num_descriptors];
- break;
+ FALLTHROUGH;
case ZINK_DESCRIPTOR_TYPE_IMAGE:
zds->surfaces = &surfaces[i * pool->key.layout->num_descriptors];
break;
@@ -873,12 +877,6 @@ zink_sampler_state_desc_set_add(struct zink_sampler_state *sampler_state, struct
}
static void
-zink_sampler_view_desc_set_add(struct zink_sampler_view *sampler_view, struct zink_descriptor_set *zds, unsigned idx)
-{
- desc_set_ref_add(zds, &sampler_view->desc_set_refs, (void**)&zds->sampler_views[idx], sampler_view);
-}
-
-static void
zink_resource_desc_set_add(struct zink_resource *res, struct zink_descriptor_set *zds, unsigned idx)
{
desc_set_ref_add(zds, res ? &res->obj->desc_set_refs : NULL, (void**)&zds->res_objs[idx], res ? res->obj : NULL);
@@ -1001,7 +999,7 @@ desc_set_res_add(struct zink_descriptor_set *zds, struct zink_resource *res, uns
}
static void
-desc_set_sampler_add(struct zink_context *ctx, struct zink_descriptor_set *zds, struct zink_sampler_view *sv,
+desc_set_sampler_add(struct zink_context *ctx, struct zink_descriptor_set *zds, struct zink_descriptor_surface *dsurf,
struct zink_sampler_state *state, unsigned int i, bool is_buffer, bool cache_hit)
{
/* if we got a cache hit, we have to verify that the cached set is still valid;
@@ -1010,13 +1008,13 @@ desc_set_sampler_add(struct zink_context *ctx, struct zink_descriptor_set *zds,
* whenever a resource is destroyed
*/
#ifndef NDEBUG
- uint32_t cur_hash = zink_get_sampler_view_hash(ctx, zds->sampler_views[i], is_buffer);
- uint32_t new_hash = zink_get_sampler_view_hash(ctx, sv, is_buffer);
+ uint32_t cur_hash = get_descriptor_surface_hash(ctx, &zds->surfaces[i]);
+ uint32_t new_hash = get_descriptor_surface_hash(ctx, dsurf);
#endif
assert(!cache_hit || cur_hash == new_hash);
assert(!cache_hit || zds->sampler_states[i] == state);
if (!cache_hit) {
- zink_sampler_view_desc_set_add(sv, zds, i);
+ zink_descriptor_surface_desc_set_add(dsurf, zds, i);
zink_sampler_state_desc_set_add(state, zds, i);
}
}
@@ -1158,12 +1156,11 @@ update_descriptors_internal(struct zink_context *ctx, struct zink_descriptor_set
for (unsigned k = 0; k < shader->bindings[h][j].size; k++) {
assert(num_resources < num_bindings);
if (h == ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW) {
- struct zink_sampler_view *sampler_view = zink_sampler_view(ctx->sampler_views[stage][index + k]);
struct zink_sampler_state *sampler = NULL;
if (!is_buffer && image_info->imageView)
sampler = ctx->sampler_states[stage][index + k];;
- desc_set_sampler_add(ctx, zds[h], sampler_view, sampler, num_resources++, is_buffer, cache_hit[h]);
+ desc_set_sampler_add(ctx, zds[h], &ctx->di.sampler_surfaces[stage][index + k], sampler, num_resources++, is_buffer, cache_hit[h]);
} else {
struct zink_image_view *image_view = &ctx->image_views[stage][index + k];
desc_set_image_add(ctx, zds[h], image_view, num_resources++, is_buffer, cache_hit[h]);