summaryrefslogtreecommitdiff
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2021-01-13 14:12:45 -0500
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2021-05-11 22:39:50 -0400
commit27a4ba52dba48101c22d4d86e47785bcd827a22d (patch)
tree4eddac276d6ac869f8e062c7938abd80afd66b2e /src/gallium/drivers
parent42634824f8c6ec50f19e69299bb8f820ad3787c7 (diff)
zink: unify resource rebinding
this improves handling for shader images Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10699>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/zink/zink_context.c41
-rw-r--r--src/gallium/drivers/zink/zink_resource.c30
2 files changed, 38 insertions, 33 deletions
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index c4af042af0f..34c139a1104 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -2525,11 +2525,9 @@ zink_rebind_framebuffer(struct zink_context *ctx, struct zink_resource *res)
zink_batch_no_rp(ctx);
}
-void
-zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res)
+static void
+rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
{
- assert(res->base.b.target == PIPE_BUFFER);
-
if (res->bind_history & ZINK_RESOURCE_USAGE_STREAMOUT)
ctx->dirty_so_targets = true;
/* force counter buffer reset */
@@ -2637,6 +2635,41 @@ zink_resource_commit(struct pipe_context *pctx, struct pipe_resource *pres, unsi
}
static void
+rebind_image(struct zink_context *ctx, struct zink_resource *res)
+{
+ zink_rebind_framebuffer(ctx, res);
+ for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
+ if (res->bind_history & BITFIELD_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW)) {
+ for (unsigned j = 0; j < ctx->num_sampler_views[i]; j++) {
+ struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[i][j]);
+ if (sv && sv->base.texture == &res->base.b) {
+ struct pipe_surface *psurf = &sv->image_view->base;
+ zink_rebind_surface(ctx, &psurf);
+ sv->image_view = zink_surface(psurf);
+ zink_context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW);
+ update_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, j);
+ }
+ }
+ }
+ for (unsigned j = 0; j < ctx->di.num_images[i]; j++) {
+ if (zink_resource(ctx->image_views[i][j].base.resource) == res) {
+ zink_context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_IMAGE);
+ update_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_IMAGE, j);
+ }
+ }
+ }
+}
+
+void
+zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res)
+{
+ if (res->base.b.target == PIPE_BUFFER)
+ rebind_buffer(ctx, res);
+ else
+ rebind_image(ctx, res);
+}
+
+static void
zink_context_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resource *dst, struct pipe_resource *src)
{
struct zink_resource *d = zink_resource(dst);
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index d0d9df53eb4..67e3f37e69f 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -1232,35 +1232,7 @@ zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource
zink_resource_object_reference(screen, &old_obj, NULL);
}
- if (res->bind_history & BITFIELD64_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW)) {
- for (unsigned shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
- if (res->bind_stages & (1 << shader)) {
- for (unsigned i = 0; i < ZINK_DESCRIPTOR_TYPE_IMAGE; i++) {
- if (res->bind_history & BITFIELD64_BIT(i))
- zink_context_invalidate_descriptor_state(ctx, shader, i);
- }
- }
- }
- }
- if (res->obj->is_buffer)
- zink_resource_rebind(ctx, res);
- else {
- zink_rebind_framebuffer(ctx, res);
- /* this will be cleaned up in future commits */
- if (res->bind_history & BITFIELD_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW)) {
- for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
- for (unsigned j = 0; j < ctx->num_sampler_views[i]; j++) {
- struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[i][j]);
- if (sv && sv->base.texture == &res->base.b) {
- struct pipe_surface *psurf = &sv->image_view->base;
- zink_rebind_surface(ctx, &psurf);
- sv->image_view = zink_surface(psurf);
- zink_context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW);
- }
- }
- }
- }
- }
+ zink_resource_rebind(ctx, res);
return true;
}