summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-I Wu <olvaffe@gmail.com>2021-04-22 21:07:27 -0700
committerChia-I Wu <olvaffe@gmail.com>2021-04-28 12:58:58 -0700
commitf41a79f9481b20975bd4dc0b26100e0598214a1a (patch)
tree803bed0ed8f8ac8e23f4d61bedfeb072d6c47656
parentc62026165cd2c34b0f7b17c8d10b10f7de1cea4b (diff)
venus: use sparse array to manage vn_renderer_bo
It should be faster. More importantly, we want to use it to keep track of all BOs for correct dmabuf import. Signed-off-by: Chia-I Wu <olvaffe@gmail.com> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10437>
-rw-r--r--src/virtio/vulkan/vn_renderer_virtgpu.c17
-rw-r--r--src/virtio/vulkan/vn_renderer_vtest.c14
2 files changed, 9 insertions, 22 deletions
diff --git a/src/virtio/vulkan/vn_renderer_virtgpu.c b/src/virtio/vulkan/vn_renderer_virtgpu.c
index dc7192e47b5..69c298e1490 100644
--- a/src/virtio/vulkan/vn_renderer_virtgpu.c
+++ b/src/virtio/vulkan/vn_renderer_virtgpu.c
@@ -107,6 +107,7 @@ struct virtgpu {
* virtio_gpu_resource_id_get)
*/
struct util_sparse_array shmem_array;
+ struct util_sparse_array bo_array;
};
#ifdef SIMULATE_SYNCOBJ
@@ -1105,8 +1106,6 @@ virtgpu_bo_destroy(struct vn_renderer *renderer, struct vn_renderer_bo *_bo)
if (bo->base.mmap_ptr)
munmap(bo->base.mmap_ptr, bo->base.mmap_size);
virtgpu_ioctl_gem_close(gpu, bo->gem_handle);
-
- free(bo);
}
static uint32_t
@@ -1164,10 +1163,7 @@ virtgpu_bo_create_from_dmabuf(struct vn_renderer *renderer,
size = 0;
}
- struct virtgpu_bo *bo = calloc(1, sizeof(*bo));
- if (!bo)
- goto fail;
-
+ struct virtgpu_bo *bo = util_sparse_array_get(&gpu->bo_array, gem_handle);
*bo = (struct virtgpu_bo){
.base = {
.refcount = 1,
@@ -1206,12 +1202,7 @@ virtgpu_bo_create_from_device_memory(
if (!gem_handle)
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
- struct virtgpu_bo *bo = calloc(1, sizeof(*bo));
- if (!bo) {
- virtgpu_ioctl_gem_close(gpu, gem_handle);
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
-
+ struct virtgpu_bo *bo = util_sparse_array_get(&gpu->bo_array, gem_handle);
*bo = (struct virtgpu_bo){
.base = {
.refcount = 1,
@@ -1341,6 +1332,7 @@ virtgpu_destroy(struct vn_renderer *renderer,
close(gpu->fd);
util_sparse_array_finish(&gpu->shmem_array);
+ util_sparse_array_finish(&gpu->bo_array);
vk_free(alloc, gpu);
}
@@ -1499,6 +1491,7 @@ virtgpu_init(struct virtgpu *gpu)
{
util_sparse_array_init(&gpu->shmem_array, sizeof(struct virtgpu_shmem),
1024);
+ util_sparse_array_init(&gpu->bo_array, sizeof(struct virtgpu_bo), 1024);
VkResult result = virtgpu_open(gpu);
if (result == VK_SUCCESS)
diff --git a/src/virtio/vulkan/vn_renderer_vtest.c b/src/virtio/vulkan/vn_renderer_vtest.c
index f86001eb0bc..e0971785d1c 100644
--- a/src/virtio/vulkan/vn_renderer_vtest.c
+++ b/src/virtio/vulkan/vn_renderer_vtest.c
@@ -64,6 +64,7 @@ struct vtest {
} capset;
struct util_sparse_array shmem_array;
+ struct util_sparse_array bo_array;
};
static int
@@ -742,8 +743,6 @@ vtest_bo_destroy(struct vn_renderer *renderer, struct vn_renderer_bo *_bo)
mtx_lock(&vtest->sock_mutex);
vtest_vcmd_resource_unref(vtest, bo->base.res_id);
mtx_unlock(&vtest->sock_mutex);
-
- free(bo);
}
static uint32_t
@@ -780,14 +779,7 @@ vtest_bo_create_from_device_memory(
assert(res_id > 0 && res_fd >= 0);
mtx_unlock(&vtest->sock_mutex);
- struct vtest_bo *bo = calloc(1, sizeof(*bo));
- if (!bo) {
- mtx_lock(&vtest->sock_mutex);
- vtest_vcmd_resource_unref(vtest, res_id);
- mtx_unlock(&vtest->sock_mutex);
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
-
+ struct vtest_bo *bo = util_sparse_array_get(&vtest->bo_array, res_id);
*bo = (struct vtest_bo){
.base = {
.refcount = 1,
@@ -966,6 +958,7 @@ vtest_destroy(struct vn_renderer *renderer,
mtx_destroy(&vtest->sock_mutex);
util_sparse_array_finish(&vtest->shmem_array);
+ util_sparse_array_finish(&vtest->bo_array);
vk_free(alloc, vtest);
}
@@ -1023,6 +1016,7 @@ vtest_init(struct vtest *vtest)
{
util_sparse_array_init(&vtest->shmem_array, sizeof(struct vtest_shmem),
1024);
+ util_sparse_array_init(&vtest->bo_array, sizeof(struct vtest_bo), 1024);
mtx_init(&vtest->sock_mutex, mtx_plain);
vtest->sock_fd =