anv: Implement Xe functions to create and destroy VM

Also using the vm_id to create gem buffers.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21698>
This commit is contained in:
José Roberto de Souza
2023-02-09 08:44:04 -08:00
committed by Marge Bot
parent d5f767edf9
commit 149e945ad4
8 changed files with 130 additions and 5 deletions
+34 -3
View File
@@ -59,6 +59,7 @@
#include "perf/intel_perf.h"
#include "i915/anv_device.h"
#include "xe/anv_device.h"
#include "genxml/gen7_pack.h"
#include "genxml/genX_bits.h"
@@ -3163,6 +3164,36 @@ static struct intel_mapped_pinned_buffer_alloc aux_map_allocator = {
.free = intel_aux_map_buffer_free,
};
static VkResult
anv_device_setup_context_or_vm(struct anv_device *device,
const VkDeviceCreateInfo *pCreateInfo,
const uint32_t num_queues)
{
switch (anv_kmd_type_get(device)) {
case INTEL_KMD_TYPE_I915:
return anv_i915_device_setup_context(device, pCreateInfo, num_queues);
case INTEL_KMD_TYPE_XE:
return anv_xe_device_setup_vm(device);
default:
unreachable("Missing");
return VK_ERROR_UNKNOWN;
}
}
static bool
anv_device_destroy_context_or_vm(struct anv_device *device)
{
switch (anv_kmd_type_get(device)) {
case INTEL_KMD_TYPE_I915:
return intel_gem_destroy_context(device->fd, device->context_id);
case INTEL_KMD_TYPE_XE:
return anv_xe_device_destroy_vm(device);
default:
unreachable("Missing");
return false;
}
}
VkResult anv_CreateDevice(
VkPhysicalDevice physicalDevice,
const VkDeviceCreateInfo* pCreateInfo,
@@ -3259,7 +3290,7 @@ VkResult anv_CreateDevice(
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
num_queues += pCreateInfo->pQueueCreateInfos[i].queueCount;
result = anv_i915_device_setup_context(device, pCreateInfo, num_queues);
result = anv_device_setup_context_or_vm(device, pCreateInfo, num_queues);
if (result != VK_SUCCESS)
goto fail_fd;
@@ -3636,7 +3667,7 @@ VkResult anv_CreateDevice(
anv_queue_finish(&device->queues[i]);
vk_free(&device->vk.alloc, device->queues);
fail_context_id:
intel_gem_destroy_context(device->fd, device->context_id);
anv_device_destroy_context_or_vm(device);
fail_fd:
close(device->fd);
fail_device:
@@ -3728,7 +3759,7 @@ void anv_DestroyDevice(
anv_queue_finish(&device->queues[i]);
vk_free(&device->vk.alloc, device->queues);
intel_gem_destroy_context(device->fd, device->context_id);
anv_device_destroy_context_or_vm(device);
if (INTEL_DEBUG(DEBUG_BATCH)) {
for (unsigned i = 0; i < pdevice->queue.family_count; i++)
+7
View File
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include "anv_kmd_backend.h"
#include "anv_private.h"
const struct anv_kmd_backend *
anv_kmd_backend_get(enum intel_kmd_type type)
@@ -39,3 +40,9 @@ anv_kmd_backend_get(enum intel_kmd_type type)
return NULL;
}
}
inline enum intel_kmd_type
anv_kmd_type_get(struct anv_device *device)
{
return device->info->kmd_type;
}
+3
View File
@@ -68,6 +68,9 @@ struct anv_kmd_backend {
const struct anv_kmd_backend *anv_kmd_backend_get(enum intel_kmd_type type);
enum intel_kmd_type
anv_kmd_type_get(struct anv_device *device);
/* Internal functions, should only be called by anv_kmd_backend_get() */
const struct anv_kmd_backend *anv_i915_kmd_backend_get(void);
const struct anv_kmd_backend *anv_xe_kmd_backend_get(void);
+4 -1
View File
@@ -1127,7 +1127,10 @@ struct anv_device {
const struct intel_device_info * info;
const struct anv_kmd_backend * kmd_backend;
struct isl_device isl_dev;
uint32_t context_id;
union {
uint32_t context_id; /* i915 */
uint32_t vm_id; /* Xe */
};
int fd;
pthread_mutex_t vma_mutex;
+2
View File
@@ -138,6 +138,8 @@ libanv_files = files(
'layers/anv_doom64.c',
'layers/anv_hitman3.c',
'xe/anv_kmd_backend.c',
'xe/anv_device.c',
'xe/anv_device.h',
'anv_allocator.c',
'anv_android.h',
'anv_batch_chain.c',
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright © 2023 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "xe/anv_device.h"
#include "anv_private.h"
#include "drm-uapi/xe_drm.h"
bool anv_xe_device_destroy_vm(struct anv_device *device)
{
struct drm_xe_vm_destroy destroy = {
.vm_id = device->vm_id,
};
return intel_ioctl(device->fd, DRM_IOCTL_XE_VM_DESTROY, &destroy) == 0;
}
VkResult anv_xe_device_setup_vm(struct anv_device *device)
{
struct drm_xe_vm_create create = {
.flags = DRM_XE_VM_CREATE_SCRATCH_PAGE,
};
if (intel_ioctl(device->fd, DRM_IOCTL_XE_VM_CREATE, &create) != 0)
return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
"vm creation failed");
device->vm_id = create.vm_id;
return VK_SUCCESS;
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright © 2023 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <stdbool.h>
#include "vulkan/vulkan_core.h"
struct anv_device;
bool anv_xe_device_destroy_vm(struct anv_device *device);
VkResult anv_xe_device_setup_vm(struct anv_device *device);
+1 -1
View File
@@ -32,7 +32,7 @@ xe_gem_create(struct anv_device *device,
enum anv_bo_alloc_flags alloc_flags)
{
struct drm_xe_gem_create gem_create = {
.vm_id = 0,/* TODO: create VM */
.vm_id = device->vm_id,
.size = size,
};
for (uint16_t i = 0; i < regions_count; i++)