anv,vulkan: Implement VK_EXT_private_data
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 21 Apr 2020 21:31:25 +0000 (16:31 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 12 May 2020 18:01:48 +0000 (18:01 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4882>

docs/relnotes/new_features.txt
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_extensions.py
src/vulkan/util/vk_object.c
src/vulkan/util/vk_object.h

index de4cd0a531732487213d10790ae048800b4a237c..9a34a73f821a2afdc23ebde4b47a67a770231d74 100644 (file)
@@ -1 +1,2 @@
 GL_ARB_compute_variable_group_size on Iris.
+VK_EXT_private_data on ANV.
index 49553b0b2aa5ddf73b6f2e0f1ce57c7007d38344..993fa06de98a7e17a4d62b97e4fe9a32ca3c2530 100644 (file)
@@ -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);
+}
index 3da10c724b98867790bfa9331ccf8c47b49990ce..bcc91fdf467b338568b64ed6edf2b3b36b4879c9 100644 (file)
@@ -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'),
index 70519dbc718f3d116bed60dfee306b5b71842c0b..789cf12b15cf6888639da7a55122559a6bdd72f4 100644 (file)
@@ -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;
+}
index d28f79d4943c2f236b9953dc8b5acdd2ce17335b..8ae539bd55645a9f3fea6857d2d15cb8d22b3b46 100644 (file)
@@ -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