winsys/amdgpu: optimize out conditionals in amdgpu_lookup_buffer
Move them to a wrapper function. Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8849>
This commit is contained in:
parent
c9bc23d27a
commit
06b9dedfd9
|
@ -408,30 +408,18 @@ static unsigned amdgpu_cs_epilog_dws(struct amdgpu_cs *cs)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int amdgpu_lookup_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo)
|
||||
static int amdgpu_lookup_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo,
|
||||
struct amdgpu_cs_buffer *buffers, unsigned num_buffers)
|
||||
{
|
||||
unsigned hash = bo->unique_id & (ARRAY_SIZE(cs->buffer_indices_hashlist)-1);
|
||||
int i = cs->buffer_indices_hashlist[hash];
|
||||
struct amdgpu_cs_buffer *buffers;
|
||||
int num_buffers;
|
||||
|
||||
if (bo->bo) {
|
||||
buffers = cs->real_buffers;
|
||||
num_buffers = cs->num_real_buffers;
|
||||
} else if (!(bo->base.usage & RADEON_FLAG_SPARSE)) {
|
||||
buffers = cs->slab_buffers;
|
||||
num_buffers = cs->num_slab_buffers;
|
||||
} else {
|
||||
buffers = cs->sparse_buffers;
|
||||
num_buffers = cs->num_sparse_buffers;
|
||||
}
|
||||
|
||||
/* not found or found */
|
||||
if (i < 0 || (i < num_buffers && buffers[i].bo == bo))
|
||||
return i;
|
||||
|
||||
/* Hash collision, look for the BO in the list of buffers linearly. */
|
||||
for (i = num_buffers - 1; i >= 0; i--) {
|
||||
for (int i = num_buffers - 1; i >= 0; i--) {
|
||||
if (buffers[i].bo == bo) {
|
||||
/* Put this buffer in the hash list.
|
||||
* This will prevent additional hash collisions if there are
|
||||
|
@ -449,6 +437,25 @@ int amdgpu_lookup_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *
|
|||
return -1;
|
||||
}
|
||||
|
||||
int amdgpu_lookup_buffer_any_type(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo)
|
||||
{
|
||||
struct amdgpu_cs_buffer *buffers;
|
||||
int num_buffers;
|
||||
|
||||
if (bo->bo) {
|
||||
buffers = cs->real_buffers;
|
||||
num_buffers = cs->num_real_buffers;
|
||||
} else if (!(bo->base.usage & RADEON_FLAG_SPARSE)) {
|
||||
buffers = cs->slab_buffers;
|
||||
num_buffers = cs->num_slab_buffers;
|
||||
} else {
|
||||
buffers = cs->sparse_buffers;
|
||||
num_buffers = cs->num_sparse_buffers;
|
||||
}
|
||||
|
||||
return amdgpu_lookup_buffer(cs, bo, buffers, num_buffers);
|
||||
}
|
||||
|
||||
static int
|
||||
amdgpu_do_add_real_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo)
|
||||
{
|
||||
|
@ -494,7 +501,7 @@ amdgpu_lookup_or_add_real_buffer(struct radeon_cmdbuf *rcs, struct amdgpu_cs *ac
|
|||
{
|
||||
struct amdgpu_cs_context *cs = acs->csc;
|
||||
unsigned hash;
|
||||
int idx = amdgpu_lookup_buffer(cs, bo);
|
||||
int idx = amdgpu_lookup_buffer(cs, bo, cs->real_buffers, cs->num_real_buffers);
|
||||
|
||||
if (idx >= 0)
|
||||
return idx;
|
||||
|
@ -519,7 +526,7 @@ static int amdgpu_lookup_or_add_slab_buffer(struct radeon_cmdbuf *rcs,
|
|||
struct amdgpu_cs_context *cs = acs->csc;
|
||||
struct amdgpu_cs_buffer *buffer;
|
||||
unsigned hash;
|
||||
int idx = amdgpu_lookup_buffer(cs, bo);
|
||||
int idx = amdgpu_lookup_buffer(cs, bo, cs->slab_buffers, cs->num_slab_buffers);
|
||||
int real_idx;
|
||||
|
||||
if (idx >= 0)
|
||||
|
@ -569,7 +576,7 @@ static int amdgpu_lookup_or_add_sparse_buffer(struct radeon_cmdbuf *rcs,
|
|||
struct amdgpu_cs_context *cs = acs->csc;
|
||||
struct amdgpu_cs_buffer *buffer;
|
||||
unsigned hash;
|
||||
int idx = amdgpu_lookup_buffer(cs, bo);
|
||||
int idx = amdgpu_lookup_buffer(cs, bo, cs->sparse_buffers, cs->num_sparse_buffers);
|
||||
|
||||
if (idx >= 0)
|
||||
return idx;
|
||||
|
|
|
@ -208,7 +208,7 @@ static inline void amdgpu_fence_reference(struct pipe_fence_handle **dst,
|
|||
*adst = asrc;
|
||||
}
|
||||
|
||||
int amdgpu_lookup_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo);
|
||||
int amdgpu_lookup_buffer_any_type(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo);
|
||||
|
||||
static inline struct amdgpu_cs *
|
||||
amdgpu_cs(struct radeon_cmdbuf *rcs)
|
||||
|
@ -227,7 +227,7 @@ amdgpu_bo_is_referenced_by_cs(struct amdgpu_cs *cs,
|
|||
{
|
||||
int num_refs = bo->num_cs_references;
|
||||
return num_refs == bo->ws->num_cs ||
|
||||
(num_refs && amdgpu_lookup_buffer(cs->csc, bo) != -1);
|
||||
(num_refs && amdgpu_lookup_buffer_any_type(cs->csc, bo) != -1);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
|
@ -241,7 +241,7 @@ amdgpu_bo_is_referenced_by_cs_with_usage(struct amdgpu_cs *cs,
|
|||
if (!bo->num_cs_references)
|
||||
return false;
|
||||
|
||||
index = amdgpu_lookup_buffer(cs->csc, bo);
|
||||
index = amdgpu_lookup_buffer_any_type(cs->csc, bo);
|
||||
if (index == -1)
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue