zink: extract debug_resource_mem from resource_object_create

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27155>
This commit is contained in:
Gert Wollny
2024-01-22 10:33:01 +01:00
committed by Marge Bot
parent 7180670e28
commit 063949063c

View File

@@ -1352,6 +1352,39 @@ update_obj_info(struct zink_screen *screen, struct zink_resource_object *obj,
obj->host_visible = screen->info.mem_props.memoryTypes[obj->bo->base.base.placement].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
}
}
static inline void
debug_resource_mem(struct zink_resource_object *obj, const struct pipe_resource *templ, struct zink_screen *screen)
{
char buf[4096];
unsigned idx = 0;
if (obj->is_buffer) {
size_t size = (size_t)DIV_ROUND_UP(obj->size, 1024);
if (templ->bind == PIPE_BIND_QUERY_BUFFER && templ->usage == PIPE_USAGE_STAGING) //internal qbo
idx += snprintf(buf, sizeof(buf), "QBO(%zu)", size);
else
idx += snprintf(buf, sizeof(buf), "BUF(%zu)", size);
} else {
idx += snprintf(buf, sizeof(buf), "IMG(%s:%ux%ux%u)", util_format_short_name(templ->format), templ->width0, templ->height0, templ->depth0);
}
/*
zink_vkflags_func flag_func = obj->is_buffer ? (zink_vkflags_func)vk_BufferCreateFlagBits_to_str : (zink_vkflags_func)vk_ImageCreateFlagBits_to_str;
zink_vkflags_func usage_func = obj->is_buffer ? (zink_vkflags_func)vk_BufferUsageFlagBits_to_str : (zink_vkflags_func)vk_ImageUsageFlagBits_to_str;
if (obj->vkflags) {
buf[idx++] = '[';
idx += zink_string_vkflags_unroll(&buf[idx], sizeof(buf) - idx, obj->vkflags, flag_func);
buf[idx++] = ']';
}
if (obj->vkusage) {
buf[idx++] = '[';
idx += zink_string_vkflags_unroll(&buf[idx], sizeof(buf) - idx, obj->vkusage, usage_func);
buf[idx++] = ']';
}
*/
buf[idx] = 0;
obj->bo->name = zink_debug_mem_add(screen, obj->size, buf);
}
static struct zink_resource_object *
resource_object_create(struct zink_screen *screen, const struct pipe_resource *templ, struct winsys_handle *whandle, bool *linear,
uint64_t *modifiers, int modifiers_count, const void *loader_private, const void *user_mem)
@@ -1432,38 +1465,11 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
assert(obj->bo);
};
if (zink_debug & ZINK_DEBUG_MEM) {
char buf[4096];
unsigned idx = 0;
if (obj->is_buffer) {
size_t size = (size_t)DIV_ROUND_UP(obj->size, 1024);
if (templ->bind == PIPE_BIND_QUERY_BUFFER && templ->usage == PIPE_USAGE_STAGING) //internal qbo
idx += snprintf(buf, sizeof(buf), "QBO(%zu)", size);
else
idx += snprintf(buf, sizeof(buf), "BUF(%zu)", size);
} else {
idx += snprintf(buf, sizeof(buf), "IMG(%s:%ux%ux%u)", util_format_short_name(templ->format), templ->width0, templ->height0, templ->depth0);
}
/*
zink_vkflags_func flag_func = obj->is_buffer ? (zink_vkflags_func)vk_BufferCreateFlagBits_to_str : (zink_vkflags_func)vk_ImageCreateFlagBits_to_str;
zink_vkflags_func usage_func = obj->is_buffer ? (zink_vkflags_func)vk_BufferUsageFlagBits_to_str : (zink_vkflags_func)vk_ImageUsageFlagBits_to_str;
if (obj->vkflags) {
buf[idx++] = '[';
idx += zink_string_vkflags_unroll(&buf[idx], sizeof(buf) - idx, obj->vkflags, flag_func);
buf[idx++] = ']';
}
if (obj->vkusage) {
buf[idx++] = '[';
idx += zink_string_vkflags_unroll(&buf[idx], sizeof(buf) - idx, obj->vkusage, usage_func);
buf[idx++] = ']';
}
*/
buf[idx] = 0;
obj->bo->name = zink_debug_mem_add(screen, obj->size, buf);
}
update_obj_info(screen, obj, templ, &alloc_info);
if (zink_debug & ZINK_DEBUG_MEM)
debug_resource_mem(obj, templ, screen);
if (templ->target == PIPE_BUFFER) {
if (!(templ->flags & PIPE_RESOURCE_FLAG_SPARSE)) {
if (VKSCR(BindBufferMemory)(screen->dev, obj->buffer, zink_bo_get_mem(obj->bo), obj->offset) != VK_SUCCESS) {