gallium/u_queue: add optional cleanup callback
authorRob Clark <robdclark@gmail.com>
Wed, 13 Jul 2016 16:17:05 +0000 (12:17 -0400)
committerRob Clark <robdclark@gmail.com>
Sat, 16 Jul 2016 14:00:04 +0000 (10:00 -0400)
Adds a second optional cleanup callback, called after the fence is
signaled.  This is needed if, for example, the queue has the last
reference to the object that embeds the util_queue_fence.  In this
case we cannot drop the ref in the main callback, since that would
result in the fence being destroyed before it is signaled.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_queue.c
src/gallium/auxiliary/util/u_queue.h
src/gallium/drivers/radeonsi/si_state_shaders.c
src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
src/gallium/winsys/radeon/drm/radeon_drm_cs.c

index ac3afa177734b2db56c38fc28866e17cee9afde3..838464fb9a6a88d7f82b2a30ea1bedb927e2d519 100644 (file)
@@ -91,6 +91,8 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
       if (job.job) {
          job.execute(job.job, thread_index);
          util_queue_fence_signal(job.fence);
+         if (job.cleanup)
+            job.cleanup(job.job, thread_index);
       }
    }
 
@@ -213,7 +215,8 @@ void
 util_queue_add_job(struct util_queue *queue,
                    void *job,
                    struct util_queue_fence *fence,
-                   util_queue_execute_func execute)
+                   util_queue_execute_func execute,
+                   util_queue_execute_func cleanup)
 {
    struct util_queue_job *ptr;
 
@@ -232,6 +235,7 @@ util_queue_add_job(struct util_queue *queue,
    ptr->job = job;
    ptr->fence = fence;
    ptr->execute = execute;
+   ptr->cleanup = cleanup;
    queue->write_idx = (queue->write_idx + 1) % queue->max_jobs;
 
    queue->num_queued++;
index f70d6466887b9d6fc3d2e7b83d5c74f22d5fd51d..59646cc298be0b10f8636c77b9161eb8cb46df56 100644 (file)
@@ -50,6 +50,7 @@ struct util_queue_job {
    void *job;
    struct util_queue_fence *fence;
    util_queue_execute_func execute;
+   util_queue_execute_func cleanup;
 };
 
 /* Put this into your context. */
@@ -75,10 +76,13 @@ 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);
 
+/* optional cleanup callback is called after fence is signaled: */
 void util_queue_add_job(struct util_queue *queue,
                         void *job,
                         struct util_queue_fence *fence,
-                        util_queue_execute_func execute);
+                        util_queue_execute_func execute,
+                        util_queue_execute_func cleanup);
+
 void util_queue_job_wait(struct util_queue_fence *fence);
 
 /* util_queue needs to be cleared to zeroes for this to work */
index c24130dab9c6f88219aeea163282adbbaf7b3716..a4232961d0bcbadc04ba39596a785517abb8a096 100644 (file)
@@ -1330,7 +1330,8 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
                si_init_shader_selector_async(sel, -1);
        else
                util_queue_add_job(&sscreen->shader_compiler_queue, sel,
-                                   &sel->ready, si_init_shader_selector_async);
+                                   &sel->ready, si_init_shader_selector_async,
+                                   NULL);
 
        return sel;
 }
index 1a094fd8d218b243b4fc592c763fb34543c68552..fb517b9ac54c05262c57c7b26825fb4cbc68aab8 100644 (file)
@@ -1058,7 +1058,7 @@ static int amdgpu_cs_flush(struct radeon_winsys_cs *rcs,
       if ((flags & RADEON_FLUSH_ASYNC) &&
           util_queue_is_initialized(&ws->cs_queue)) {
          util_queue_add_job(&ws->cs_queue, cs, &cs->flush_completed,
-                            amdgpu_cs_submit_ib);
+                            amdgpu_cs_submit_ib, NULL);
       } else {
          amdgpu_cs_submit_ib(cs, 0);
          error_code = cs->cst->error_code;
index 767c263a33d09987746e7a55b04db909458a3a58..15c3e5cd0d0401153cbb2a53f1718a75491adcc7 100644 (file)
@@ -587,7 +587,7 @@ static int 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,
-                               radeon_drm_cs_emit_ioctl_oneshot);
+                               radeon_drm_cs_emit_ioctl_oneshot, NULL);
             if (!(flags & RADEON_FLUSH_ASYNC))
                 radeon_drm_cs_sync_flush(rcs);
         } else {