vkr: unbind resources on detach

A resource can be bound to the encoder or to a ring.  We must unbind on
resource detach.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent c1fee683ec
commit b98518c296
  1. 24
      src/venus/vkr_context.c
  2. 9
      src/venus/vkr_cs.c
  3. 2
      src/venus/vkr_ring.c
  4. 1
      src/venus/vkr_transport.c

@ -528,6 +528,30 @@ vkr_context_detach_resource(struct virgl_context *base, struct virgl_resource *r
struct vkr_context *ctx = (struct vkr_context *)base; struct vkr_context *ctx = (struct vkr_context *)base;
mtx_lock(&ctx->mutex); mtx_lock(&ctx->mutex);
const struct vkr_resource_attachment *att = ctx->encoder.stream.attachment;
if (att && att->resource == res) {
/* TODO vkSetReplyCommandStreamMESA should support res_id 0 to unset.
* Until then, and until we can ignore older guests, treat this as
* non-fatal
*/
vkr_cs_encoder_set_stream(&ctx->encoder, NULL, 0, 0);
}
struct vkr_ring *ring, *ring_tmp;
LIST_FOR_EACH_ENTRY_SAFE (ring, ring_tmp, &ctx->rings, head) {
if (ring->attachment->resource != res)
continue;
vkr_cs_decoder_set_fatal(&ctx->decoder);
mtx_unlock(&ctx->mutex);
vkr_ring_stop(ring);
mtx_lock(&ctx->mutex);
vkr_ring_destroy(ring);
}
vkr_context_remove_resource(ctx, res->res_id); vkr_context_remove_resource(ctx, res->res_id);
mtx_unlock(&ctx->mutex); mtx_unlock(&ctx->mutex);
} }

@ -15,6 +15,15 @@ vkr_cs_encoder_set_stream(struct vkr_cs_encoder *enc,
size_t offset, size_t offset,
size_t size) size_t size)
{ {
if (!att) {
memset(&enc->stream, 0, sizeof(enc->stream));
enc->remaining_size = 0;
enc->next_iov = 0;
enc->cur = NULL;
enc->end = NULL;
return;
}
enc->stream.attachment = att; enc->stream.attachment = att;
enc->stream.iov = att->iov; enc->stream.iov = att->iov;
enc->stream.iov_count = att->iov_count; enc->stream.iov_count = att->iov_count;

@ -232,6 +232,8 @@ vkr_ring_create(const struct vkr_ring_layout *layout,
void void
vkr_ring_destroy(struct vkr_ring *ring) vkr_ring_destroy(struct vkr_ring *ring)
{ {
list_del(&ring->head);
assert(!ring->started); assert(!ring->started);
mtx_destroy(&ring->mutex); mtx_destroy(&ring->mutex);
cnd_destroy(&ring->cond); cnd_destroy(&ring->cond);

@ -268,7 +268,6 @@ vkr_dispatch_vkDestroyRingMESA(struct vn_dispatch_context *dispatch,
return; return;
} }
list_del(&ring->head);
vkr_ring_destroy(ring); vkr_ring_destroy(ring);
} }

Loading…
Cancel
Save