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>
#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"
.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,
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;
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:
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++)
#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)
return NULL;
}
}
+
+inline enum intel_kmd_type
+anv_kmd_type_get(struct anv_device *device)
+{
+ return device->info->kmd_type;
+}
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);
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;
'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',
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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);
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++)