zink: support PIPE_CAP_QUERY_MEMORY_INFO

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10511>
This commit is contained in:
Mike Blumenkrantz
2021-04-21 13:20:40 -04:00
committed by Marge Bot
parent ce1e05de8a
commit ff4ba3d4a7

View File

@@ -228,6 +228,7 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
case PIPE_CAP_ANISOTROPIC_FILTER:
return screen->info.feats.features.samplerAnisotropy;
case PIPE_CAP_QUERY_MEMORY_INFO:
case PIPE_CAP_NPOT_TEXTURES:
case PIPE_CAP_TGSI_TEXCOORD:
case PIPE_CAP_DRAW_INDIRECT:
@@ -1401,6 +1402,49 @@ zink_get_loader_version(void)
return loader_version;
}
static void
zink_query_memory_info(struct pipe_screen *pscreen, struct pipe_memory_info *info)
{
struct zink_screen *screen = zink_screen(pscreen);
memset(info, 0, sizeof(struct pipe_memory_info));
if (screen->info.have_EXT_memory_budget && screen->vk_GetPhysicalDeviceMemoryProperties2) {
VkPhysicalDeviceMemoryProperties2 mem = {};
mem.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
VkPhysicalDeviceMemoryBudgetPropertiesEXT budget = {};
budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
mem.pNext = &budget;
screen->vk_GetPhysicalDeviceMemoryProperties2(screen->pdev, &mem);
for (unsigned i = 0; i < mem.memoryProperties.memoryHeapCount; i++) {
if (mem.memoryProperties.memoryHeaps[i].flags == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
/* VRAM */
info->total_device_memory = mem.memoryProperties.memoryHeaps[i].size / 1024;
info->avail_device_memory = (budget.heapBudget[i] - budget.heapUsage[i]) / 1024;
} else if (mem.memoryProperties.memoryHeaps[i].flags == (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
/* GART */
info->total_staging_memory = mem.memoryProperties.memoryHeaps[i].size / 1024;
info->avail_staging_memory = (budget.heapBudget[i] - budget.heapUsage[i]) / 1024;
}
}
/* evictions not yet supported in vulkan */
} else {
for (unsigned i = 0; i < screen->info.mem_props.memoryHeapCount; i++) {
if (screen->info.mem_props.memoryHeaps[i].flags == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
/* VRAM */
info->total_device_memory = screen->info.mem_props.memoryHeaps[i].size / 1024;
/* free real estate! */
info->avail_device_memory = info->total_device_memory;
} else if (screen->info.mem_props.memoryHeaps[i].flags == (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
/* GART */
info->total_staging_memory = screen->info.mem_props.memoryHeaps[i].size / 1024;
/* free real estate! */
info->avail_staging_memory = info->total_staging_memory;
}
}
}
}
static VkDevice
zink_create_logical_device(struct zink_screen *screen)
{
@@ -1521,6 +1565,7 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
screen->base.get_vendor = zink_get_vendor;
screen->base.get_device_vendor = zink_get_device_vendor;
screen->base.get_compute_param = zink_get_compute_param;
screen->base.query_memory_info = zink_query_memory_info;
screen->base.get_param = zink_get_param;
screen->base.get_paramf = zink_get_paramf;
screen->base.get_shader_param = zink_get_shader_param;