[Mesa-dev] [PATCH 5/8] radv: refactor render pass creation

Fredrik Höglund fredrik at kde.org
Tue Jun 26 21:49:33 UTC 2018


Allocate the render pass with a single call to vk_zalloc2.

Signed-off-by: Fredrik Höglund <fredrik at kde.org>
---
 src/amd/vulkan/radv_pass.c    | 45 +++++++++++++----------------------
 src/amd/vulkan/radv_private.h |  1 -
 2 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/src/amd/vulkan/radv_pass.c b/src/amd/vulkan/radv_pass.c
index 7e6fd84af55..17dafaca071 100644
--- a/src/amd/vulkan/radv_pass.c
+++ b/src/amd/vulkan/radv_pass.c
@@ -38,6 +38,7 @@ VkResult radv_CreateRenderPass(
 	struct radv_render_pass *pass;
 	size_t size;
 	size_t attachments_offset;
+	size_t subpass_attachments_offset;
 	VkRenderPassMultiviewCreateInfoKHR *multiview_info = NULL;
 
 	assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
@@ -46,13 +47,25 @@ VkResult radv_CreateRenderPass(
 	size += pCreateInfo->subpassCount * sizeof(pass->subpasses[0]);
 	attachments_offset = size;
 	size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]);
+	subpass_attachments_offset = size;
 
-	pass = vk_alloc2(&device->alloc, pAllocator, size, 8,
-			   VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+	uint32_t subpass_attachment_count = 0;
+	for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
+		const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i];
+
+		subpass_attachment_count +=
+			desc->inputAttachmentCount +
+			desc->colorAttachmentCount +
+			(desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +
+			(desc->pDepthStencilAttachment != NULL);
+	}
+	size += subpass_attachment_count * sizeof(VkAttachmentReference);
+
+	pass = vk_zalloc2(&device->alloc, pAllocator, size, 8,
+	                  VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 	if (pass == NULL)
 		return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(pass, 0, size);
 	pass->attachment_count = pCreateInfo->attachmentCount;
 	pass->subpass_count = pCreateInfo->subpassCount;
 	pass->attachments = (void *) pass + attachments_offset;
@@ -79,31 +92,8 @@ VkResult radv_CreateRenderPass(
 		// att->store_op = pCreateInfo->pAttachments[i].storeOp;
 		// att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
 	}
-	uint32_t subpass_attachment_count = 0;
-	VkAttachmentReference *p;
-	for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
-		const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i];
-
-		subpass_attachment_count +=
-			desc->inputAttachmentCount +
-			desc->colorAttachmentCount +
-			(desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +
-			(desc->pDepthStencilAttachment != NULL);
-	}
-
-	if (subpass_attachment_count) {
-		pass->subpass_attachments =
-			vk_alloc2(&device->alloc, pAllocator,
-				    subpass_attachment_count * sizeof(VkAttachmentReference), 8,
-				    VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
-		if (pass->subpass_attachments == NULL) {
-			vk_free2(&device->alloc, pAllocator, pass);
-			return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
-		}
-	} else
-		pass->subpass_attachments = NULL;
 
-	p = pass->subpass_attachments;
+	VkAttachmentReference *p = (void *) pass + subpass_attachments_offset;
 	for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
 		const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i];
 		uint32_t color_sample_count = 1, depth_sample_count = 1;
@@ -211,7 +201,6 @@ void radv_DestroyRenderPass(
 
 	if (!_pass)
 		return;
-	vk_free2(&device->alloc, pAllocator, pass->subpass_attachments);
 	vk_free2(&device->alloc, pAllocator, pass);
 }
 
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index a202697e935..8627b3c7696 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1726,7 +1726,6 @@ struct radv_render_pass_attachment {
 struct radv_render_pass {
 	uint32_t                                     attachment_count;
 	uint32_t                                     subpass_count;
-	VkAttachmentReference *                      subpass_attachments;
 	struct radv_render_pass_attachment *         attachments;
 	struct radv_subpass_barrier                  end_barrier;
 	struct radv_subpass                          subpasses[0];
-- 
2.17.0



More information about the mesa-dev mailing list