anv: handle protected memory allocation
v2: Add assert on VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT in vkMapMemory Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: José Roberto de Souza <jose.souza@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8064>
This commit is contained in:
committed by
Marge Bot
parent
5ef8587b1e
commit
5f2c77a10a
@@ -1592,6 +1592,7 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device,
|
||||
assert(!(alloc_flags & (ANV_BO_ALLOC_MAPPED |
|
||||
ANV_BO_ALLOC_SNOOPED |
|
||||
ANV_BO_ALLOC_DEDICATED |
|
||||
ANV_BO_ALLOC_PROTECTED |
|
||||
ANV_BO_ALLOC_FIXED_ADDRESS)));
|
||||
assert(alloc_flags & ANV_BO_ALLOC_EXTERNAL);
|
||||
|
||||
|
||||
@@ -4029,6 +4029,9 @@ VkResult anv_AllocateMemory(
|
||||
if (mem->vk.alloc_flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT)
|
||||
alloc_flags |= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS;
|
||||
|
||||
if (mem->vk.alloc_flags & VK_MEMORY_PROPERTY_PROTECTED_BIT)
|
||||
alloc_flags |= ANV_BO_ALLOC_PROTECTED;
|
||||
|
||||
/* Anything imported or exported is EXTERNAL. Apply implicit sync to be
|
||||
* compatible with clients relying on implicit fencing. This matches the
|
||||
* behavior in iris i915_batch_submit. An example client is VA-API.
|
||||
@@ -4541,6 +4544,7 @@ VkResult anv_ResetEvent(
|
||||
|
||||
static void
|
||||
anv_get_buffer_memory_requirements(struct anv_device *device,
|
||||
VkBufferCreateFlags flags,
|
||||
VkDeviceSize size,
|
||||
VkBufferUsageFlags usage,
|
||||
bool is_sparse,
|
||||
@@ -4553,7 +4557,18 @@ anv_get_buffer_memory_requirements(struct anv_device *device,
|
||||
* only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
|
||||
* structure for the physical device is supported.
|
||||
*/
|
||||
uint32_t memory_types = (1ull << device->physical->memory.type_count) - 1;
|
||||
uint32_t memory_types = 0;
|
||||
for (uint32_t i = 0; i < device->physical->memory.type_count; i++) {
|
||||
/* Have the protected buffer bit match only the memory types with the
|
||||
* equivalent bit.
|
||||
*/
|
||||
if (!!(flags & VK_BUFFER_CREATE_PROTECTED_BIT) !=
|
||||
!!(device->physical->memory.types[i].propertyFlags &
|
||||
VK_MEMORY_PROPERTY_PROTECTED_BIT))
|
||||
continue;
|
||||
|
||||
memory_types |= 1ull << i;
|
||||
}
|
||||
|
||||
/* The GPU appears to write back to main memory in cachelines. Writes to a
|
||||
* buffers should not clobber with writes to another buffers so make sure
|
||||
@@ -4622,6 +4637,7 @@ void anv_GetDeviceBufferMemoryRequirementsKHR(
|
||||
__LINE__, pInfo->pCreateInfo->flags);
|
||||
|
||||
anv_get_buffer_memory_requirements(device,
|
||||
pInfo->pCreateInfo->flags,
|
||||
pInfo->pCreateInfo->size,
|
||||
pInfo->pCreateInfo->usage,
|
||||
is_sparse,
|
||||
|
||||
@@ -1890,10 +1890,19 @@ anv_image_get_memory_requirements(struct anv_device *device,
|
||||
* supported memory type for the resource. The bit `1<<i` is set if and
|
||||
* only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
|
||||
* structure for the physical device is supported.
|
||||
*
|
||||
* All types are currently supported for images.
|
||||
*/
|
||||
uint32_t memory_types = (1ull << device->physical->memory.type_count) - 1;
|
||||
uint32_t memory_types = 0;
|
||||
for (uint32_t i = 0; i < device->physical->memory.type_count; i++) {
|
||||
/* Have the protected image bit match only the memory types with the
|
||||
* equivalent bit.
|
||||
*/
|
||||
if (!!(image->vk.create_flags & VK_IMAGE_CREATE_PROTECTED_BIT) !=
|
||||
!!(device->physical->memory.types[i].propertyFlags &
|
||||
VK_MEMORY_PROPERTY_PROTECTED_BIT))
|
||||
continue;
|
||||
|
||||
memory_types |= 1ull << i;
|
||||
}
|
||||
|
||||
vk_foreach_struct(ext, pMemoryRequirements->pNext) {
|
||||
switch (ext->sType) {
|
||||
|
||||
@@ -406,6 +406,9 @@ enum anv_bo_alloc_flags {
|
||||
* Not for buffers used as the TR-TT page tables.
|
||||
*/
|
||||
ANV_BO_ALLOC_TRTT = (1 << 14),
|
||||
|
||||
/** Protected buffer */
|
||||
ANV_BO_ALLOC_PROTECTED = (1 << 15),
|
||||
};
|
||||
|
||||
struct anv_bo {
|
||||
|
||||
@@ -206,6 +206,18 @@ anv_i915_physical_device_init_memory_types(struct anv_physical_device *device)
|
||||
};
|
||||
}
|
||||
|
||||
if (device->has_protected_contexts) {
|
||||
/* Add a memory type for protected buffers, local and not host
|
||||
* visible.
|
||||
*/
|
||||
device->memory.types[device->memory.type_count++] =
|
||||
(struct anv_memory_type) {
|
||||
.propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
||||
VK_MEMORY_PROPERTY_PROTECTED_BIT,
|
||||
.heapIndex = 0,
|
||||
};
|
||||
}
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,16 +78,18 @@ i915_gem_create(struct anv_device *device,
|
||||
flags |= I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS;
|
||||
|
||||
struct drm_i915_gem_create_ext_memory_regions ext_regions = {
|
||||
.base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS },
|
||||
.num_regions = num_regions,
|
||||
.regions = (uintptr_t)i915_regions,
|
||||
};
|
||||
struct drm_i915_gem_create_ext gem_create = {
|
||||
.size = size,
|
||||
.extensions = (uintptr_t) &ext_regions,
|
||||
.flags = flags,
|
||||
};
|
||||
|
||||
intel_i915_gem_add_ext(&gem_create.extensions,
|
||||
I915_GEM_CREATE_EXT_MEMORY_REGIONS,
|
||||
&ext_regions.base);
|
||||
|
||||
struct drm_i915_gem_create_ext_set_pat set_pat_param = { 0 };
|
||||
if (device->info->has_set_pat_uapi) {
|
||||
/* Set PAT param */
|
||||
@@ -97,6 +99,13 @@ i915_gem_create(struct anv_device *device,
|
||||
&set_pat_param.base);
|
||||
}
|
||||
|
||||
struct drm_i915_gem_create_ext_protected_content protected_param = { 0 };
|
||||
if (alloc_flags & ANV_BO_ALLOC_PROTECTED) {
|
||||
intel_i915_gem_add_ext(&gem_create.extensions,
|
||||
I915_GEM_CREATE_EXT_PROTECTED_CONTENT,
|
||||
&protected_param.base);
|
||||
}
|
||||
|
||||
if (intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CREATE_EXT, &gem_create))
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ xe_gem_create(struct anv_device *device,
|
||||
enum anv_bo_alloc_flags alloc_flags,
|
||||
uint64_t *actual_size)
|
||||
{
|
||||
/* TODO: protected content */
|
||||
assert((alloc_flags & ANV_BO_ALLOC_PROTECTED) == 0);
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (alloc_flags & ANV_BO_ALLOC_SCANOUT)
|
||||
flags |= XE_GEM_CREATE_FLAG_SCANOUT;
|
||||
|
||||
Reference in New Issue
Block a user