[Mesa-dev] [PATCH 6/6] gallium/u_queue: allow the execute function to differ per job
Marek Olšák
maraeo at gmail.com
Tue Jun 21 12:17:34 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
so that independent types of jobs can use the same queue.
---
src/gallium/auxiliary/util/u_queue.c | 12 ++++++------
src/gallium/auxiliary/util/u_queue.h | 10 ++++++----
src/gallium/winsys/amdgpu/drm/amdgpu_cs.c | 3 ++-
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 2 +-
src/gallium/winsys/radeon/drm/radeon_drm_cs.c | 3 ++-
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 3 +--
6 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_queue.c b/src/gallium/auxiliary/util/u_queue.c
index fbdd759..7d8f15df 100644
--- a/src/gallium/auxiliary/util/u_queue.c
+++ b/src/gallium/auxiliary/util/u_queue.c
@@ -85,7 +85,7 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
}
job = queue->jobs[queue->read_idx];
- queue->jobs[queue->read_idx].job = NULL;
+ memset(&queue->jobs[queue->read_idx], 0, sizeof(struct util_queue_job));
queue->read_idx = (queue->read_idx + 1) % queue->max_jobs;
queue->num_queued--;
@@ -93,7 +93,7 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
pipe_mutex_unlock(queue->lock);
if (job.job) {
- queue->execute_job(job.job, thread_index);
+ job.execute(job.job, thread_index);
util_queue_fence_signal(job.fence);
}
}
@@ -114,8 +114,7 @@ bool
util_queue_init(struct util_queue *queue,
const char *name,
unsigned max_jobs,
- unsigned num_threads,
- void (*execute_job)(void *, int))
+ unsigned num_threads)
{
unsigned i;
@@ -129,7 +128,6 @@ util_queue_init(struct util_queue *queue,
if (!queue->jobs)
goto fail;
- queue->execute_job = execute_job;
pipe_mutex_init(queue->lock);
queue->num_queued = 0;
@@ -217,7 +215,8 @@ util_queue_fence_destroy(struct util_queue_fence *fence)
void
util_queue_add_job(struct util_queue *queue,
void *job,
- struct util_queue_fence *fence)
+ struct util_queue_fence *fence,
+ util_queue_execute_func execute)
{
struct util_queue_job *ptr;
@@ -235,6 +234,7 @@ util_queue_add_job(struct util_queue *queue,
assert(ptr->job == NULL);
ptr->job = job;
ptr->fence = fence;
+ ptr->execute = execute;
queue->write_idx = (queue->write_idx + 1) % queue->max_jobs;
queue->num_queued++;
diff --git a/src/gallium/auxiliary/util/u_queue.h b/src/gallium/auxiliary/util/u_queue.h
index 750327e..f70d646 100644
--- a/src/gallium/auxiliary/util/u_queue.h
+++ b/src/gallium/auxiliary/util/u_queue.h
@@ -44,9 +44,12 @@ struct util_queue_fence {
int signalled;
};
+typedef void (*util_queue_execute_func)(void *job, int thread_index);
+
struct util_queue_job {
void *job;
struct util_queue_fence *fence;
+ util_queue_execute_func execute;
};
/* Put this into your context. */
@@ -62,21 +65,20 @@ struct util_queue {
int max_jobs;
int write_idx, read_idx; /* ring buffer pointers */
struct util_queue_job *jobs;
- void (*execute_job)(void *job, int thread_index);
};
bool util_queue_init(struct util_queue *queue,
const char *name,
unsigned max_jobs,
- unsigned num_threads,
- void (*execute_job)(void *, int));
+ unsigned num_threads);
void util_queue_destroy(struct util_queue *queue);
void util_queue_fence_init(struct util_queue_fence *fence);
void util_queue_fence_destroy(struct util_queue_fence *fence);
void util_queue_add_job(struct util_queue *queue,
void *job,
- struct util_queue_fence *fence);
+ struct util_queue_fence *fence,
+ util_queue_execute_func execute);
void util_queue_job_wait(struct util_queue_fence *fence);
/* util_queue needs to be cleared to zeroes for this to work */
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
index 5636f83..8c1e9fb 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
@@ -1052,7 +1052,8 @@ static void amdgpu_cs_flush(struct radeon_winsys_cs *rcs,
/* Submit. */
if ((flags & RADEON_FLUSH_ASYNC) &&
util_queue_is_initialized(&ws->cs_queue)) {
- util_queue_add_job(&ws->cs_queue, cs, &cs->flush_completed);
+ util_queue_add_job(&ws->cs_queue, cs, &cs->flush_completed,
+ amdgpu_cs_submit_ib);
} else {
amdgpu_cs_submit_ib(cs, 0);
}
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
index 8782665..2a0b66d 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
@@ -493,7 +493,7 @@ amdgpu_winsys_create(int fd, radeon_screen_create_t screen_create)
pipe_mutex_init(ws->bo_fence_lock);
if (sysconf(_SC_NPROCESSORS_ONLN) > 1 && debug_get_option_thread())
- util_queue_init(&ws->cs_queue, "amdgpu_cs", 8, 1, amdgpu_cs_submit_ib);
+ util_queue_init(&ws->cs_queue, "amdgpu_cs", 8, 1);
/* Create the screen at the end. The winsys must be initialized
* completely.
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
index 9532a6a..efefd75 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
@@ -586,7 +586,8 @@ static void radeon_drm_cs_flush(struct radeon_winsys_cs *rcs,
}
if (util_queue_is_initialized(&cs->ws->cs_queue)) {
- util_queue_add_job(&cs->ws->cs_queue, cs, &cs->flush_completed);
+ util_queue_add_job(&cs->ws->cs_queue, cs, &cs->flush_completed,
+ radeon_drm_cs_emit_ioctl_oneshot);
if (!(flags & RADEON_FLUSH_ASYNC))
radeon_drm_cs_sync_flush(rcs);
} else {
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index ea5d212..f5f9d42 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -783,8 +783,7 @@ radeon_drm_winsys_create(int fd, radeon_screen_create_t screen_create)
ws->info.gart_page_size = sysconf(_SC_PAGESIZE);
if (ws->num_cpus > 1 && debug_get_option_thread())
- util_queue_init(&ws->cs_queue, "radeon_cs", 8, 1,
- radeon_drm_cs_emit_ioctl_oneshot);
+ util_queue_init(&ws->cs_queue, "radeon_cs", 8, 1);
/* Create the screen at the end. The winsys must be initialized
* completely.
--
2.7.4
More information about the mesa-dev
mailing list