vk: Allocate subpass attachment in one big block

This avoids making a lot of small allocations and handles allocation
failure correctly.

Fixes dEQP-VK.api.object_management.alloc_callback_fail.* failures.
This commit is contained in:
Kristian Høgsberg Kristensen
2016-01-03 22:58:00 -08:00
parent 5526c1782a
commit fca1c08e34
2 changed files with 29 additions and 23 deletions

View File

@@ -65,6 +65,27 @@ VkResult anv_CreateRenderPass(
// att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp; // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
} }
uint32_t subpass_attachment_count = 0, *p;
for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i];
subpass_attachment_count +=
desc->inputAttachmentCount +
desc->colorAttachmentCount +
/* Count colorAttachmentCount again for resolve_attachments */
desc->colorAttachmentCount;
}
pass->subpass_attachments =
anv_alloc2(&device->alloc, pAllocator,
subpass_attachment_count * sizeof(uint32_t), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (pass->subpass_attachments == NULL) {
anv_free2(&device->alloc, pAllocator, pass);
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
}
p = pass->subpass_attachments;
for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i]; const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i];
struct anv_subpass *subpass = &pass->subpasses[i]; struct anv_subpass *subpass = &pass->subpasses[i];
@@ -73,10 +94,8 @@ VkResult anv_CreateRenderPass(
subpass->color_count = desc->colorAttachmentCount; subpass->color_count = desc->colorAttachmentCount;
if (desc->inputAttachmentCount > 0) { if (desc->inputAttachmentCount > 0) {
subpass->input_attachments = subpass->input_attachments = p;
anv_alloc2(&device->alloc, pAllocator, p += desc->inputAttachmentCount;
desc->inputAttachmentCount * sizeof(uint32_t), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) { for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {
subpass->input_attachments[j] subpass->input_attachments[j]
@@ -85,10 +104,8 @@ VkResult anv_CreateRenderPass(
} }
if (desc->colorAttachmentCount > 0) { if (desc->colorAttachmentCount > 0) {
subpass->color_attachments = subpass->color_attachments = p;
anv_alloc2(&device->alloc, pAllocator, p += desc->colorAttachmentCount;
desc->colorAttachmentCount * sizeof(uint32_t), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) { for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
subpass->color_attachments[j] subpass->color_attachments[j]
@@ -97,10 +114,8 @@ VkResult anv_CreateRenderPass(
} }
if (desc->pResolveAttachments) { if (desc->pResolveAttachments) {
subpass->resolve_attachments = subpass->resolve_attachments = p;
anv_alloc2(&device->alloc, pAllocator, p += desc->colorAttachmentCount;
desc->colorAttachmentCount * sizeof(uint32_t), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) { for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
subpass->resolve_attachments[j] subpass->resolve_attachments[j]
@@ -129,17 +144,7 @@ void anv_DestroyRenderPass(
ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_render_pass, pass, _pass); ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
for (uint32_t i = 0; i < pass->subpass_count; i++) { anv_free2(&device->alloc, pAllocator, pass->subpass_attachments);
/* In VkSubpassCreateInfo, each of the attachment arrays may be null.
* Don't free the null arrays.
*/
struct anv_subpass *subpass = &pass->subpasses[i];
anv_free2(&device->alloc, pAllocator, subpass->input_attachments);
anv_free2(&device->alloc, pAllocator, subpass->color_attachments);
anv_free2(&device->alloc, pAllocator, subpass->resolve_attachments);
}
anv_free2(&device->alloc, pAllocator, pass); anv_free2(&device->alloc, pAllocator, pass);
} }

View File

@@ -1613,6 +1613,7 @@ struct anv_render_pass_attachment {
struct anv_render_pass { struct anv_render_pass {
uint32_t attachment_count; uint32_t attachment_count;
uint32_t subpass_count; uint32_t subpass_count;
uint32_t * subpass_attachments;
struct anv_render_pass_attachment * attachments; struct anv_render_pass_attachment * attachments;
struct anv_subpass subpasses[0]; struct anv_subpass subpasses[0];
}; };