diff options
author | Nicolai Hähnle <[email protected]> | 2019-05-13 16:58:08 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-06-12 18:30:25 -0400 |
commit | de8a919702a377207e83434ab40d91c3013ed96c (patch) | |
tree | ba800d0375de39a447a6690b448ae52807ab01f3 /src/gallium/drivers/lima | |
parent | 71b45bae14be84ab09212c9ded758fa31e31e945 (diff) |
u_dynarray: turn util_dynarray_{grow, resize} into element-oriented macros
The main motivation for this change is API ergonomics: most operations
on dynarrays are really on elements, not on bytes, so it's weird to have
grow and resize as the odd operations out.
The secondary motivation is memory safety. Users of the old byte-oriented
functions would often multiply a number of elements with the element size,
which could overflow, and checking for overflow is tedious.
With this change, we only need to implement the overflow checks once.
The checks are cheap: since eltsize is a compile-time constant and the
functions should be inlined, they only add a single comparison and an
unlikely branch.
v2:
- ensure operations are no-op when allocation fails
- in util_dynarray_clone, call resize_bytes with a compile-time constant element size
v3:
- fix iris, lima, panfrost
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/gallium/drivers/lima')
-rw-r--r-- | src/gallium/drivers/lima/lima_draw.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_submit.c | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index c97258c592f..c87542d24bb 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -123,7 +123,7 @@ struct lima_render_state { /* plbu commands */ #define PLBU_CMD_BEGIN(max) { \ int i = 0, max_n = max; \ - uint32_t *plbu_cmd = util_dynarray_grow_cap(&ctx->plbu_cmd_array, max_n * 4); + uint32_t *plbu_cmd = util_dynarray_ensure_cap(&ctx->plbu_cmd_array, ctx->plbu_cmd_array.size + max_n * 4); #define PLBU_CMD_END() \ assert(i <= max_n); \ @@ -172,7 +172,7 @@ struct lima_render_state { /* vs commands */ #define VS_CMD_BEGIN(max) { \ int i = 0, max_n = max; \ - uint32_t *vs_cmd = util_dynarray_grow_cap(&ctx->vs_cmd_array, max_n * 4); + uint32_t *vs_cmd = util_dynarray_ensure_cap(&ctx->vs_cmd_array, ctx->vs_cmd_array.size + max_n * 4); #define VS_CMD_END() \ assert(i <= max_n); \ @@ -1425,7 +1425,7 @@ static void lima_finish_plbu_cmd(struct lima_context *ctx) { int i = 0; - uint32_t *plbu_cmd = util_dynarray_grow_cap(&ctx->plbu_cmd_array, 2 * 4); + uint32_t *plbu_cmd = util_dynarray_ensure_cap(&ctx->plbu_cmd_array, ctx->plbu_cmd_array.size + 2 * 4); plbu_cmd[i++] = 0x00000000; plbu_cmd[i++] = 0x50000000; /* END */ diff --git a/src/gallium/drivers/lima/lima_submit.c b/src/gallium/drivers/lima/lima_submit.c index 83c78bf82da..c54289d1470 100644 --- a/src/gallium/drivers/lima/lima_submit.c +++ b/src/gallium/drivers/lima/lima_submit.c @@ -106,11 +106,11 @@ bool lima_submit_add_bo(struct lima_submit *submit, struct lima_bo *bo, uint32_t } struct drm_lima_gem_submit_bo *submit_bo = - util_dynarray_grow(&submit->gem_bos, sizeof(*submit_bo)); + util_dynarray_grow(&submit->gem_bos, struct drm_lima_gem_submit_bo, 1); submit_bo->handle = bo->handle; submit_bo->flags = flags; - struct lima_bo **jbo = util_dynarray_grow(&submit->bos, sizeof(*jbo)); + struct lima_bo **jbo = util_dynarray_grow(&submit->bos, struct lima_bo, 1); *jbo = bo; /* prevent bo from being freed when submit start */ |