Commit 51782878 authored by Chia-I Wu's avatar Chia-I Wu Committed by Marge Bot
Browse files

venus: move vn_renderer_sync_ops to vn_renderer



To follow vn_renderer_{shmem,bo}_ops.
Signed-off-by: Chia-I Wu's avatarChia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang's avatarYiwei Zhang <zzyiwei@chromium.org>
Part-of: <mesa/mesa!11253>
parent eddbb319
......@@ -23,35 +23,6 @@ struct vn_renderer_bo {
void *mmap_ptr;
};
enum vn_renderer_sync_flags {
VN_RENDERER_SYNC_SHAREABLE = 1u << 0,
VN_RENDERER_SYNC_BINARY = 1u << 1,
};
struct vn_renderer_sync_ops {
void (*destroy)(struct vn_renderer_sync *sync);
/* a sync can be initialized/released multiple times */
VkResult (*init)(struct vn_renderer_sync *sync,
uint64_t initial_val,
uint32_t flags);
VkResult (*init_syncobj)(struct vn_renderer_sync *sync,
int fd,
bool sync_file);
void (*release)(struct vn_renderer_sync *sync);
int (*export_syncobj)(struct vn_renderer_sync *sync, bool sync_file);
/* reset the counter */
VkResult (*reset)(struct vn_renderer_sync *sync, uint64_t initial_val);
/* read the current value from the counter */
VkResult (*read)(struct vn_renderer_sync *sync, uint64_t *val);
/* write a new value (larger than the current one) to the counter */
VkResult (*write)(struct vn_renderer_sync *sync, uint64_t val);
};
/*
* A sync consists of a uint64_t counter. The counter can be updated by CPU
* or by GPU. It can also be waited on by CPU or by GPU until it reaches
......@@ -62,8 +33,6 @@ struct vn_renderer_sync_ops {
*/
struct vn_renderer_sync {
uint32_t sync_id;
struct vn_renderer_sync_ops ops;
};
struct vn_renderer_info {
......@@ -160,8 +129,6 @@ struct vn_renderer_ops {
*/
VkResult (*wait)(struct vn_renderer *renderer,
const struct vn_renderer_wait *wait);
struct vn_renderer_sync *(*sync_create)(struct vn_renderer *renderer);
};
struct vn_renderer_shmem_ops {
......@@ -204,10 +171,53 @@ struct vn_renderer_bo_ops {
VkDeviceSize size);
};
enum vn_renderer_sync_flags {
VN_RENDERER_SYNC_SHAREABLE = 1u << 0,
VN_RENDERER_SYNC_BINARY = 1u << 1,
};
struct vn_renderer_sync_ops {
struct vn_renderer_sync *(*create)(struct vn_renderer *renderer);
void (*destroy)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync);
/* a sync can be initialized/released multiple times */
VkResult (*init)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t initial_val,
uint32_t flags);
VkResult (*init_syncobj)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
int fd,
bool sync_file);
void (*release)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync);
int (*export_syncobj)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
bool sync_file);
/* reset the counter */
VkResult (*reset)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t initial_val);
/* read the current value from the counter */
VkResult (*read)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t *val);
/* write a new value (larger than the current one) to the counter */
VkResult (*write)(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t val);
};
struct vn_renderer {
struct vn_renderer_ops ops;
struct vn_renderer_shmem_ops shmem_ops;
struct vn_renderer_bo_ops bo_ops;
struct vn_renderer_sync_ops sync_ops;
};
VkResult
......@@ -422,15 +432,16 @@ static inline VkResult
vn_renderer_sync_create_cpu(struct vn_renderer *renderer,
struct vn_renderer_sync **_sync)
{
struct vn_renderer_sync *sync = renderer->ops.sync_create(renderer);
struct vn_renderer_sync *sync = renderer->sync_ops.create(renderer);
if (!sync)
return VK_ERROR_OUT_OF_HOST_MEMORY;
const uint64_t initial_val = 0;
const uint32_t flags = 0;
VkResult result = sync->ops.init(sync, initial_val, flags);
VkResult result =
renderer->sync_ops.init(renderer, sync, initial_val, flags);
if (result != VK_SUCCESS) {
sync->ops.destroy(sync);
renderer->sync_ops.destroy(renderer, sync);
return result;
}
......@@ -444,16 +455,17 @@ vn_renderer_sync_create_fence(struct vn_renderer *renderer,
VkExternalFenceHandleTypeFlags external_handles,
struct vn_renderer_sync **_sync)
{
struct vn_renderer_sync *sync = renderer->ops.sync_create(renderer);
struct vn_renderer_sync *sync = renderer->sync_ops.create(renderer);
if (!sync)
return VK_ERROR_OUT_OF_HOST_MEMORY;
const uint64_t initial_val = signaled;
const uint32_t flags = VN_RENDERER_SYNC_BINARY |
(external_handles ? VN_RENDERER_SYNC_SHAREABLE : 0);
VkResult result = sync->ops.init(sync, initial_val, flags);
VkResult result =
renderer->sync_ops.init(renderer, sync, initial_val, flags);
if (result != VK_SUCCESS) {
sync->ops.destroy(sync);
renderer->sync_ops.destroy(renderer, sync);
return result;
}
......@@ -469,16 +481,17 @@ vn_renderer_sync_create_semaphore(
VkExternalSemaphoreHandleTypeFlags external_handles,
struct vn_renderer_sync **_sync)
{
struct vn_renderer_sync *sync = renderer->ops.sync_create(renderer);
struct vn_renderer_sync *sync = renderer->sync_ops.create(renderer);
if (!sync)
return VK_ERROR_OUT_OF_HOST_MEMORY;
const uint32_t flags =
(external_handles ? VN_RENDERER_SYNC_SHAREABLE : 0) |
(type == VK_SEMAPHORE_TYPE_BINARY ? VN_RENDERER_SYNC_BINARY : 0);
VkResult result = sync->ops.init(sync, initial_val, flags);
VkResult result =
renderer->sync_ops.init(renderer, sync, initial_val, flags);
if (result != VK_SUCCESS) {
sync->ops.destroy(sync);
renderer->sync_ops.destroy(renderer, sync);
return result;
}
......@@ -490,7 +503,7 @@ static inline VkResult
vn_renderer_sync_create_empty(struct vn_renderer *renderer,
struct vn_renderer_sync **_sync)
{
struct vn_renderer_sync *sync = renderer->ops.sync_create(renderer);
struct vn_renderer_sync *sync = renderer->sync_ops.create(renderer);
if (!sync)
return VK_ERROR_OUT_OF_HOST_MEMORY;
......@@ -501,55 +514,67 @@ vn_renderer_sync_create_empty(struct vn_renderer *renderer,
}
static inline void
vn_renderer_sync_destroy(struct vn_renderer_sync *sync)
vn_renderer_sync_destroy(struct vn_renderer *renderer,
struct vn_renderer_sync *sync)
{
sync->ops.destroy(sync);
renderer->sync_ops.destroy(renderer, sync);
}
static inline VkResult
vn_renderer_sync_init_signaled(struct vn_renderer_sync *sync)
vn_renderer_sync_init_signaled(struct vn_renderer *renderer,
struct vn_renderer_sync *sync)
{
const uint64_t initial_val = 1;
const uint32_t flags = VN_RENDERER_SYNC_BINARY;
return sync->ops.init(sync, initial_val, flags);
return renderer->sync_ops.init(renderer, sync, initial_val, flags);
}
static inline VkResult
vn_renderer_sync_init_syncobj(struct vn_renderer_sync *sync,
vn_renderer_sync_init_syncobj(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
int fd,
bool sync_file)
{
return sync->ops.init_syncobj(sync, fd, sync_file);
return renderer->sync_ops.init_syncobj(renderer, sync, fd, sync_file);
}
static inline void
vn_renderer_sync_release(struct vn_renderer_sync *sync)
vn_renderer_sync_release(struct vn_renderer *renderer,
struct vn_renderer_sync *sync)
{
sync->ops.release(sync);
renderer->sync_ops.release(renderer, sync);
}
static inline int
vn_renderer_sync_export_syncobj(struct vn_renderer_sync *sync, bool sync_file)
vn_renderer_sync_export_syncobj(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
bool sync_file)
{
return sync->ops.export_syncobj(sync, sync_file);
return renderer->sync_ops.export_syncobj(renderer, sync, sync_file);
}
static inline VkResult
vn_renderer_sync_reset(struct vn_renderer_sync *sync, uint64_t initial_val)
vn_renderer_sync_reset(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t initial_val)
{
return sync->ops.reset(sync, initial_val);
return renderer->sync_ops.reset(renderer, sync, initial_val);
}
static inline VkResult
vn_renderer_sync_read(struct vn_renderer_sync *sync, uint64_t *val)
vn_renderer_sync_read(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t *val)
{
return sync->ops.read(sync, val);
return renderer->sync_ops.read(renderer, sync, val);
}
static inline VkResult
vn_renderer_sync_write(struct vn_renderer_sync *sync, uint64_t val)
vn_renderer_sync_write(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t val)
{
return sync->ops.write(sync, val);
return renderer->sync_ops.write(renderer, sync, val);
}
#endif /* VN_RENDERER_H */
......@@ -65,7 +65,6 @@ struct virtgpu_bo {
struct virtgpu_sync {
struct vn_renderer_sync base;
struct virtgpu *gpu;
/*
* drm_syncobj is in one of these states
......@@ -895,10 +894,12 @@ virtgpu_ioctl_submit(struct virtgpu *gpu,
}
static VkResult
virtgpu_sync_write(struct vn_renderer_sync *_sync, uint64_t val)
virtgpu_sync_write(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t val)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
const int ret =
virtgpu_ioctl_syncobj_timeline_signal(gpu, sync->syncobj_handle, val);
......@@ -907,10 +908,12 @@ virtgpu_sync_write(struct vn_renderer_sync *_sync, uint64_t val)
}
static VkResult
virtgpu_sync_read(struct vn_renderer_sync *_sync, uint64_t *val)
virtgpu_sync_read(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t *val)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
const int ret =
virtgpu_ioctl_syncobj_query(gpu, sync->syncobj_handle, val);
......@@ -919,10 +922,12 @@ virtgpu_sync_read(struct vn_renderer_sync *_sync, uint64_t *val)
}
static VkResult
virtgpu_sync_reset(struct vn_renderer_sync *_sync, uint64_t initial_val)
virtgpu_sync_reset(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t initial_val)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
int ret = virtgpu_ioctl_syncobj_reset(gpu, sync->syncobj_handle);
if (!ret) {
......@@ -934,20 +939,23 @@ virtgpu_sync_reset(struct vn_renderer_sync *_sync, uint64_t initial_val)
}
static int
virtgpu_sync_export_syncobj(struct vn_renderer_sync *_sync, bool sync_file)
virtgpu_sync_export_syncobj(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
bool sync_file)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
return virtgpu_ioctl_syncobj_handle_to_fd(gpu, sync->syncobj_handle,
sync_file);
}
static void
virtgpu_sync_release(struct vn_renderer_sync *_sync)
virtgpu_sync_release(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
virtgpu_ioctl_syncobj_destroy(gpu, sync->syncobj_handle);
......@@ -956,12 +964,13 @@ virtgpu_sync_release(struct vn_renderer_sync *_sync)
}
static VkResult
virtgpu_sync_init_syncobj(struct vn_renderer_sync *_sync,
virtgpu_sync_init_syncobj(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
int fd,
bool sync_file)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
uint32_t syncobj_handle;
if (sync_file) {
......@@ -985,12 +994,13 @@ virtgpu_sync_init_syncobj(struct vn_renderer_sync *_sync,
}
static VkResult
virtgpu_sync_init(struct vn_renderer_sync *_sync,
virtgpu_sync_init(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t initial_val,
uint32_t flags)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
struct virtgpu *gpu = (struct virtgpu *)sync->gpu;
/* TODO */
if (flags & VN_RENDERER_SYNC_SHAREABLE)
......@@ -1006,7 +1016,7 @@ virtgpu_sync_init(struct vn_renderer_sync *_sync,
const int ret = virtgpu_ioctl_syncobj_timeline_signal(
gpu, sync->syncobj_handle, initial_val);
if (ret) {
virtgpu_sync_release(&sync->base);
virtgpu_sync_release(&gpu->base, &sync->base);
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
......@@ -1019,12 +1029,13 @@ virtgpu_sync_init(struct vn_renderer_sync *_sync,
}
static void
virtgpu_sync_destroy(struct vn_renderer_sync *_sync)
virtgpu_sync_destroy(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync)
{
struct virtgpu_sync *sync = (struct virtgpu_sync *)_sync;
if (sync->syncobj_handle)
virtgpu_sync_release(&sync->base);
virtgpu_sync_release(renderer, &sync->base);
free(sync);
}
......@@ -1032,23 +1043,10 @@ virtgpu_sync_destroy(struct vn_renderer_sync *_sync)
static struct vn_renderer_sync *
virtgpu_sync_create(struct vn_renderer *renderer)
{
struct virtgpu *gpu = (struct virtgpu *)renderer;
struct virtgpu_sync *sync = calloc(1, sizeof(*sync));
if (!sync)
return NULL;
sync->gpu = gpu;
sync->base.ops.destroy = virtgpu_sync_destroy;
sync->base.ops.init = virtgpu_sync_init;
sync->base.ops.init_syncobj = virtgpu_sync_init_syncobj;
sync->base.ops.release = virtgpu_sync_release;
sync->base.ops.export_syncobj = virtgpu_sync_export_syncobj;
sync->base.ops.reset = virtgpu_sync_reset;
sync->base.ops.read = virtgpu_sync_read;
sync->base.ops.write = virtgpu_sync_write;
return &sync->base;
}
......@@ -1555,7 +1553,6 @@ virtgpu_init(struct virtgpu *gpu)
gpu->base.ops.get_info = virtgpu_get_info;
gpu->base.ops.submit = virtgpu_submit;
gpu->base.ops.wait = virtgpu_wait;
gpu->base.ops.sync_create = virtgpu_sync_create;
gpu->base.shmem_ops.create = virtgpu_shmem_create;
gpu->base.shmem_ops.destroy = virtgpu_shmem_destroy;
......@@ -1569,6 +1566,16 @@ virtgpu_init(struct virtgpu *gpu)
gpu->base.bo_ops.flush = virtgpu_bo_flush;
gpu->base.bo_ops.invalidate = virtgpu_bo_invalidate;
gpu->base.sync_ops.create = virtgpu_sync_create;
gpu->base.sync_ops.destroy = virtgpu_sync_destroy;
gpu->base.sync_ops.init = virtgpu_sync_init;
gpu->base.sync_ops.init_syncobj = virtgpu_sync_init_syncobj;
gpu->base.sync_ops.release = virtgpu_sync_release;
gpu->base.sync_ops.export_syncobj = virtgpu_sync_export_syncobj;
gpu->base.sync_ops.reset = virtgpu_sync_reset;
gpu->base.sync_ops.read = virtgpu_sync_read;
gpu->base.sync_ops.write = virtgpu_sync_write;
return VK_SUCCESS;
}
......
......@@ -43,7 +43,6 @@ struct vtest_bo {
struct vtest_sync {
struct vn_renderer_sync base;
struct vtest *vtest;
};
struct vtest {
......@@ -575,10 +574,12 @@ vtest_vcmd_submit_cmd2(struct vtest *vtest,
}
static VkResult
vtest_sync_write(struct vn_renderer_sync *_sync, uint64_t val)
vtest_sync_write(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t val)
{
struct vtest *vtest = (struct vtest *)renderer;
struct vtest_sync *sync = (struct vtest_sync *)_sync;
struct vtest *vtest = sync->vtest;
mtx_lock(&vtest->sock_mutex);
vtest_vcmd_sync_write(vtest, sync->base.sync_id, val);
......@@ -588,10 +589,12 @@ vtest_sync_write(struct vn_renderer_sync *_sync, uint64_t val)
}
static VkResult
vtest_sync_read(struct vn_renderer_sync *_sync, uint64_t *val)
vtest_sync_read(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t *val)
{
struct vtest *vtest = (struct vtest *)renderer;
struct vtest_sync *sync = (struct vtest_sync *)_sync;
struct vtest *vtest = sync->vtest;
mtx_lock(&vtest->sock_mutex);
*val = vtest_vcmd_sync_read(vtest, sync->base.sync_id);
......@@ -601,17 +604,20 @@ vtest_sync_read(struct vn_renderer_sync *_sync, uint64_t *val)
}
static VkResult
vtest_sync_reset(struct vn_renderer_sync *sync, uint64_t initial_val)
vtest_sync_reset(struct vn_renderer *renderer,
struct vn_renderer_sync *sync,
uint64_t initial_val)
{
/* same as write */
return vtest_sync_write(sync, initial_val);
return vtest_sync_write(renderer, sync, initial_val);
}
static void
vtest_sync_release(struct vn_renderer_sync *_sync)
vtest_sync_release(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync)
{
struct vtest *vtest = (struct vtest *)renderer;
struct vtest_sync *sync = (struct vtest_sync *)_sync;
struct vtest *vtest = sync->vtest;
mtx_lock(&vtest->sock_mutex);
vtest_vcmd_sync_unref(vtest, sync->base.sync_id);
......@@ -621,12 +627,13 @@ vtest_sync_release(struct vn_renderer_sync *_sync)
}
static VkResult
vtest_sync_init(struct vn_renderer_sync *_sync,
vtest_sync_init(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync,
uint64_t initial_val,
uint32_t flags)
{
struct vtest *vtest = (struct vtest *)renderer;
struct vtest_sync *sync = (struct vtest_sync *)_sync;
struct vtest *vtest = sync->vtest;
mtx_lock(&vtest->sock_mutex);
sync->base.sync_id = vtest_vcmd_sync_create(vtest, initial_val);
......@@ -636,12 +643,13 @@ vtest_sync_init(struct vn_renderer_sync *_sync,
}
static void
vtest_sync_destroy(struct vn_renderer_sync *_sync)
vtest_sync_destroy(struct vn_renderer *renderer,
struct vn_renderer_sync *_sync)
{
struct vtest_sync *sync = (struct vtest_sync *)_sync;
if (sync->base.sync_id)
vtest_sync_release(&sync->base);
vtest_sync_release(renderer, &sync->base);
free(sync);
}
......@@ -649,23 +657,10 @@ vtest_sync_destroy(struct vn_renderer_sync *_sync)
static struct vn_renderer_sync *
vtest_sync_create(struct vn_renderer *renderer)
{
struct vtest *vtest = (struct vtest *)renderer;
struct vtest_sync *sync = calloc(1, sizeof(*sync));
if (!sync)
return NULL;
sync->vtest = vtest;
sync->base.ops.destroy = vtest_sync_destroy;
sync->base.ops.init = vtest_sync_init;
sync->base.ops.init_syncobj = NULL;
sync->base.ops.release = vtest_sync_release;
sync->base.ops.export_syncobj = NULL;
sync->base.ops.reset = vtest_sync_reset;
sync->base.ops.read = vtest_sync_read;
sync->base.ops.write = vtest_sync_write;
return &sync->base;
}
......@@ -1045,7 +1040,6 @@ vtest_init(struct vtest *vtest)
vtest->base.ops.get_info = vtest_get_info;
vtest->base.ops.submit = vtest_submit;
vtest->base.ops.wait = vtest_wait;
vtest->base.ops.sync_create = vtest_sync_create;
vtest->base.shmem_ops.create = vtest_shmem_create;
vtest->base.shmem_ops.destroy = vtest_shmem_destroy;
......@@ -1059,6 +1053,16 @@ vtest_init(struct vtest *vtest)
vtest->base.bo_ops.flush = vtest_bo_flush;
vtest->base.bo_ops.invalidate = vtest_bo_invalidate;
vtest->base.sync_ops.create = vtest_sync_create;
vtest->base.sync_ops.destroy = vtest_sync_destroy;
vtest->base.sync_ops.init = vtest_sync_init;
vtest->base.sync_ops.init_syncobj = NULL;
vtest->base.sync_ops.release = vtest_sync_release;
vtest->base.sync_ops.export_syncobj = NULL;
vtest->base.sync_ops.reset = vtest_sync_reset;
vtest->base.sync_ops.read = vtest_sync_read;
vtest->base.sync_ops.write = vtest_sync_write;
return VK_SUCCESS;
}
......
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