+ ANV_FROM_HANDLE(anv_device, device, _device);
+ struct anv_descriptor_pool *pool;
+
+ uint32_t descriptor_count = 0;
+ uint32_t buffer_count = 0;
+ for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) {
+ switch (pCreateInfo->pPoolSizes[i].type) {
+ case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+ case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
+ case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
+ case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
+ buffer_count += pCreateInfo->pPoolSizes[i].descriptorCount;
+ default:
+ descriptor_count += pCreateInfo->pPoolSizes[i].descriptorCount;
+ break;
+ }
+ }
+
+ const size_t size =
+ sizeof(*pool) +
+ pCreateInfo->maxSets * sizeof(struct anv_descriptor_set) +
+ descriptor_count * sizeof(struct anv_descriptor) +
+ buffer_count * sizeof(struct anv_buffer_view);
+
+ pool = anv_alloc2(&device->alloc, pAllocator, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (!pool)
+ return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ pool->size = size;
+ pool->next = 0;
+ pool->free_list = EMPTY;
+
+ anv_state_stream_init(&pool->surface_state_stream,
+ &device->surface_state_block_pool);
+ pool->surface_state_free_list = NULL;
+
+ *pDescriptorPool = anv_descriptor_pool_to_handle(pool);
+