radv: refactor descriptor set layout tracking

Separately track descriptor set layouts for pools with
FREE_DESCRIPTOR_SET disabled, instead of reusing
`radv_descriptor_pool::entries`. This saves 8 bytes for each entry and
also avoids some indirection.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16541>
This commit is contained in:
Victor Hermann Chiletto 2022-05-14 17:00:21 -03:00
parent f97ba1f95d
commit 70871aa50c
2 changed files with 40 additions and 16 deletions

View file

@ -674,11 +674,15 @@ radv_descriptor_set_create(struct radv_device *device, struct radv_descriptor_po
set->header.bo = pool->bo;
set->header.mapped_ptr = (uint32_t *)(pool->mapped_ptr + pool->current_offset);
set->header.va = pool->bo ? (radv_buffer_get_va(set->header.bo) + pool->current_offset) : 0;
if (!pool->host_memory_base) {
pool->entries[pool->entry_count].offset = pool->current_offset;
pool->entries[pool->entry_count].size = layout_size;
pool->entries[pool->entry_count].set = set;
} else {
pool->layouts[pool->entry_count] = layout;
}
pool->entries[pool->entry_count].set = set;
pool->current_offset += layout_size;
} else if (!pool->host_memory_base) {
uint64_t offset = 0;
@ -734,10 +738,9 @@ static void
radv_descriptor_set_destroy(struct radv_device *device, struct radv_descriptor_pool *pool,
struct radv_descriptor_set *set, bool free_bo)
{
vk_descriptor_set_layout_unref(&device->vk, &set->header.layout->vk);
assert(!pool->host_memory_base);
if (pool->host_memory_base)
return;
vk_descriptor_set_layout_unref(&device->vk, &set->header.layout->vk);
if (free_bo && !pool->host_memory_base) {
for (int i = 0; i < pool->entry_count; ++i) {
@ -757,8 +760,15 @@ static void
radv_destroy_descriptor_pool(struct radv_device *device, const VkAllocationCallbacks *pAllocator,
struct radv_descriptor_pool *pool)
{
for (int i = 0; i < pool->entry_count; ++i) {
radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
if (!pool->host_memory_base) {
for (uint32_t i = 0; i < pool->entry_count; ++i) {
radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
}
} else {
for (uint32_t i = 0; i < pool->entry_count; ++i) {
vk_descriptor_set_layout_unref(&device->vk, &pool->layouts[i]->vk);
}
}
if (pool->bo)
@ -852,14 +862,17 @@ radv_CreateDescriptorPool(VkDevice _device, const VkDescriptorPoolCreateInfo *pC
}
}
uint64_t entries_size = sizeof(struct radv_descriptor_pool_entry) * pCreateInfo->maxSets;
size += entries_size;
uint64_t layouts_size = 0;
if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
uint64_t host_size = pCreateInfo->maxSets * sizeof(struct radv_descriptor_set);
host_size += sizeof(struct radeon_winsys_bo *) * bo_count;
host_size += sizeof(struct radv_descriptor_range) * range_count;
size += host_size;
size += pCreateInfo->maxSets * sizeof(struct radv_descriptor_set);
size += sizeof(struct radeon_winsys_bo *) * bo_count;
size += sizeof(struct radv_descriptor_range) * range_count;
layouts_size = sizeof(struct radv_descriptor_set_layout *) * pCreateInfo->maxSets;
size += layouts_size;
} else {
size += sizeof(struct radv_descriptor_pool_entry) * pCreateInfo->maxSets;
}
pool = vk_alloc2(&device->vk.alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
@ -871,7 +884,7 @@ radv_CreateDescriptorPool(VkDevice _device, const VkDescriptorPoolCreateInfo *pC
vk_object_base_init(&device->vk, &pool->base, VK_OBJECT_TYPE_DESCRIPTOR_POOL);
if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
pool->host_memory_base = (uint8_t *)pool + sizeof(struct radv_descriptor_pool) + entries_size;
pool->host_memory_base = (uint8_t *)pool + sizeof(struct radv_descriptor_pool) + layouts_size;
pool->host_memory_ptr = pool->host_memory_base;
pool->host_memory_end = (uint8_t *)pool + size;
}
@ -933,9 +946,16 @@ radv_ResetDescriptorPool(VkDevice _device, VkDescriptorPool descriptorPool,
RADV_FROM_HANDLE(radv_device, device, _device);
RADV_FROM_HANDLE(radv_descriptor_pool, pool, descriptorPool);
for (int i = 0; i < pool->entry_count; ++i) {
radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
if (!pool->host_memory_base) {
for (uint32_t i = 0; i < pool->entry_count; ++i) {
radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
}
} else {
for (uint32_t i = 0; i < pool->entry_count; ++i) {
vk_descriptor_set_layout_unref(&device->vk, &pool->layouts[i]->vk);
}
}
pool->entry_count = 0;
pool->current_offset = 0;

View file

@ -1012,7 +1012,11 @@ struct radv_descriptor_pool {
uint32_t entry_count;
uint32_t max_entry_count;
struct radv_descriptor_pool_entry entries[0];
union {
struct radv_descriptor_set_layout *layouts[0];
struct radv_descriptor_pool_entry entries[0];
};
};
struct radv_descriptor_update_template_entry {