Created
August 14, 2017 13:46
-
-
Save mdomrach/372294fba3dcb1b55e5297e3fda439aa to your computer and use it in GitHub Desktop.
CreateRenderPass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void FVulkanApplication::CreateRenderPass() | |
{ | |
VkAttachmentDescription colorAttachment = {}; | |
colorAttachment.format = swapChain.colorFormat; | |
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; | |
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; | |
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; | |
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; | |
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; | |
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; | |
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; | |
VkAttachmentDescription depthAttachment = {}; | |
// depthAttachment.format is set to VK_FORMAT_D32_SFLOAT on machine | |
depthAttachment.format = FVulkanCalculator::FindDepthFormat(vulkanDevice.physicalDevice); | |
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT; | |
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; | |
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; | |
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; | |
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; | |
depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; | |
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; | |
VkAttachmentReference colorAttachmentRef = {}; | |
colorAttachmentRef.attachment = 0; | |
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; | |
VkAttachmentReference depthAttachmentRef = {}; | |
depthAttachmentRef.attachment = 1; | |
depthAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; | |
VkSubpassDescription subPass = {}; | |
subPass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; | |
subPass.colorAttachmentCount = 1; | |
subPass.pColorAttachments = &colorAttachmentRef; | |
subPass.pDepthStencilAttachment = &depthAttachmentRef; | |
VkSubpassDependency dependency = {}; | |
dependency.srcSubpass = VK_SUBPASS_EXTERNAL; | |
dependency.dstSubpass = 0; | |
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; | |
dependency.srcAccessMask = 0; | |
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; | |
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | |
std::array<VkAttachmentDescription, 2> attachments = { colorAttachment, depthAttachment }; | |
VkRenderPassCreateInfo renderPassInfo = FVulkanInitializers::RenderPassCreateInfo(); | |
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); | |
renderPassInfo.pAttachments = attachments.data(); | |
renderPassInfo.subpassCount = 1; | |
renderPassInfo.pSubpasses = &subPass; | |
renderPassInfo.dependencyCount = 1; | |
renderPassInfo.pDependencies = &dependency; | |
if (vkCreateRenderPass(vulkanDevice.logicalDevice, &renderPassInfo, nullptr, &renderPass) != VK_SUCCESS) | |
{ | |
throw std::runtime_error("failed to create render pass!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment