vkr: destroy vkr_instance at vkr_context_destroy

Also adjust to destroy vkr_physical_device first.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Yiwei Zhang 3 years ago
parent f46f128278
commit 122625e79c
  1. 50
      src/vkr_renderer.c

@ -1047,25 +1047,8 @@ vkr_dispatch_vkCreateInstance(struct vn_dispatch_context *dispatch,
}
static void
vkr_dispatch_vkDestroyInstance(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroyInstance *args)
vkr_instance_destroy(struct vkr_context *ctx, struct vkr_instance *instance)
{
struct vkr_context *ctx = dispatch->data;
struct vkr_instance *instance = (struct vkr_instance *)args->instance;
if (ctx->instance != instance) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
if (ctx->validate_level != VKR_CONTEXT_VALIDATE_NONE) {
instance->destroy_debug_utils_messenger(instance->base.handle.instance,
instance->validation_messenger, NULL);
}
vn_replace_vkDestroyInstance_args_handle(args);
vkDestroyInstance(args->instance, NULL);
/* TODO cleanup all objects instead? */
for (uint32_t i = 0; i < instance->physical_device_count; i++) {
struct vkr_physical_device *physical_dev = instance->physical_devices[i];
@ -1074,10 +1057,33 @@ vkr_dispatch_vkDestroyInstance(struct vn_dispatch_context *dispatch,
free(physical_dev->extensions);
util_hash_table_remove_u64(ctx->object_table, physical_dev->base.id);
}
if (ctx->validate_level != VKR_CONTEXT_VALIDATE_NONE) {
instance->destroy_debug_utils_messenger(instance->base.handle.instance,
instance->validation_messenger, NULL);
}
vkDestroyInstance(instance->base.handle.instance, NULL);
free(instance->physical_device_handles);
free(instance->physical_devices);
util_hash_table_remove_u64(ctx->object_table, instance->base.id);
}
static void
vkr_dispatch_vkDestroyInstance(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroyInstance *args)
{
struct vkr_context *ctx = dispatch->data;
struct vkr_instance *instance = (struct vkr_instance *)args->instance;
if (ctx->instance != instance) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
vkr_instance_destroy(ctx, instance);
ctx->instance = NULL;
}
@ -4728,6 +4734,7 @@ vkr_context_detach_resource(struct virgl_context *base, struct virgl_resource *r
static void
vkr_context_destroy(struct virgl_context *base)
{
/* TODO move the entire teardown process to a separate thread */
struct vkr_context *ctx = (struct vkr_context *)base;
struct vkr_ring *ring, *ring_tmp;
@ -4736,7 +4743,12 @@ vkr_context_destroy(struct virgl_context *base)
vkr_ring_destroy(ring);
}
/* TODO properly destroy all Vulkan objects */
if (ctx->instance) {
vrend_printf("destroying context with a valid instance");
vkr_instance_destroy(ctx, ctx->instance);
}
util_hash_table_destroy(ctx->resource_table);
util_hash_table_destroy_u64(ctx->object_table);

Loading…
Cancel
Save