From f3e514361c817037e5c26edaf4200a20a3442382 Mon Sep 17 00:00:00 2001 From: Nicolai Hähnle Date: Tue, 7 Feb 2017 17:53:49 +0100 Subject: winsys/amdgpu: extend amdgpu_add_fence to allow adding multiple fences MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák --- src/gallium/winsys/amdgpu/drm/amdgpu_cs.c | 35 +++++++++++++++++++++---------- src/gallium/winsys/amdgpu/drm/amdgpu_cs.h | 3 +++ 2 files changed, 27 insertions(+), 11 deletions(-) (limited to 'src/gallium/winsys') diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c index e2d3a45e6e6..bffa725427e 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c @@ -952,31 +952,44 @@ static void amdgpu_add_fence_dependency(struct amdgpu_cs *acs, bo->num_fences = new_num_fences; } -static void amdgpu_add_fence(struct amdgpu_winsys_bo *bo, - struct pipe_fence_handle *fence) +/* Add the given list of fences to the buffer's fence list. + * + * Must be called with the winsys bo_fence_lock held. + */ +void amdgpu_add_fences(struct amdgpu_winsys_bo *bo, + unsigned num_fences, + struct pipe_fence_handle **fences) { - if (bo->num_fences >= bo->max_fences) { - unsigned new_max_fences = MAX2(1, bo->max_fences * 2); + if (bo->num_fences + num_fences > bo->max_fences) { + unsigned new_max_fences = MAX2(bo->num_fences + num_fences, bo->max_fences * 2); struct pipe_fence_handle **new_fences = REALLOC(bo->fences, bo->num_fences * sizeof(*new_fences), new_max_fences * sizeof(*new_fences)); - if (new_fences) { + if (likely(new_fences)) { bo->fences = new_fences; bo->max_fences = new_max_fences; } else { - fprintf(stderr, "amdgpu_add_fence: allocation failure, dropping fence\n"); + unsigned drop; + + fprintf(stderr, "amdgpu_add_fences: allocation failure, dropping fence(s)\n"); if (!bo->num_fences) return; - bo->num_fences--; /* prefer to keep a more recent fence if possible */ + bo->num_fences--; /* prefer to keep the most recent fence if possible */ amdgpu_fence_reference(&bo->fences[bo->num_fences], NULL); + + drop = bo->num_fences + num_fences - bo->max_fences; + num_fences -= drop; + fences += drop; } } - bo->fences[bo->num_fences] = NULL; - amdgpu_fence_reference(&bo->fences[bo->num_fences], fence); - bo->num_fences++; + for (unsigned i = 0; i < num_fences; ++i) { + bo->fences[bo->num_fences] = NULL; + amdgpu_fence_reference(&bo->fences[bo->num_fences], fences[i]); + bo->num_fences++; + } } static void amdgpu_add_fence_dependencies_list(struct amdgpu_cs *acs, @@ -990,7 +1003,7 @@ static void amdgpu_add_fence_dependencies_list(struct amdgpu_cs *acs, amdgpu_add_fence_dependency(acs, buffer); p_atomic_inc(&bo->num_active_ioctls); - amdgpu_add_fence(bo, fence); + amdgpu_add_fences(bo, 1, &fence); } } diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h index bdf7cb2b8eb..242410f0821 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h @@ -240,6 +240,9 @@ amdgpu_bo_is_referenced_by_any_cs(struct amdgpu_winsys_bo *bo) bool amdgpu_fence_wait(struct pipe_fence_handle *fence, uint64_t timeout, bool absolute); +void amdgpu_add_fences(struct amdgpu_winsys_bo *bo, + unsigned num_fences, + struct pipe_fence_handle **fences); void amdgpu_cs_sync_flush(struct radeon_winsys_cs *rcs); void amdgpu_cs_init_functions(struct amdgpu_winsys *ws); void amdgpu_cs_submit_ib(void *job, int thread_index); -- cgit v1.2.3