anv: use vk_realloc for the anv_execbuf arrays
Three reasons for that: 0. The operation we're doing here is actually a reallocation. 1. The newer code is, IMHO, easier to read. 2. Realloc has this property where sometimes, when possible, it will expand your array without moving it somewhere else, so it doesn't need to copy the memory contents, returning the original pointer back to you. I did some analysis and while that case is not common, it does happen sometimes in real world applications (I could see it happening in Shootergame and Aztec Ruins, but not Dota 2), so we're able to save a few CPU cycles. v2: Rebase. Reviewed-by: Ivan Briano <ivan.briano@intel.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20703>
This commit is contained in:
@@ -109,28 +109,19 @@ anv_execbuf_add_bo(struct anv_device *device,
|
||||
uint32_t new_len = exec->objects ? exec->bo_array_length * 2 : 64;
|
||||
|
||||
struct drm_i915_gem_exec_object2 *new_objects =
|
||||
vk_alloc(exec->alloc, new_len * sizeof(*new_objects), 8, exec->alloc_scope);
|
||||
vk_realloc(exec->alloc, exec->objects,
|
||||
new_len * sizeof(*new_objects), 8, exec->alloc_scope);
|
||||
if (new_objects == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
struct anv_bo **new_bos =
|
||||
vk_alloc(exec->alloc, new_len * sizeof(*new_bos), 8, exec->alloc_scope);
|
||||
if (new_bos == NULL) {
|
||||
vk_free(exec->alloc, new_objects);
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
}
|
||||
|
||||
if (exec->objects) {
|
||||
memcpy(new_objects, exec->objects,
|
||||
exec->bo_count * sizeof(*new_objects));
|
||||
memcpy(new_bos, exec->bos,
|
||||
exec->bo_count * sizeof(*new_bos));
|
||||
}
|
||||
|
||||
vk_free(exec->alloc, exec->objects);
|
||||
vk_free(exec->alloc, exec->bos);
|
||||
|
||||
exec->objects = new_objects;
|
||||
|
||||
struct anv_bo **new_bos =
|
||||
vk_realloc(exec->alloc, exec->bos, new_len * sizeof(*new_bos), 8,
|
||||
exec->alloc_scope);
|
||||
if (new_bos == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
exec->bos = new_bos;
|
||||
exec->bo_array_length = new_len;
|
||||
}
|
||||
@@ -200,26 +191,21 @@ anv_execbuf_add_syncobj(struct anv_device *device,
|
||||
uint32_t new_len = MAX2(exec->syncobj_array_length * 2, 16);
|
||||
|
||||
struct drm_i915_gem_exec_fence *new_syncobjs =
|
||||
vk_alloc(exec->alloc, new_len * sizeof(*new_syncobjs),
|
||||
8, exec->alloc_scope);
|
||||
if (!new_syncobjs)
|
||||
vk_realloc(exec->alloc, exec->syncobjs,
|
||||
new_len * sizeof(*new_syncobjs), 8, exec->alloc_scope);
|
||||
if (new_syncobjs == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
if (exec->syncobjs)
|
||||
typed_memcpy(new_syncobjs, exec->syncobjs, exec->syncobj_count);
|
||||
|
||||
exec->syncobjs = new_syncobjs;
|
||||
|
||||
if (exec->syncobj_values) {
|
||||
uint64_t *new_syncobj_values =
|
||||
vk_alloc(exec->alloc, new_len * sizeof(*new_syncobj_values),
|
||||
8, exec->alloc_scope);
|
||||
if (!new_syncobj_values)
|
||||
vk_realloc(exec->alloc, exec->syncobj_values,
|
||||
new_len * sizeof(*new_syncobj_values), 8,
|
||||
exec->alloc_scope);
|
||||
if (new_syncobj_values == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
typed_memcpy(new_syncobj_values, exec->syncobj_values,
|
||||
exec->syncobj_count);
|
||||
|
||||
exec->syncobj_values = new_syncobj_values;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user