diff --git a/src/venus/vkr_context.c b/src/venus/vkr_context.c index 8aaf068..9a82833 100644 --- a/src/venus/vkr_context.c +++ b/src/venus/vkr_context.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; 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); mtx_unlock(&ctx->mutex); } diff --git a/src/venus/vkr_cs.c b/src/venus/vkr_cs.c index 9886494..bd9b0aa 100644 --- a/src/venus/vkr_cs.c +++ b/src/venus/vkr_cs.c @@ -15,6 +15,15 @@ vkr_cs_encoder_set_stream(struct vkr_cs_encoder *enc, size_t offset, 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.iov = att->iov; enc->stream.iov_count = att->iov_count; diff --git a/src/venus/vkr_ring.c b/src/venus/vkr_ring.c index 01aa7f1..4769797 100644 --- a/src/venus/vkr_ring.c +++ b/src/venus/vkr_ring.c @@ -232,6 +232,8 @@ vkr_ring_create(const struct vkr_ring_layout *layout, void vkr_ring_destroy(struct vkr_ring *ring) { + list_del(&ring->head); + assert(!ring->started); mtx_destroy(&ring->mutex); cnd_destroy(&ring->cond); diff --git a/src/venus/vkr_transport.c b/src/venus/vkr_transport.c index 0b8e2b0..ab7f31d 100644 --- a/src/venus/vkr_transport.c +++ b/src/venus/vkr_transport.c @@ -268,7 +268,6 @@ vkr_dispatch_vkDestroyRingMESA(struct vn_dispatch_context *dispatch, return; } - list_del(&ring->head); vkr_ring_destroy(ring); }