diff options
author | Jason Ekstrand <[email protected]> | 2020-04-21 16:31:25 -0500 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-05-12 18:01:48 +0000 |
commit | 51c6bc13ce3a70b1948ce5c4edbc1d29c5460986 (patch) | |
tree | 73d0629796332d4fd80c205bb755f919124a7f12 | |
parent | d76e722ed63607ecead2c66ef9f3a37a12b62bab (diff) |
anv,vulkan: Implement VK_EXT_private_data
Reviewed-by: Samuel Pitoiset <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4882>
-rw-r--r-- | docs/relnotes/new_features.txt | 1 | ||||
-rw-r--r-- | src/intel/vulkan/anv_device.c | 52 | ||||
-rw-r--r-- | src/intel/vulkan/anv_extensions.py | 1 | ||||
-rw-r--r-- | src/vulkan/util/vk_object.c | 78 | ||||
-rw-r--r-- | src/vulkan/util/vk_object.h | 46 |
5 files changed, 177 insertions, 1 deletions
diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index de4cd0a5317..9a34a73f821 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -1 +1,2 @@ GL_ARB_compute_variable_group_size on Iris. +VK_EXT_private_data on ANV. diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 49553b0b2aa..993fa06de98 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -1237,6 +1237,12 @@ void anv_GetPhysicalDeviceFeatures2( break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT: { + VkPhysicalDevicePrivateDataFeaturesEXT *features = (void *)ext; + features->privateData = true; + break; + } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: { VkPhysicalDeviceProtectedMemoryFeatures *features = (void *)ext; CORE_FEATURE(1, 1, protectedMemory); @@ -4511,3 +4517,49 @@ vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) *pSupportedVersion = MIN2(*pSupportedVersion, 4u); return VK_SUCCESS; } + +VkResult anv_CreatePrivateDataSlotEXT( + VkDevice _device, + const VkPrivateDataSlotCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkPrivateDataSlotEXT* pPrivateDataSlot) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + return vk_private_data_slot_create(&device->vk, pCreateInfo, pAllocator, + pPrivateDataSlot); +} + +void anv_DestroyPrivateDataSlotEXT( + VkDevice _device, + VkPrivateDataSlotEXT privateDataSlot, + const VkAllocationCallbacks* pAllocator) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + vk_private_data_slot_destroy(&device->vk, privateDataSlot, pAllocator); +} + +VkResult anv_SetPrivateDataEXT( + VkDevice _device, + VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot, + uint64_t data) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + return vk_object_base_set_private_data(&device->vk, + objectType, objectHandle, + privateDataSlot, data); +} + +void anv_GetPrivateDataEXT( + VkDevice _device, + VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot, + uint64_t* pData) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + vk_object_base_get_private_data(&device->vk, + objectType, objectHandle, + privateDataSlot, pData); +} diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py index 3da10c724b9..bcc91fdf467 100644 --- a/src/intel/vulkan/anv_extensions.py +++ b/src/intel/vulkan/anv_extensions.py @@ -152,6 +152,7 @@ EXTENSIONS = [ Extension('VK_EXT_pci_bus_info', 2, True), Extension('VK_EXT_pipeline_creation_feedback', 1, True), Extension('VK_EXT_post_depth_coverage', 1, 'device->info.gen >= 9'), + Extension('VK_EXT_private_data', 1, True), Extension('VK_EXT_queue_family_foreign', 1, 'ANDROID'), Extension('VK_EXT_robustness2', 1, True), Extension('VK_EXT_sampler_filter_minmax', 1, 'device->info.gen >= 9'), diff --git a/src/vulkan/util/vk_object.c b/src/vulkan/util/vk_object.c index 70519dbc718..789cf12b15c 100644 --- a/src/vulkan/util/vk_object.c +++ b/src/vulkan/util/vk_object.c @@ -23,6 +23,8 @@ #include "vk_object.h" +#include "vk_alloc.h" + void vk_object_base_init(UNUSED struct vk_device *device, struct vk_object_base *base, @@ -30,11 +32,13 @@ vk_object_base_init(UNUSED struct vk_device *device, { base->_loader_data.loaderMagic = ICD_LOADER_MAGIC; base->type = obj_type; + util_sparse_array_init(&base->private_data, sizeof(uint64_t), 8); } void -vk_object_base_finish(UNUSED struct vk_object_base *base) +vk_object_base_finish(struct vk_object_base *base) { + util_sparse_array_finish(&base->private_data); } void @@ -48,6 +52,8 @@ vk_device_init(struct vk_device *device, device->alloc = *device_alloc; else device->alloc = *instance_alloc; + + p_atomic_set(&device->private_data_next_index, 0); } void @@ -55,3 +61,73 @@ vk_device_finish(UNUSED struct vk_device *device) { vk_object_base_finish(&device->base); } + +VkResult +vk_private_data_slot_create(struct vk_device *device, + const VkPrivateDataSlotCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkPrivateDataSlotEXT* pPrivateDataSlot) +{ + struct vk_private_data_slot *slot = + vk_alloc2(&device->alloc, pAllocator, sizeof(*slot), 8, + VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (slot == NULL) + return VK_ERROR_OUT_OF_HOST_MEMORY; + + vk_object_base_init(device, &slot->base, + VK_OBJECT_TYPE_PRIVATE_DATA_SLOT_EXT); + slot->index = p_atomic_inc_return(&device->private_data_next_index); + + *pPrivateDataSlot = vk_private_data_slot_to_handle(slot); + + return VK_SUCCESS; +} + +void +vk_private_data_slot_destroy(struct vk_device *device, + VkPrivateDataSlotEXT privateDataSlot, + const VkAllocationCallbacks *pAllocator) +{ + VK_FROM_HANDLE(vk_private_data_slot, slot, privateDataSlot); + if (slot == NULL) + return; + + vk_object_base_finish(&slot->base); + vk_free2(&device->alloc, pAllocator, slot); +} + +static uint64_t * +vk_object_base_private_data(VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot) +{ + VK_FROM_HANDLE(vk_private_data_slot, slot, privateDataSlot); + struct vk_object_base *obj = + vk_object_base_from_u64_handle(objectHandle, objectType); + return util_sparse_array_get(&obj->private_data, slot->index); +} + +VkResult +vk_object_base_set_private_data(struct vk_device *device, + VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot, + uint64_t data) +{ + uint64_t *private_data = + vk_object_base_private_data(objectType, objectHandle, privateDataSlot); + *private_data = data; + return VK_SUCCESS; +} + +void +vk_object_base_get_private_data(struct vk_device *device, + VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot, + uint64_t *pData) +{ + uint64_t *private_data = + vk_object_base_private_data(objectType, objectHandle, privateDataSlot); + *pData = *private_data; +} diff --git a/src/vulkan/util/vk_object.h b/src/vulkan/util/vk_object.h index d28f79d4943..8ae539bd556 100644 --- a/src/vulkan/util/vk_object.h +++ b/src/vulkan/util/vk_object.h @@ -27,6 +27,7 @@ #include <vulkan/vk_icd.h> #include "util/macros.h" +#include "util/sparse_array.h" #ifdef __cplusplus extern "C" { @@ -37,6 +38,9 @@ struct vk_device; struct vk_object_base { VK_LOADER_DATA _loader_data; VkObjectType type; + + /* For VK_EXT_private_data */ + struct util_sparse_array private_data; }; void vk_object_base_init(UNUSED struct vk_device *device, @@ -51,10 +55,21 @@ vk_object_base_assert_valid(ASSERTED struct vk_object_base *base, assert(base == NULL || base->type == obj_type); } +static inline struct vk_object_base * +vk_object_base_from_u64_handle(uint64_t handle, VkObjectType obj_type) +{ + struct vk_object_base *base = (struct vk_object_base *)(uintptr_t)handle; + vk_object_base_assert_valid(base, obj_type); + return base; +} + struct vk_device { struct vk_object_base base; VkAllocationCallbacks alloc; + + /* For VK_EXT_private_data */ + uint32_t private_data_next_index; }; void vk_device_init(struct vk_device *device, @@ -101,6 +116,37 @@ void vk_device_finish(struct vk_device *device); #define VK_FROM_HANDLE(__driver_type, __name, __handle) \ struct __driver_type *__name = __driver_type ## _from_handle(__handle) + +struct vk_private_data_slot { + struct vk_object_base base; + uint32_t index; +}; +VK_DEFINE_NONDISP_HANDLE_CASTS(vk_private_data_slot, base, + VkPrivateDataSlotEXT, + VK_OBJECT_TYPE_PRIVATE_DATA_SLOT_EXT); + +VkResult +vk_private_data_slot_create(struct vk_device *device, + const VkPrivateDataSlotCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkPrivateDataSlotEXT* pPrivateDataSlot); +void +vk_private_data_slot_destroy(struct vk_device *device, + VkPrivateDataSlotEXT privateDataSlot, + const VkAllocationCallbacks *pAllocator); +VkResult +vk_object_base_set_private_data(struct vk_device *device, + VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot, + uint64_t data); +void +vk_object_base_get_private_data(struct vk_device *device, + VkObjectType objectType, + uint64_t objectHandle, + VkPrivateDataSlotEXT privateDataSlot, + uint64_t *pData); + #ifdef __cplusplus } #endif |