mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 04:50:11 +01:00
anv: Delay allocation of relocation lists
The old relocation list code always allocated 256 relocations and a hash set up-front without knowing whether or not we really need them. In particular, in the softpin case, this is two fairly large allocations that we don't need to be making. Also, for pipeline objects on haswell where we don't have softpin, we don't need relocations unless scratch is used so this is extra data per-pipeline. Instead, we should do it on-demand. This shaves 3.5% off of a cpu-limited example running with the Dawn WebGPU implementation. Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
parent
4fe2317601
commit
a3153162a9
1 changed files with 70 additions and 66 deletions
|
|
@ -46,69 +46,67 @@
|
||||||
* Functions related to anv_reloc_list
|
* Functions related to anv_reloc_list
|
||||||
*-----------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
anv_reloc_list_init(struct anv_reloc_list *list,
|
||||||
|
const VkAllocationCallbacks *alloc)
|
||||||
|
{
|
||||||
|
memset(list, 0, sizeof(*list));
|
||||||
|
return VK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
anv_reloc_list_init_clone(struct anv_reloc_list *list,
|
anv_reloc_list_init_clone(struct anv_reloc_list *list,
|
||||||
const VkAllocationCallbacks *alloc,
|
const VkAllocationCallbacks *alloc,
|
||||||
const struct anv_reloc_list *other_list)
|
const struct anv_reloc_list *other_list)
|
||||||
{
|
{
|
||||||
if (other_list) {
|
|
||||||
list->num_relocs = other_list->num_relocs;
|
list->num_relocs = other_list->num_relocs;
|
||||||
list->array_length = other_list->array_length;
|
list->array_length = other_list->array_length;
|
||||||
} else {
|
|
||||||
list->num_relocs = 0;
|
|
||||||
list->array_length = 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (list->num_relocs > 0) {
|
||||||
list->relocs =
|
list->relocs =
|
||||||
vk_alloc(alloc, list->array_length * sizeof(*list->relocs), 8,
|
vk_alloc(alloc, list->array_length * sizeof(*list->relocs), 8,
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||||
|
|
||||||
if (list->relocs == NULL)
|
if (list->relocs == NULL)
|
||||||
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
|
||||||
list->reloc_bos =
|
list->reloc_bos =
|
||||||
vk_alloc(alloc, list->array_length * sizeof(*list->reloc_bos), 8,
|
vk_alloc(alloc, list->array_length * sizeof(*list->reloc_bos), 8,
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||||
|
|
||||||
if (list->reloc_bos == NULL) {
|
if (list->reloc_bos == NULL) {
|
||||||
vk_free(alloc, list->relocs);
|
vk_free(alloc, list->relocs);
|
||||||
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
list->deps = _mesa_pointer_set_create(NULL);
|
memcpy(list->relocs, other_list->relocs,
|
||||||
|
list->array_length * sizeof(*list->relocs));
|
||||||
|
memcpy(list->reloc_bos, other_list->reloc_bos,
|
||||||
|
list->array_length * sizeof(*list->reloc_bos));
|
||||||
|
} else {
|
||||||
|
list->relocs = NULL;
|
||||||
|
list->reloc_bos = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other_list->deps) {
|
||||||
|
list->deps = _mesa_set_clone(other_list->deps, NULL);
|
||||||
if (!list->deps) {
|
if (!list->deps) {
|
||||||
vk_free(alloc, list->relocs);
|
vk_free(alloc, list->relocs);
|
||||||
vk_free(alloc, list->reloc_bos);
|
vk_free(alloc, list->reloc_bos);
|
||||||
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (other_list) {
|
list->deps = NULL;
|
||||||
memcpy(list->relocs, other_list->relocs,
|
|
||||||
list->array_length * sizeof(*list->relocs));
|
|
||||||
memcpy(list->reloc_bos, other_list->reloc_bos,
|
|
||||||
list->array_length * sizeof(*list->reloc_bos));
|
|
||||||
set_foreach(other_list->deps, entry) {
|
|
||||||
_mesa_set_add_pre_hashed(list->deps, entry->hash, entry->key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult
|
|
||||||
anv_reloc_list_init(struct anv_reloc_list *list,
|
|
||||||
const VkAllocationCallbacks *alloc)
|
|
||||||
{
|
|
||||||
return anv_reloc_list_init_clone(list, alloc, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
anv_reloc_list_finish(struct anv_reloc_list *list,
|
anv_reloc_list_finish(struct anv_reloc_list *list,
|
||||||
const VkAllocationCallbacks *alloc)
|
const VkAllocationCallbacks *alloc)
|
||||||
{
|
{
|
||||||
vk_free(alloc, list->relocs);
|
vk_free(alloc, list->relocs);
|
||||||
vk_free(alloc, list->reloc_bos);
|
vk_free(alloc, list->reloc_bos);
|
||||||
|
if (list->deps != NULL)
|
||||||
_mesa_set_destroy(list->deps, NULL);
|
_mesa_set_destroy(list->deps, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,34 +118,27 @@ anv_reloc_list_grow(struct anv_reloc_list *list,
|
||||||
if (list->num_relocs + num_additional_relocs <= list->array_length)
|
if (list->num_relocs + num_additional_relocs <= list->array_length)
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
|
|
||||||
size_t new_length = list->array_length * 2;
|
size_t new_length = MAX2(256, list->array_length * 2);
|
||||||
while (new_length < list->num_relocs + num_additional_relocs)
|
while (new_length < list->num_relocs + num_additional_relocs)
|
||||||
new_length *= 2;
|
new_length *= 2;
|
||||||
|
|
||||||
struct drm_i915_gem_relocation_entry *new_relocs =
|
struct drm_i915_gem_relocation_entry *new_relocs =
|
||||||
vk_alloc(alloc, new_length * sizeof(*list->relocs), 8,
|
vk_realloc(alloc, list->relocs,
|
||||||
|
new_length * sizeof(*list->relocs), 8,
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||||
if (new_relocs == NULL)
|
if (new_relocs == NULL)
|
||||||
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
list->relocs = new_relocs;
|
||||||
|
|
||||||
struct anv_bo **new_reloc_bos =
|
struct anv_bo **new_reloc_bos =
|
||||||
vk_alloc(alloc, new_length * sizeof(*list->reloc_bos), 8,
|
vk_realloc(alloc, list->reloc_bos,
|
||||||
|
new_length * sizeof(*list->reloc_bos), 8,
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||||
if (new_reloc_bos == NULL) {
|
if (new_reloc_bos == NULL)
|
||||||
vk_free(alloc, new_relocs);
|
|
||||||
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
}
|
list->reloc_bos = new_reloc_bos;
|
||||||
|
|
||||||
memcpy(new_relocs, list->relocs, list->num_relocs * sizeof(*list->relocs));
|
|
||||||
memcpy(new_reloc_bos, list->reloc_bos,
|
|
||||||
list->num_relocs * sizeof(*list->reloc_bos));
|
|
||||||
|
|
||||||
vk_free(alloc, list->relocs);
|
|
||||||
vk_free(alloc, list->reloc_bos);
|
|
||||||
|
|
||||||
list->array_length = new_length;
|
list->array_length = new_length;
|
||||||
list->relocs = new_relocs;
|
|
||||||
list->reloc_bos = new_reloc_bos;
|
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -161,6 +152,11 @@ anv_reloc_list_add(struct anv_reloc_list *list,
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
if (target_bo->flags & EXEC_OBJECT_PINNED) {
|
if (target_bo->flags & EXEC_OBJECT_PINNED) {
|
||||||
|
if (list->deps == NULL) {
|
||||||
|
list->deps = _mesa_pointer_set_create(NULL);
|
||||||
|
if (unlikely(list->deps == NULL))
|
||||||
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
}
|
||||||
_mesa_set_add(list->deps, target_bo);
|
_mesa_set_add(list->deps, target_bo);
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -193,6 +189,7 @@ anv_reloc_list_append(struct anv_reloc_list *list,
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
if (other->num_relocs > 0) {
|
||||||
memcpy(&list->relocs[list->num_relocs], &other->relocs[0],
|
memcpy(&list->relocs[list->num_relocs], &other->relocs[0],
|
||||||
other->num_relocs * sizeof(other->relocs[0]));
|
other->num_relocs * sizeof(other->relocs[0]));
|
||||||
memcpy(&list->reloc_bos[list->num_relocs], &other->reloc_bos[0],
|
memcpy(&list->reloc_bos[list->num_relocs], &other->reloc_bos[0],
|
||||||
|
|
@ -202,8 +199,15 @@ anv_reloc_list_append(struct anv_reloc_list *list,
|
||||||
list->relocs[i + list->num_relocs].offset += offset;
|
list->relocs[i + list->num_relocs].offset += offset;
|
||||||
|
|
||||||
list->num_relocs += other->num_relocs;
|
list->num_relocs += other->num_relocs;
|
||||||
|
}
|
||||||
|
|
||||||
set_foreach(other->deps, entry) {
|
if (other->deps) {
|
||||||
|
if (list->deps == NULL) {
|
||||||
|
list->deps = _mesa_pointer_set_create(NULL);
|
||||||
|
if (unlikely(list->deps == NULL))
|
||||||
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
}
|
||||||
|
set_foreach(other->deps, entry)
|
||||||
_mesa_set_add_pre_hashed(list->deps, entry->hash, entry->key);
|
_mesa_set_add_pre_hashed(list->deps, entry->hash, entry->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue