Module: Mesa Branch: main Commit: fb3171b653bd39a6521928fd8d41df1972e6b43d URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fb3171b653bd39a6521928fd8d41df1972e6b43d
Author: Marek Olšák <marek.ol...@amd.com> Date: Sun Jan 7 16:01:58 2024 -0500 winsys/amdgpu: add more fence_reference helpers Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-pra...@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27060> --- src/gallium/winsys/amdgpu/drm/amdgpu_cs.c | 11 +++++++++++ src/gallium/winsys/amdgpu/drm/amdgpu_cs.h | 31 +++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c index 4b52c99894a..acdad8bca0d 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c @@ -15,6 +15,17 @@ /* FENCES */ +void amdgpu_fence_destroy(struct amdgpu_fence *fence) +{ + if (amdgpu_fence_is_syncobj(fence)) + amdgpu_cs_destroy_syncobj(fence->ws->dev, fence->syncobj); + else + amdgpu_ctx_reference(&fence->ctx, NULL); + + util_queue_fence_destroy(&fence->submitted); + FREE(fence); +} + static struct pipe_fence_handle * amdgpu_fence_create(struct amdgpu_cs *cs) { diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h index 2476c2f7fc2..0ad4e62831b 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h @@ -173,6 +173,8 @@ struct amdgpu_fence { uint_seq_no queue_seq_no; /* winsys-generated sequence number */ }; +void amdgpu_fence_destroy(struct amdgpu_fence *fence); + static inline bool amdgpu_fence_is_syncobj(struct amdgpu_fence *fence) { return fence->ctx == NULL; @@ -197,20 +199,29 @@ static inline void amdgpu_fence_reference(struct pipe_fence_handle **dst, struct amdgpu_fence **adst = (struct amdgpu_fence **)dst; struct amdgpu_fence *asrc = (struct amdgpu_fence *)src; - if (pipe_reference(&(*adst)->reference, &asrc->reference)) { - struct amdgpu_fence *fence = *adst; - - if (amdgpu_fence_is_syncobj(fence)) - amdgpu_cs_destroy_syncobj(fence->ws->dev, fence->syncobj); - else - amdgpu_ctx_reference(&fence->ctx, NULL); + if (pipe_reference(&(*adst)->reference, &asrc->reference)) + amdgpu_fence_destroy(*adst); - util_queue_fence_destroy(&fence->submitted); - FREE(fence); - } *adst = asrc; } +/* Same as amdgpu_fence_reference, but ignore the value in *dst. */ +static inline void amdgpu_fence_set_reference(struct pipe_fence_handle **dst, + struct pipe_fence_handle *src) +{ + *dst = src; + pipe_reference(NULL, &((struct amdgpu_fence *)src)->reference); /* only increment refcount */ +} + +/* Unreference dst, but don't assign anything. */ +static inline void amdgpu_fence_drop_reference(struct pipe_fence_handle *dst) +{ + struct amdgpu_fence *adst = (struct amdgpu_fence *)dst; + + if (pipe_reference(&adst->reference, NULL)) /* only decrement refcount */ + amdgpu_fence_destroy(adst); +} + struct amdgpu_cs_buffer * amdgpu_lookup_buffer_any_type(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo);