17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2020 Intel Corporation 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg#ifndef VK_OBJECT_H 247ec681f3Smrg#define VK_OBJECT_H 257ec681f3Smrg 267ec681f3Smrg#include <vulkan/vulkan.h> 277ec681f3Smrg#include <vulkan/vk_icd.h> 287ec681f3Smrg 297ec681f3Smrg#include "c11/threads.h" 307ec681f3Smrg#include "util/macros.h" 317ec681f3Smrg#include "util/sparse_array.h" 327ec681f3Smrg 337ec681f3Smrg#ifdef __cplusplus 347ec681f3Smrgextern "C" { 357ec681f3Smrg#endif 367ec681f3Smrg 377ec681f3Smrgstruct hash_table; 387ec681f3Smrg 397ec681f3Smrgstruct vk_device; 407ec681f3Smrg 417ec681f3Smrgstruct vk_object_base { 427ec681f3Smrg VK_LOADER_DATA _loader_data; 437ec681f3Smrg VkObjectType type; 447ec681f3Smrg 457ec681f3Smrg struct vk_device *device; 467ec681f3Smrg 477ec681f3Smrg /* True if this object is fully constructed and visible to the client */ 487ec681f3Smrg bool client_visible; 497ec681f3Smrg 507ec681f3Smrg /* For VK_EXT_private_data */ 517ec681f3Smrg struct util_sparse_array private_data; 527ec681f3Smrg 537ec681f3Smrg /* VK_EXT_debug_utils */ 547ec681f3Smrg char *object_name; 557ec681f3Smrg}; 567ec681f3Smrg 577ec681f3Smrgvoid vk_object_base_init(UNUSED struct vk_device *device, 587ec681f3Smrg struct vk_object_base *base, 597ec681f3Smrg UNUSED VkObjectType obj_type); 607ec681f3Smrgvoid vk_object_base_finish(UNUSED struct vk_object_base *base); 617ec681f3Smrg 627ec681f3Smrgstatic inline void 637ec681f3Smrgvk_object_base_assert_valid(ASSERTED struct vk_object_base *base, 647ec681f3Smrg ASSERTED VkObjectType obj_type) 657ec681f3Smrg{ 667ec681f3Smrg assert(base == NULL || base->type == obj_type); 677ec681f3Smrg} 687ec681f3Smrg 697ec681f3Smrgstatic inline struct vk_object_base * 707ec681f3Smrgvk_object_base_from_u64_handle(uint64_t handle, VkObjectType obj_type) 717ec681f3Smrg{ 727ec681f3Smrg struct vk_object_base *base = (struct vk_object_base *)(uintptr_t)handle; 737ec681f3Smrg vk_object_base_assert_valid(base, obj_type); 747ec681f3Smrg return base; 757ec681f3Smrg} 767ec681f3Smrg 777ec681f3Smrg#define VK_DEFINE_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \ 787ec681f3Smrg static inline struct __driver_type * \ 797ec681f3Smrg __driver_type ## _from_handle(__VkType _handle) \ 807ec681f3Smrg { \ 817ec681f3Smrg struct vk_object_base *base = (struct vk_object_base *)_handle; \ 827ec681f3Smrg vk_object_base_assert_valid(base, __VK_TYPE); \ 837ec681f3Smrg STATIC_ASSERT(offsetof(struct __driver_type, __base) == 0); \ 847ec681f3Smrg return (struct __driver_type *) base; \ 857ec681f3Smrg } \ 867ec681f3Smrg \ 877ec681f3Smrg static inline __VkType \ 887ec681f3Smrg __driver_type ## _to_handle(struct __driver_type *_obj) \ 897ec681f3Smrg { \ 907ec681f3Smrg vk_object_base_assert_valid(&_obj->__base, __VK_TYPE); \ 917ec681f3Smrg if (_obj != NULL) \ 927ec681f3Smrg _obj->__base.client_visible = true; \ 937ec681f3Smrg return (__VkType) _obj; \ 947ec681f3Smrg } 957ec681f3Smrg 967ec681f3Smrg#define VK_DEFINE_NONDISP_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \ 977ec681f3Smrg static inline struct __driver_type * \ 987ec681f3Smrg __driver_type ## _from_handle(__VkType _handle) \ 997ec681f3Smrg { \ 1007ec681f3Smrg struct vk_object_base *base = \ 1017ec681f3Smrg (struct vk_object_base *)(uintptr_t)_handle; \ 1027ec681f3Smrg vk_object_base_assert_valid(base, __VK_TYPE); \ 1037ec681f3Smrg STATIC_ASSERT(offsetof(struct __driver_type, __base) == 0); \ 1047ec681f3Smrg return (struct __driver_type *)base; \ 1057ec681f3Smrg } \ 1067ec681f3Smrg \ 1077ec681f3Smrg static inline __VkType \ 1087ec681f3Smrg __driver_type ## _to_handle(struct __driver_type *_obj) \ 1097ec681f3Smrg { \ 1107ec681f3Smrg vk_object_base_assert_valid(&_obj->__base, __VK_TYPE); \ 1117ec681f3Smrg if (_obj != NULL) \ 1127ec681f3Smrg _obj->__base.client_visible = true; \ 1137ec681f3Smrg return (__VkType)(uintptr_t) _obj; \ 1147ec681f3Smrg } 1157ec681f3Smrg 1167ec681f3Smrg#define VK_FROM_HANDLE(__driver_type, __name, __handle) \ 1177ec681f3Smrg struct __driver_type *__name = __driver_type ## _from_handle(__handle) 1187ec681f3Smrg 1197ec681f3Smrg/* Helpers for vk object (de)allocation and (de)initialization */ 1207ec681f3Smrgvoid * 1217ec681f3Smrgvk_object_alloc(struct vk_device *device, 1227ec681f3Smrg const VkAllocationCallbacks *alloc, 1237ec681f3Smrg size_t size, 1247ec681f3Smrg VkObjectType vk_obj_type); 1257ec681f3Smrg 1267ec681f3Smrgvoid * 1277ec681f3Smrgvk_object_zalloc(struct vk_device *device, 1287ec681f3Smrg const VkAllocationCallbacks *alloc, 1297ec681f3Smrg size_t size, 1307ec681f3Smrg VkObjectType vk_obj_type); 1317ec681f3Smrg 1327ec681f3Smrgstruct vk_multialloc; 1337ec681f3Smrg 1347ec681f3Smrgvoid * 1357ec681f3Smrgvk_object_multialloc(struct vk_device *device, 1367ec681f3Smrg struct vk_multialloc *ma, 1377ec681f3Smrg const VkAllocationCallbacks *alloc, 1387ec681f3Smrg VkObjectType vk_obj_type); 1397ec681f3Smrg 1407ec681f3Smrgvoid * 1417ec681f3Smrgvk_object_multizalloc(struct vk_device *device, 1427ec681f3Smrg struct vk_multialloc *ma, 1437ec681f3Smrg const VkAllocationCallbacks *alloc, 1447ec681f3Smrg VkObjectType vk_obj_type); 1457ec681f3Smrg 1467ec681f3Smrgvoid 1477ec681f3Smrgvk_object_free(struct vk_device *device, 1487ec681f3Smrg const VkAllocationCallbacks *alloc, 1497ec681f3Smrg void *data); 1507ec681f3Smrg 1517ec681f3Smrg 1527ec681f3Smrgstruct vk_private_data_slot { 1537ec681f3Smrg struct vk_object_base base; 1547ec681f3Smrg uint32_t index; 1557ec681f3Smrg}; 1567ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(vk_private_data_slot, base, 1577ec681f3Smrg VkPrivateDataSlotEXT, 1587ec681f3Smrg VK_OBJECT_TYPE_PRIVATE_DATA_SLOT_EXT); 1597ec681f3Smrg 1607ec681f3SmrgVkResult 1617ec681f3Smrgvk_private_data_slot_create(struct vk_device *device, 1627ec681f3Smrg const VkPrivateDataSlotCreateInfoEXT* pCreateInfo, 1637ec681f3Smrg const VkAllocationCallbacks* pAllocator, 1647ec681f3Smrg VkPrivateDataSlotEXT* pPrivateDataSlot); 1657ec681f3Smrgvoid 1667ec681f3Smrgvk_private_data_slot_destroy(struct vk_device *device, 1677ec681f3Smrg VkPrivateDataSlotEXT privateDataSlot, 1687ec681f3Smrg const VkAllocationCallbacks *pAllocator); 1697ec681f3SmrgVkResult 1707ec681f3Smrgvk_object_base_set_private_data(struct vk_device *device, 1717ec681f3Smrg VkObjectType objectType, 1727ec681f3Smrg uint64_t objectHandle, 1737ec681f3Smrg VkPrivateDataSlotEXT privateDataSlot, 1747ec681f3Smrg uint64_t data); 1757ec681f3Smrgvoid 1767ec681f3Smrgvk_object_base_get_private_data(struct vk_device *device, 1777ec681f3Smrg VkObjectType objectType, 1787ec681f3Smrg uint64_t objectHandle, 1797ec681f3Smrg VkPrivateDataSlotEXT privateDataSlot, 1807ec681f3Smrg uint64_t *pData); 1817ec681f3Smrg 1827ec681f3Smrgconst char * 1837ec681f3Smrgvk_object_base_name(struct vk_object_base *obj); 1847ec681f3Smrg 1857ec681f3Smrg#ifdef __cplusplus 1867ec681f3Smrg} 1877ec681f3Smrg#endif 1887ec681f3Smrg 1897ec681f3Smrg#endif /* VK_OBJECT_H */ 190