vkr: add VKR_DEFINE_OBJECT_CAST

The macro defines a type-safe cast function.  Define one for every
object.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent cc151f30ad
commit ab431feabe
  1. 2
      src/venus/vkr_buffer.h
  2. 2
      src/venus/vkr_command_buffer.h
  3. 14
      src/venus/vkr_common.h
  4. 8
      src/venus/vkr_descriptor_set.h
  5. 1
      src/venus/vkr_device.h
  6. 1
      src/venus/vkr_device_memory.h
  7. 6
      src/venus/vkr_image.h
  8. 1
      src/venus/vkr_instance.h
  9. 1
      src/venus/vkr_physical_device.h
  10. 4
      src/venus/vkr_pipeline.h
  11. 1
      src/venus/vkr_query_pool.h
  12. 4
      src/venus/vkr_queue.h
  13. 2
      src/venus/vkr_render_pass.h

@ -11,10 +11,12 @@
struct vkr_buffer {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(buffer, VK_OBJECT_TYPE_BUFFER, VkBuffer)
struct vkr_buffer_view {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(buffer_view, VK_OBJECT_TYPE_BUFFER_VIEW, VkBufferView)
void
vkr_context_init_buffer_dispatch(struct vkr_context *ctx);

@ -13,12 +13,14 @@ struct vkr_command_pool {
struct list_head command_buffers;
};
VKR_DEFINE_OBJECT_CAST(command_pool, VK_OBJECT_TYPE_COMMAND_POOL, VkCommandPool)
struct vkr_command_buffer {
struct vkr_object base;
struct vkr_device *device;
};
VKR_DEFINE_OBJECT_CAST(command_buffer, VK_OBJECT_TYPE_COMMAND_BUFFER, VkCommandBuffer)
void
vkr_context_init_command_pool_dispatch(struct vkr_context *ctx);

@ -45,6 +45,20 @@
#define VKR_DEBUG(category) (unlikely(vkr_debug_flags & VKR_DEBUG_##category))
/* define a type-safe cast function */
#define VKR_DEFINE_OBJECT_CAST(vkr_type, vk_enum, vk_type) \
static inline struct vkr_##vkr_type *vkr_##vkr_type##_from_handle(vk_type handle) \
{ \
struct vkr_##vkr_type *obj = (struct vkr_##vkr_type *)(uintptr_t)handle; \
if (obj) { \
assert(obj->base.type == vk_enum); \
assert(obj->base.id); \
assert(obj->base.handle.vkr_type); \
assert((uintptr_t)obj->base.handle.vkr_type == obj->base.handle.u64); \
} \
return obj; \
}
/*
* TODO Most of the functions are generated. Some of them are then
* hand-edited. Find a better/cleaner way to reduce manual works.

@ -11,22 +11,30 @@
struct vkr_descriptor_set_layout {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(descriptor_set_layout,
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT,
VkDescriptorSetLayout)
struct vkr_descriptor_pool {
struct vkr_object base;
struct list_head descriptor_sets;
};
VKR_DEFINE_OBJECT_CAST(descriptor_pool, VK_OBJECT_TYPE_DESCRIPTOR_POOL, VkDescriptorPool)
struct vkr_descriptor_set {
struct vkr_object base;
struct vkr_device *device;
};
VKR_DEFINE_OBJECT_CAST(descriptor_set, VK_OBJECT_TYPE_DESCRIPTOR_SET, VkDescriptorSet)
struct vkr_descriptor_update_template {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(descriptor_update_template,
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE,
VkDescriptorUpdateTemplate)
void
vkr_context_init_descriptor_set_layout_dispatch(struct vkr_context *ctx);

@ -48,6 +48,7 @@ struct vkr_device {
struct list_head objects;
};
VKR_DEFINE_OBJECT_CAST(device, VK_OBJECT_TYPE_DEVICE, VkDevice)
void
vkr_context_init_device_dispatch(struct vkr_context *ctx);

@ -19,6 +19,7 @@ struct vkr_device_memory {
uint32_t exported_res_id;
struct list_head exported_head;
};
VKR_DEFINE_OBJECT_CAST(device_memory, VK_OBJECT_TYPE_DEVICE_MEMORY, VkDeviceMemory)
void
vkr_context_init_device_memory_dispatch(struct vkr_context *ctx);

@ -11,18 +11,24 @@
struct vkr_image {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(image, VK_OBJECT_TYPE_IMAGE, VkImage)
struct vkr_image_view {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(image_view, VK_OBJECT_TYPE_IMAGE_VIEW, VkImageView)
struct vkr_sampler {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(sampler, VK_OBJECT_TYPE_SAMPLER, VkSampler)
struct vkr_sampler_ycbcr_conversion {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(sampler_ycbcr_conversion,
VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION,
VkSamplerYcbcrConversion)
void
vkr_context_init_image_dispatch(struct vkr_context *ctx);

@ -23,6 +23,7 @@ struct vkr_instance {
VkPhysicalDevice *physical_device_handles;
struct vkr_physical_device **physical_devices;
};
VKR_DEFINE_OBJECT_CAST(instance, VK_OBJECT_TYPE_INSTANCE, VkInstance)
void
vkr_context_init_instance_dispatch(struct vkr_context *ctx);

@ -26,6 +26,7 @@ struct vkr_physical_device {
struct list_head devices;
};
VKR_DEFINE_OBJECT_CAST(physical_device, VK_OBJECT_TYPE_PHYSICAL_DEVICE, VkPhysicalDevice)
void
vkr_context_init_physical_device_dispatch(struct vkr_context *ctx);

@ -11,18 +11,22 @@
struct vkr_shader_module {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(shader_module, VK_OBJECT_TYPE_SHADER_MODULE, VkShaderModule)
struct vkr_pipeline_layout {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(pipeline_layout, VK_OBJECT_TYPE_PIPELINE_LAYOUT, VkPipelineLayout)
struct vkr_pipeline_cache {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(pipeline_cache, VK_OBJECT_TYPE_PIPELINE_CACHE, VkPipelineCache)
struct vkr_pipeline {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(pipeline, VK_OBJECT_TYPE_PIPELINE, VkPipeline)
void
vkr_context_init_shader_module_dispatch(struct vkr_context *ctx);

@ -11,6 +11,7 @@
struct vkr_query_pool {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(query_pool, VK_OBJECT_TYPE_QUERY_POOL, VkQueryPool)
void
vkr_context_init_query_pool_dispatch(struct vkr_context *ctx);

@ -54,18 +54,22 @@ struct vkr_queue {
struct list_head busy_head;
};
VKR_DEFINE_OBJECT_CAST(queue, VK_OBJECT_TYPE_QUEUE, VkQueue)
struct vkr_fence {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(fence, VK_OBJECT_TYPE_FENCE, VkFence)
struct vkr_semaphore {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(semaphore, VK_OBJECT_TYPE_SEMAPHORE, VkSemaphore)
struct vkr_event {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(event, VK_OBJECT_TYPE_EVENT, VkEvent)
void
vkr_context_init_queue_dispatch(struct vkr_context *ctx);

@ -11,10 +11,12 @@
struct vkr_render_pass {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(render_pass, VK_OBJECT_TYPE_RENDER_PASS, VkRenderPass)
struct vkr_framebuffer {
struct vkr_object base;
};
VKR_DEFINE_OBJECT_CAST(framebuffer, VK_OBJECT_TYPE_FRAMEBUFFER, VkFramebuffer)
void
vkr_context_init_render_pass_dispatch(struct vkr_context *ctx);

Loading…
Cancel
Save