Create renderpass
The render pass is the core object for describing the general rendering process in Vulkan. It is a required part of rendering with Vulkan, and influences both the graphics pipeline state and all framebuffers.
The renderpass describes a list of attachments, a list of subpasses and a list of dependencies. The attachments contain the format, layouts before and after the renderpass, and the operations to be performed on this attachment for the duration of the renderpass.
Render passes allow the driver implementation to prepare for the rendering process beforehand, determining what barriers will be needed and where, and allowing for optimization primarily on mobile devices. For more info, refer to the Render pass page in API outline.
result = vkCreateRenderPass (
renderer->device,
&(VkRenderPassCreateInfo){
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.attachmentCount = 2,
.pAttachments = (VkAttachmentDescription[2]){
[0] = {
.flags = 0,
.format = VK_FORMAT_R8G8B8A8_UNORM,
.samples = VK_SAMPLE_COUNT_1_BIT,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
},
[1] = {
.flags = 0,
.format = VK_FORMAT_D32_SFLOAT,
.samples = VK_SAMPLE_COUNT_1_BIT,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
},
.subpassCount = 1,
.pSubpasses = (VkSubpassDescription[1]){
[0] = {
.flags = 0,
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.inputAttachmentCount = 0,
.pInputAttachments = NULL,
.colorAttachmentCount = 1,
.pColorAttachments = (VkAttachmentReference[1]){
[0] = {
.attachment = 0,
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
},
},
.pResolveAttachments = NULL,
.pDepthStencilAttachment = &(VkAttachmentReference){
.attachment = 1,
.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
.preserveAttachmentCount = 0,
.pPreserveAttachments = NULL,
},
},
.dependencyCount = 0,
.pDependencies = NULL,
},
NULL,
&renderer->renderPass
);
if ( result != VK_SUCCESS )
RETURN_ERROR(-1, "vkCreateRenderPass failed (0x%08X)", (uint32_t)result);