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 */