dynamic* descriptor pools when VK_NV_descriptor_pool_overallocation is

unsupported
This commit is contained in:
Gregory Wells
2025-06-17 12:17:58 -04:00
parent 537134742d
commit 960fee7cec
3 changed files with 71 additions and 133 deletions

View File

@@ -29,11 +29,11 @@ const char* *vkGetGryphnDeviceExtensions(uint32_t* outCount, VkPhysicalDevice de
}
free(vkExtensions);
if (supportsDescriptorPoolOverallocation) {
count++;
extensiosns = realloc(extensiosns, sizeof(const char*) * count);
extensiosns[(count - 1)] = VK_NV_DESCRIPTOR_POOL_OVERALLOCATION_EXTENSION_NAME;
}
// if (supportsDescriptorPoolOverallocation) {
// count++;
// extensiosns = realloc(extensiosns, sizeof(const char*) * count);
// extensiosns[(count - 1)] = VK_NV_DESCRIPTOR_POOL_OVERALLOCATION_EXTENSION_NAME;
// }
*outCount = count;

View File

@@ -11,58 +11,77 @@ VkGryphnUniformPool* GetLastUniformPool(VkGryphnUniformPoolArrayList* list) { re
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
pool->uniformPool->pools = VkGryphnUniformPoolArrayListCreate();
{
VkGryphnUniformPool firstPool = {
.pool = VK_NULL_HANDLE,
.layouts = VkDescriptorSetLayoutArrayListCreate()
if (device->outputDevice->enabledOversizedDescriptorPools == gnTrue) {
{
VkGryphnUniformPool firstPool = {
.pool = VK_NULL_HANDLE,
.layouts = VkDescriptorSetLayoutArrayListCreate()
};
VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, firstPool);
} // scopped because the add function copies and I don't want it lying around
VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools);
VkDescriptorPoolCreateInfo poolInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.flags = VK_DESCRIPTOR_POOL_CREATE_ALLOW_OVERALLOCATION_SETS_BIT_NV,
.poolSizeCount = 0,
.pPoolSizes = NULL,
.maxSets = 0
};
VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, firstPool);
} // scopped because the add function copies and I don't want it lying around
VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools);
VkDescriptorPoolCreateInfo poolInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.flags = VK_DESCRIPTOR_POOL_CREATE_ALLOW_OVERALLOCATION_SETS_BIT_NV,
.poolSizeCount = 0,
.pPoolSizes = NULL,
.maxSets = 0
};
if (vkCreateDescriptorPool(
pool->device->outputDevice->device, &poolInfo, NULL,
&currentPool->pool
) != VK_SUCCESS)
return GN_FAILED_TO_ALLOCATE_MEMORY;
// if (device->outputDevice->enabledOversizedDescriptorPools == gnTrue) {
// VkDescriptorPoolCreateInfo poolInfo = {
// .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
// .flags = VK_DESCRIPTOR_POOL_CREATE_ALLOW_OVERALLOCATION_SETS_BIT_NV,
// .poolSizeCount = 0,
// .pPoolSizes = NULL,
// .maxSets = 0
// };
// if (vkCreateDescriptorPool(
// pool->device->outputDevice->device, &poolInfo, NULL,
// &pool->uniformPool->pools[pool->uniformPool->poolCount].pool
// ) != VK_SUCCESS)
// return GN_FAILED_TO_ALLOCATE_MEMORY;
// pool->uniformPool->pools[0].layoutCount = 0;
// pool->uniformPool->pools[0].layouts = NULL;
// pool->uniformPool->poolCount = 1;
// }
// pool->uniformPool->currentPool = 0;
if (vkCreateDescriptorPool(
pool->device->outputDevice->device, &poolInfo, NULL,
&currentPool->pool
) != VK_SUCCESS)
return GN_FAILED_TO_ALLOCATE_MEMORY;
}
return GN_SUCCESS;
}
gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, gnUniformAllocationInfo allocInfo) {
gnBool fixedAllocation = !pool->device->outputDevice->enabledOversizedDescriptorPools;
if (fixedAllocation) {
VkGryphnUniformPool newPool = {
.pool = VK_NULL_HANDLE,
.layouts = VkDescriptorSetLayoutArrayListCreate()
};
// TODO: redo this, its not warning me IDK why cuz its totally wrong
VkDescriptorPoolSize uniformBufferSize = {
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 0
};
VkDescriptorPoolSize imageSize = {
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = 0
};
for (int i = 0; i < allocInfo.setCount; i++) {
for (int c = 0; c < allocInfo.sets[i].uniformBindingCount; c++) {
if (allocInfo.sets[i].uniformBindings[i].type == GN_UNIFORM_BUFFER_DESCRIPTOR) uniformBufferSize.descriptorCount++;
if (allocInfo.sets[i].uniformBindings[i].type == GN_IMAGE_DESCRIPTOR) imageSize.descriptorCount++;
}
}
VkDescriptorPoolCreateInfo poolInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.poolSizeCount = 2,
.pPoolSizes = (VkDescriptorPoolSize[]){ uniformBufferSize, imageSize },
.maxSets = allocInfo.setCount
};
if (vkCreateDescriptorPool(
pool->device->outputDevice->device, &poolInfo, NULL,
&newPool.pool
) != VK_SUCCESS)
return NULL;
VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, newPool);
} // scopped for same reasons as before
VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools);
uint32_t startingCount = currentPool->layouts.count;
@@ -93,93 +112,12 @@ gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, gnUniformAllocati
uniforms[i]->uniform->set = sets[i];
}
return uniforms;
// gnBool fixedAllocCount = pool->device->outputDevice->enabledOversizedDescriptorPools;
// if (fixedAllocCount) {
// if (pool->uniformPool->poolCount >= pool->uniformPool->maxPoolCount) {
// pool->uniformPool->maxPoolCount *= 2;
// pool->uniformPool->pools = realloc(pool->uniformPool->pools, sizeof(vkGryphnUniformPool) * pool->uniformPool->maxPoolCount);
// }
// VkDescriptorPoolSize uniformBufferSize = {
// .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// .descriptorCount = 0
// };
// VkDescriptorPoolSize imageSize = {
// .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
// .descriptorCount = 0
// };
// for (int i = 0; i < allocInfo.setCount; i++) {
// for (int c = 0; c < allocInfo.sets[i].uniformBindingCount; c++) {
// if (allocInfo.sets[i].uniformBindings[i].type == GN_UNIFORM_BUFFER_DESCRIPTOR) uniformBufferSize.descriptorCount++;
// if (allocInfo.sets[i].uniformBindings[i].type == GN_IMAGE_DESCRIPTOR) imageSize.descriptorCount++;
// }
// }
// VkDescriptorPoolCreateInfo poolInfo = {
// .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
// .poolSizeCount = 1,
// .pPoolSizes = (VkDescriptorPoolSize[]){ uniformBufferSize, imageSize },
// .maxSets = allocInfo.setCount
// };
// if (vkCreateDescriptorPool(
// pool->device->outputDevice->device, &poolInfo, NULL,
// &pool->uniformPool->pools[pool->uniformPool->poolCount].pool
// ) != VK_SUCCESS)
// return NULL;
// pool->uniformPool->poolCount++;
// uint32_t maxSets = uniformBufferSize.descriptorCount + uniformBufferSize.descriptorCount;
// }
// if (fixedAllocCount)
// pool->uniformPool->pools[pool->uniformPool->currentPool].layouts = malloc(sizeof(VkDescriptorSetLayout) * allocInfo.setCount);
// else {
// if (pool->uniformPool->pools[pool->uniformPool->currentPool].layouts == NULL) {
// pool->uniformPool->pools[pool->uniformPool->currentPool].layouts = malloc(sizeof(VkDescriptorSetLayout) * allocInfo.setCount);
// }
// else {
// pool->uniformPool->pools[pool->uniformPool->currentPool].layouts = realloc(
// pool->uniformPool->pools[pool->uniformPool->currentPool].layouts,
// sizeof(VkDescriptorSetLayout) * (allocInfo.setCount + pool->uniformPool->pools[pool->uniformPool->currentPool].layoutCount));
// }
// }
// for (int i = 0; i < allocInfo.setCount; i++) {
// pool->uniformPool->pools[pool->uniformPool->currentPool].layouts[pool->uniformPool->pools[pool->uniformPool->currentPool].layoutCount + i] = vkGryphnCreateSetLayouts(&allocInfo.sets[i], pool->device->outputDevice->device);
// }
// VkDescriptorSetAllocateInfo vkAllocInfo = {
// .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
// .descriptorPool = pool->uniformPool->pools[pool->uniformPool->currentPool].pool,
// .descriptorSetCount = allocInfo.setCount,
// .pSetLayouts = &pool->uniformPool->pools[pool->uniformPool->currentPool].layouts[pool->uniformPool->pools[pool->uniformPool->currentPool].layoutCount]
// };
// pool->uniformPool->pools[pool->uniformPool->currentPool].layoutCount += allocInfo.setCount;
// VkDescriptorSet* sets = malloc(sizeof(VkDescriptorSet) * allocInfo.setCount);
// if (vkAllocateDescriptorSets(pool->device->outputDevice->device, &vkAllocInfo, sets) != VK_SUCCESS)
// return NULL;
// gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount);
// for (int i = 0; i < allocInfo.setCount; i++) {
// uniforms[i] = malloc(sizeof(struct gnUniform_t));
// uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t));
// uniforms[i]->uniform->set = sets[i];
// }
// return uniforms;
}
void gnDestroyUniformPoolFn(gnUniformPool pool) {
for (int k = 0; k < pool->uniformPool->pools.count; k++) {
vkDestroyDescriptorPool(pool->device->outputDevice->device, pool->uniformPool->pools.data[k].pool, NULL);
for (int i = 0; i < pool->uniformPool->pools.data[k].layouts.count; i++) {
for (int i = 0; i < pool->uniformPool->pools.data[k].layouts.count; i++)
vkDestroyDescriptorSetLayout(pool->device->outputDevice->device, pool->uniformPool->pools.data[k].layouts.data[i], NULL);
}
}
}