From 98399f37dba545305a62c1c2f691bb90c1824db4 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 9 Aug 2021 11:08:00 -0700 Subject: [PATCH] vkr: add vkr_device_{add,remove}_object They are wrappers to vkr_context_{add,remove}_object with added sanity checks. Signed-off-by: Chia-I Wu Reviewed-by: Ryan Neph Reviewed-by: Yiwei Zhang --- src/venus/vkr_device.c | 8 ++------ src/venus/vkr_device.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/venus/vkr_device.c b/src/venus/vkr_device.c index 65fe172..487ac26 100644 --- a/src/venus/vkr_device.c +++ b/src/venus/vkr_device.c @@ -233,6 +233,8 @@ vkr_device_object_destroy(struct vkr_context *ctx, { VkDevice device = dev->base.handle.device; + assert(vkr_device_should_track_object(obj)); + switch (obj->type) { case VK_OBJECT_TYPE_SEMAPHORE: vkDestroySemaphore(device, obj->handle.semaphore, NULL); @@ -315,12 +317,6 @@ vkr_device_object_destroy(struct vkr_context *ctx, vkDestroyDescriptorUpdateTemplate(device, obj->handle.descriptor_update_template, NULL); break; - case VK_OBJECT_TYPE_INSTANCE: /* non-device objects */ - case VK_OBJECT_TYPE_PHYSICAL_DEVICE: /* non-device objects */ - case VK_OBJECT_TYPE_DEVICE: /* device itself */ - case VK_OBJECT_TYPE_QUEUE: /* not tracked as device objects */ - case VK_OBJECT_TYPE_COMMAND_BUFFER: /* pool objects */ - case VK_OBJECT_TYPE_DESCRIPTOR_SET: /* pool objects */ default: vkr_log("Unhandled vkr_object(%p) with VkObjectType(%u)", obj, (uint32_t)obj->type); assert(false); diff --git a/src/venus/vkr_device.h b/src/venus/vkr_device.h index 4a1d4c4..9bd0e60 100644 --- a/src/venus/vkr_device.h +++ b/src/venus/vkr_device.h @@ -8,6 +8,8 @@ #include "vkr_common.h" +#include "vkr_context.h" + struct vkr_device { struct vkr_object base; @@ -53,4 +55,38 @@ vkr_context_init_device_dispatch(struct vkr_context *ctx); void vkr_device_destroy(struct vkr_context *ctx, struct vkr_device *dev); +static inline bool +vkr_device_should_track_object(const struct vkr_object *obj) +{ + assert(vkr_is_recognized_object_type(obj->type)); + + switch (obj->type) { + case VK_OBJECT_TYPE_INSTANCE: /* non-device objects */ + case VK_OBJECT_TYPE_PHYSICAL_DEVICE: /* non-device objects */ + case VK_OBJECT_TYPE_DEVICE: /* device itself */ + case VK_OBJECT_TYPE_QUEUE: /* not tracked as device objects */ + case VK_OBJECT_TYPE_COMMAND_BUFFER: /* pool objects */ + case VK_OBJECT_TYPE_DESCRIPTOR_SET: /* pool objects */ + return false; + default: + return true; + } +} + +static inline void +vkr_device_add_object(struct vkr_context *ctx, struct vkr_object *obj) +{ + assert(vkr_device_should_track_object(obj)); + + /* TODO add to dev->objects */ + vkr_context_add_object(ctx, obj); +} + +static inline void +vkr_device_remove_object(struct vkr_context *ctx, struct vkr_object *obj) +{ + /* TODO remove from dev->objects */ + vkr_context_remove_object(ctx, obj); +} + #endif /* VKR_DEVICE_H */