freedreno: small cleanup
Make cheezy growable array thing less open-coded before adding more. Signed-off-by: Rob Clark <robclark@freedesktop.org>main
parent
fcbf206aa2
commit
2932a03180
|
@ -101,4 +101,30 @@ static inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)
|
|||
tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Stupid/simple growable array implementation:
|
||||
*/
|
||||
|
||||
static inline void *
|
||||
grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
|
||||
{
|
||||
if ((nr + 1) > *max) {
|
||||
if ((*max * 2) < (nr + 1))
|
||||
*max = nr + 5;
|
||||
else
|
||||
*max = *max * 2;
|
||||
ptr = realloc(ptr, *max * sz);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#define DECLARE_ARRAY(type, name) \
|
||||
unsigned nr_ ## name, max_ ## name; \
|
||||
type * name;
|
||||
|
||||
#define APPEND(x, name) ({ \
|
||||
(x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
|
||||
(x)->nr_ ## name ++; \
|
||||
})
|
||||
|
||||
#endif /* MSM_PRIV_H_ */
|
||||
|
|
|
@ -42,8 +42,7 @@ struct msm_cmd {
|
|||
struct fd_bo *ring_bo;
|
||||
|
||||
/* reloc's table: */
|
||||
struct drm_msm_gem_submit_reloc *relocs;
|
||||
uint32_t nr_relocs, max_relocs;
|
||||
DECLARE_ARRAY(struct drm_msm_gem_submit_reloc, relocs);
|
||||
|
||||
uint32_t size;
|
||||
};
|
||||
|
@ -58,22 +57,18 @@ struct msm_ringbuffer {
|
|||
*/
|
||||
struct {
|
||||
/* bo's table: */
|
||||
struct drm_msm_gem_submit_bo *bos;
|
||||
uint32_t nr_bos, max_bos;
|
||||
DECLARE_ARRAY(struct drm_msm_gem_submit_bo, bos);
|
||||
|
||||
/* cmd's table: */
|
||||
struct drm_msm_gem_submit_cmd *cmds;
|
||||
uint32_t nr_cmds, max_cmds;
|
||||
DECLARE_ARRAY(struct drm_msm_gem_submit_cmd, cmds);
|
||||
} submit;
|
||||
|
||||
/* should have matching entries in submit.bos: */
|
||||
/* Note, only in parent ringbuffer */
|
||||
struct fd_bo **bos;
|
||||
uint32_t nr_bos, max_bos;
|
||||
DECLARE_ARRAY(struct fd_bo *, bos);
|
||||
|
||||
/* should have matching entries in submit.cmds: */
|
||||
struct msm_cmd **cmds;
|
||||
uint32_t nr_cmds, max_cmds;
|
||||
DECLARE_ARRAY(struct msm_cmd *, cmds);
|
||||
|
||||
/* List of physical cmdstream buffers (msm_cmd) assocated with this
|
||||
* logical fd_ringbuffer.
|
||||
|
@ -170,23 +165,6 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
|
||||
{
|
||||
if ((nr + 1) > *max) {
|
||||
if ((*max * 2) < (nr + 1))
|
||||
*max = nr + 5;
|
||||
else
|
||||
*max = *max * 2;
|
||||
ptr = realloc(ptr, *max * sz);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#define APPEND(x, name) ({ \
|
||||
(x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
|
||||
(x)->nr_ ## name ++; \
|
||||
})
|
||||
|
||||
static struct msm_cmd *current_cmd(struct fd_ringbuffer *ring)
|
||||
{
|
||||
struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring);
|
||||
|
|
Loading…
Reference in New Issue