From 1d1783fce1046c1b220938874907edd80a015354 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 3 Aug 2021 11:17:03 -0700 Subject: [PATCH] vkr: fix invalid use of RELEASE_TRACKED_OBJECTS RELEASE_TRACKED_OBJECTS did not like track_list to include "obj" after expansion. Fix the callers and fix the gotcha. v2: replace RELEASE_TRACKED_OBJECTS by an inline function (Ryan) Fixes: 9da6721 ("vkr: add RELEASE_TRACKED_OBJECTS for tracked vkr_object") Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang Reviewed-by: Ryan Neph --- src/venus/vkr_command_buffer.c | 3 +-- src/venus/vkr_common.h | 11 +++-------- src/venus/vkr_context.h | 9 +++++++++ src/venus/vkr_descriptor_set.c | 6 ++---- src/venus/vkr_device.c | 6 ++++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/venus/vkr_command_buffer.c b/src/venus/vkr_command_buffer.c index f61f82e..f740b2f 100644 --- a/src/venus/vkr_command_buffer.c +++ b/src/venus/vkr_command_buffer.c @@ -32,8 +32,7 @@ vkr_dispatch_vkDestroyCommandPool(struct vn_dispatch_context *dispatch, DESTROY_OBJECT(pool, command_pool, COMMAND_POOL, vkDestroyCommandPool, commandPool); - RELEASE_TRACKED_OBJECTS(&pool->command_buffers); - + vkr_context_remove_objects(ctx, &pool->command_buffers); util_hash_table_remove_u64(ctx->object_table, pool->base.id); } diff --git a/src/venus/vkr_common.h b/src/venus/vkr_common.h index 0150223..b571f75 100644 --- a/src/venus/vkr_common.h +++ b/src/venus/vkr_common.h @@ -48,6 +48,8 @@ /* * TODO Most of the functions are generated. Some of them are then * hand-edited. Find a better/cleaner way to reduce manual works. + * + * These macros may shadow your variables. Use with care. */ #define CREATE_OBJECT(obj, vkr_type, vk_obj, vk_cmd, vk_arg) \ struct vkr_device *_dev = (struct vkr_device *)args->device; \ @@ -134,13 +136,6 @@ object_array_fini(&arr); \ } while (0) -#define RELEASE_TRACKED_OBJECTS(track_list) \ - do { \ - struct vkr_object *obj, *tmp; \ - LIST_FOR_EACH_ENTRY_SAFE (obj, tmp, track_list, track_head) \ - util_hash_table_remove_u64(ctx->object_table, obj->id); \ - } while (0) - #define FREE_POOL_OBJECTS(vkr_type, vk_type, vk_cmd, arg_obj, arg_count, arg_pool) \ do { \ struct list_head free_list; \ @@ -162,7 +157,7 @@ vn_replace_##vk_cmd##_args_handle(args); \ vk_cmd(args->device, args->arg_pool, args->arg_count, args->arg_obj); \ \ - RELEASE_TRACKED_OBJECTS(&free_list); \ + vkr_context_remove_objects(ctx, &free_list); \ } while (0) #define CREATE_PIPELINES(vk_cmd) \ diff --git a/src/venus/vkr_context.h b/src/venus/vkr_context.h index adee4ee..7310fc3 100644 --- a/src/venus/vkr_context.h +++ b/src/venus/vkr_context.h @@ -63,4 +63,13 @@ struct vkr_context { struct vkr_instance *instance; }; +static inline void +vkr_context_remove_objects(struct vkr_context *ctx, struct list_head *objects) +{ + struct vkr_object *obj, *tmp; + LIST_FOR_EACH_ENTRY_SAFE (obj, tmp, objects, track_head) + util_hash_table_remove_u64(ctx->object_table, obj->id); + /* objects should be reinitialized if to be reused */ +} + #endif /* VKR_CONTEXT_H */ diff --git a/src/venus/vkr_descriptor_set.c b/src/venus/vkr_descriptor_set.c index 3fc55de..cad372b 100644 --- a/src/venus/vkr_descriptor_set.c +++ b/src/venus/vkr_descriptor_set.c @@ -71,8 +71,7 @@ vkr_dispatch_vkDestroyDescriptorPool(struct vn_dispatch_context *dispatch, DESTROY_OBJECT(pool, descriptor_pool, DESCRIPTOR_POOL, vkDestroyDescriptorPool, descriptorPool); - RELEASE_TRACKED_OBJECTS(&pool->descriptor_sets); - + vkr_context_remove_objects(ctx, &pool->descriptor_sets); util_hash_table_remove_u64(ctx->object_table, pool->base.id); } @@ -92,8 +91,7 @@ vkr_dispatch_vkResetDescriptorPool(struct vn_dispatch_context *dispatch, vn_replace_vkResetDescriptorPool_args_handle(args); args->ret = vkResetDescriptorPool(args->device, args->descriptorPool, args->flags); - RELEASE_TRACKED_OBJECTS(&pool->descriptor_sets); - + vkr_context_remove_objects(ctx, &pool->descriptor_sets); list_inithead(&pool->descriptor_sets); } diff --git a/src/venus/vkr_device.c b/src/venus/vkr_device.c index 5da7778..f79213b 100644 --- a/src/venus/vkr_device.c +++ b/src/venus/vkr_device.c @@ -241,7 +241,8 @@ vkr_device_object_destroy(struct vkr_context *ctx, */ vkDestroyDescriptorPool(device, obj->handle.descriptor_pool, NULL); - RELEASE_TRACKED_OBJECTS(&((struct vkr_descriptor_pool *)obj)->descriptor_sets); + struct vkr_descriptor_pool *pool = (struct vkr_descriptor_pool *)obj; + vkr_context_remove_objects(ctx, &pool->descriptor_sets); break; } case VK_OBJECT_TYPE_FRAMEBUFFER: @@ -253,7 +254,8 @@ vkr_device_object_destroy(struct vkr_context *ctx, */ vkDestroyCommandPool(device, obj->handle.command_pool, NULL); - RELEASE_TRACKED_OBJECTS(&((struct vkr_command_pool *)obj)->command_buffers); + struct vkr_command_pool *pool = (struct vkr_command_pool *)obj; + vkr_context_remove_objects(ctx, &pool->command_buffers); break; } case VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION: