From d531c8d22a52fa08209069c70dbaf6650682a24e Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sat, 17 Apr 2021 11:23:27 -0700 Subject: [PATCH] freedreno/drm: Reference count submits To merge submits, we'll need drm to internally hold an extra reference to the submit. Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_priv.h | 1 + src/freedreno/drm/freedreno_ringbuffer.c | 17 +++++++++++++++-- src/freedreno/drm/freedreno_ringbuffer.h | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index 19abcc12736..545006f822c 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -194,6 +194,7 @@ struct fd_submit_funcs { }; struct fd_submit { + int32_t refcnt; struct fd_pipe *pipe; const struct fd_submit_funcs *funcs; diff --git a/src/freedreno/drm/freedreno_ringbuffer.c b/src/freedreno/drm/freedreno_ringbuffer.c index 2e3000b5fd7..49f9a6df3ff 100644 --- a/src/freedreno/drm/freedreno_ringbuffer.c +++ b/src/freedreno/drm/freedreno_ringbuffer.c @@ -33,15 +33,28 @@ struct fd_submit * fd_submit_new(struct fd_pipe *pipe) { - return pipe->funcs->submit_new(pipe); + struct fd_submit *submit = pipe->funcs->submit_new(pipe); + submit->refcnt = 1; + return submit; } void fd_submit_del(struct fd_submit *submit) { + if (!p_atomic_dec_zero(&submit->refcnt)) + return; + if (submit->primary) fd_ringbuffer_del(submit->primary); - return submit->funcs->destroy(submit); + + submit->funcs->destroy(submit); +} + +struct fd_submit * +fd_submit_ref(struct fd_submit *submit) +{ + p_atomic_inc(&submit->refcnt); + return submit; } int diff --git a/src/freedreno/drm/freedreno_ringbuffer.h b/src/freedreno/drm/freedreno_ringbuffer.h index cc0b1095811..d4a84729ec1 100644 --- a/src/freedreno/drm/freedreno_ringbuffer.h +++ b/src/freedreno/drm/freedreno_ringbuffer.h @@ -85,6 +85,8 @@ struct fd_submit *fd_submit_new(struct fd_pipe *pipe); */ void fd_submit_del(struct fd_submit *submit); +struct fd_submit * fd_submit_ref(struct fd_submit *submit); + /* Allocate a new rb from the submit. */ struct fd_ringbuffer *fd_submit_new_ringbuffer(struct fd_submit *submit, uint32_t size,