Module: Mesa Branch: main Commit: 31a0de992127025519d405db5669bf5736ba4ae2 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=31a0de992127025519d405db5669bf5736ba4ae2
Author: Mike Blumenkrantz <[email protected]> Date: Thu Apr 13 13:54:24 2023 -0400 zink: make general bo allocation more robust by iterating previously there was a fallback path here (broken by f6d3a5755f6) which would attempt to demote BAR allocations to other heaps on failure to avoid oom this was great, but it's not the most robust solution, which is to iterate all the memory types matching the given heap and try them in addition to having a demotion fallback Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22479> --- src/gallium/drivers/zink/zink_resource.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c index eb5535d5359..1a6a9886324 100644 --- a/src/gallium/drivers/zink/zink_resource.c +++ b/src/gallium/drivers/zink/zink_resource.c @@ -1082,19 +1082,26 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t } retry: - mai.memoryTypeIndex = zink_mem_type_idx_from_bits(screen, heap, reqs.memoryTypeBits); - assert(reqs.memoryTypeBits & BITFIELD_BIT(mai.memoryTypeIndex)); - obj->bo = zink_bo(zink_bo_create(screen, reqs.size, alignment, heap, mai.pNext ? ZINK_ALLOC_NO_SUBALLOC : 0, mai.memoryTypeIndex, mai.pNext)); - if (!obj->bo) { - if (heap == ZINK_HEAP_DEVICE_LOCAL_VISIBLE) { - if (templ->flags & PIPE_RESOURCE_FLAG_MAP_COHERENT || templ->usage == PIPE_USAGE_DYNAMIC) - heap = ZINK_HEAP_HOST_VISIBLE_COHERENT; - else - heap = ZINK_HEAP_DEVICE_LOCAL; - goto retry; + /* iterate over all available memory types to reduce chance of oom */ + for (unsigned i = 0; !obj->bo && i < screen->heap_count[heap]; i++) { + if (!(reqs.memoryTypeBits & BITFIELD_BIT(screen->heap_map[heap][i]))) + continue; + + mai.memoryTypeIndex = screen->heap_map[heap][i]; + obj->bo = zink_bo(zink_bo_create(screen, reqs.size, alignment, heap, mai.pNext ? ZINK_ALLOC_NO_SUBALLOC : 0, mai.memoryTypeIndex, mai.pNext)); + if (!obj->bo) { + if (heap == ZINK_HEAP_DEVICE_LOCAL_VISIBLE) { + /* demote BAR allocations to a different heap on failure to avoid oom */ + if (templ->flags & PIPE_RESOURCE_FLAG_MAP_COHERENT || templ->usage == PIPE_USAGE_DYNAMIC) + heap = ZINK_HEAP_HOST_VISIBLE_COHERENT; + else + heap = ZINK_HEAP_DEVICE_LOCAL; + goto retry; + } } - goto fail2; } + if (!obj->bo) + goto fail2; if (aflags == ZINK_ALLOC_SPARSE) { obj->size = templ->width0; } else {
