Commit 51c6bc13 authored by Jason Ekstrand's avatar Jason Ekstrand Committed by Marge Bot
Browse files

anv,vulkan: Implement VK_EXT_private_data


Reviewed-by: Samuel Pitoiset's avatarSamuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <mesa/mesa!4882>
parent d76e722e
GL_ARB_compute_variable_group_size on Iris.
VK_EXT_private_data on ANV.
......@@ -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);
}
......@@ -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'),
......
......@@ -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;
}
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment