aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gallium/drivers/freedreno/freedreno_batch.c6
-rw-r--r--src/gallium/drivers/nouveau/nv30/nvfx_fragprog.c2
-rw-r--r--src/gallium/drivers/nouveau/nv30/nvfx_vertprog.c2
-rw-r--r--src/gallium/drivers/nouveau/nv50/nv50_context.c2
-rw-r--r--src/gallium/drivers/nouveau/nvc0/nvc0_context.c2
-rw-r--r--src/gallium/state_trackers/va/surface.c2
-rw-r--r--src/util/u_dynarray.h47
7 files changed, 45 insertions, 18 deletions
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.c b/src/gallium/drivers/freedreno/freedreno_batch.c
index 7c7a45be84d..c2142b5a214 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.c
+++ b/src/gallium/drivers/freedreno/freedreno_batch.c
@@ -76,14 +76,14 @@ batch_init(struct fd_batch *batch)
batch->max_scissor.minx = batch->max_scissor.miny = ~0;
batch->max_scissor.maxx = batch->max_scissor.maxy = 0;
- util_dynarray_init(&batch->draw_patches);
+ util_dynarray_init(&batch->draw_patches, NULL);
if (is_a3xx(ctx->screen))
- util_dynarray_init(&batch->rbrc_patches);
+ util_dynarray_init(&batch->rbrc_patches, NULL);
assert(batch->resources->entries == 0);
- util_dynarray_init(&batch->samples);
+ util_dynarray_init(&batch->samples, NULL);
}
struct fd_batch *
diff --git a/src/gallium/drivers/nouveau/nv30/nvfx_fragprog.c b/src/gallium/drivers/nouveau/nv30/nvfx_fragprog.c
index 61a5701284d..278a8a4a430 100644
--- a/src/gallium/drivers/nouveau/nv30/nvfx_fragprog.c
+++ b/src/gallium/drivers/nouveau/nv30/nvfx_fragprog.c
@@ -1119,7 +1119,7 @@ _nvfx_fragprog_translate(uint16_t oclass, struct nv30_fragprog *fp)
goto out_err;
tgsi_parse_init(&parse, fp->pipe.tokens);
- util_dynarray_init(&insns);
+ util_dynarray_init(&insns, NULL);
while (!tgsi_parse_end_of_tokens(&parse)) {
tgsi_parse_token(&parse);
diff --git a/src/gallium/drivers/nouveau/nv30/nvfx_vertprog.c b/src/gallium/drivers/nouveau/nv30/nvfx_vertprog.c
index 03d711a4cec..bec9975de9d 100644
--- a/src/gallium/drivers/nouveau/nv30/nvfx_vertprog.c
+++ b/src/gallium/drivers/nouveau/nv30/nvfx_vertprog.c
@@ -998,7 +998,7 @@ _nvfx_vertprog_translate(uint16_t oclass, struct nv30_vertprog *vp)
vpc->cvtx_idx = vpc->hpos_idx;
}
- util_dynarray_init(&insns);
+ util_dynarray_init(&insns, NULL);
tgsi_parse_init(&parse, vp->pipe.tokens);
while (!tgsi_parse_end_of_tokens(&parse)) {
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_context.c b/src/gallium/drivers/nouveau/nv50/nv50_context.c
index 1ca6a0a178a..61243438fcb 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_context.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_context.c
@@ -377,7 +377,7 @@ nv50_create(struct pipe_screen *pscreen, void *priv, unsigned ctxflags)
nv50->base.scratch.bo_size = 2 << 20;
- util_dynarray_init(&nv50->global_residents);
+ util_dynarray_init(&nv50->global_residents, NULL);
return pipe;
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
index 59edd3d7e6e..d5ef5851daa 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
@@ -461,7 +461,7 @@ nvc0_create(struct pipe_screen *pscreen, void *priv, unsigned ctxflags)
memset(nvc0->tex_handles, ~0, sizeof(nvc0->tex_handles));
- util_dynarray_init(&nvc0->global_residents);
+ util_dynarray_init(&nvc0->global_residents, NULL);
return pipe;
diff --git a/src/gallium/state_trackers/va/surface.c b/src/gallium/state_trackers/va/surface.c
index c7d6ef7c8c3..f968e9ede17 100644
--- a/src/gallium/state_trackers/va/surface.c
+++ b/src/gallium/state_trackers/va/surface.c
@@ -749,7 +749,7 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format,
assert(0);
}
- util_dynarray_init(&surf->subpics);
+ util_dynarray_init(&surf->subpics, NULL);
surfaces[i] = handle_table_add(drv->htab, surf);
if (!surfaces[i]) {
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
index 9143c5a60df..ad3889a7c80 100644
--- a/src/util/u_dynarray.h
+++ b/src/util/u_dynarray.h
@@ -28,6 +28,7 @@
#define U_DYNARRAY_H
#include <stdlib.h>
+#include "ralloc.h"
/* A zero-initialized version of this is guaranteed to represent an
* empty array.
@@ -37,37 +38,51 @@
*/
struct util_dynarray
{
+ void *mem_ctx;
void *data;
unsigned size;
unsigned capacity;
};
static inline void
-util_dynarray_init(struct util_dynarray *buf)
+util_dynarray_init(struct util_dynarray *buf, void *mem_ctx)
{
memset(buf, 0, sizeof(*buf));
+ buf->mem_ctx = mem_ctx;
}
static inline void
util_dynarray_fini(struct util_dynarray *buf)
{
if (buf->data) {
- free(buf->data);
- util_dynarray_init(buf);
+ if (buf->mem_ctx) {
+ ralloc_free(buf->data);
+ } else {
+ free(buf->data);
+ }
+ util_dynarray_init(buf, buf->mem_ctx);
}
}
+#define DYN_ARRAY_INITIAL_SIZE 64
+
/* use util_dynarray_trim to reduce the allocated storage */
static inline void *
util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
{
void *p;
if (newsize > buf->capacity) {
- unsigned newcap = buf->capacity << 1;
- if (newsize > newcap)
- newcap = newsize;
- buf->data = realloc(buf->data, newcap);
- buf->capacity = newcap;
+ if (buf->capacity == 0)
+ buf->capacity = DYN_ARRAY_INITIAL_SIZE;
+
+ while (newsize > buf->capacity)
+ buf->capacity *= 2;
+
+ if (buf->mem_ctx) {
+ buf->data = reralloc_size(buf->mem_ctx, buf->data, buf->capacity);
+ } else {
+ buf->data = realloc(buf->data, buf->capacity);
+ }
}
p = (void *)((char *)buf->data + buf->size);
@@ -87,10 +102,18 @@ util_dynarray_trim(struct util_dynarray *buf)
{
if (buf->size != buf->capacity) {
if (buf->size) {
- buf->data = realloc(buf->data, buf->size);
+ if (buf->mem_ctx) {
+ reralloc_size(buf->mem_ctx, buf->data, buf->size);
+ } else {
+ buf->data = realloc(buf->data, buf->size);
+ }
buf->capacity = buf->size;
} else {
- free(buf->data);
+ if (buf->mem_ctx) {
+ ralloc_free(buf->data);
+ } else {
+ free(buf->data);
+ }
buf->data = 0;
buf->capacity = 0;
}
@@ -107,5 +130,9 @@ util_dynarray_trim(struct util_dynarray *buf)
#define util_dynarray_begin(buf) ((buf)->data)
#define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size))
+#define util_dynarray_foreach(buf, type, elem) \
+ for (type *elem = (type *)(buf)->data; \
+ elem < (type *)((char *)(buf)->data + (buf)->size); elem++)
+
#endif /* U_DYNARRAY_H */