whillothewhisp

Renderpass creation

Jan 4th, 2022 (edited)
1,821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | None | 0 0
  1. //object picking pass
  2.  
  3. //color attachment with 1 msaa samples and a format of VK_FORMAT_R32_SFLOAT, we also clear both color and depth on load
  4. VkAttachmentDescription object_picking_colorAttachment{};
  5. object_picking_colorAttachment.format = VK_FORMAT_R32_SFLOAT;
  6. object_picking_colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
  7. object_picking_colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
  8. object_picking_colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
  9. object_picking_colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
  10. object_picking_colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
  11. object_picking_colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  12. object_picking_colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
  13.  
  14. //depth attachment with 1 msaa sample
  15. VkAttachmentDescription object_picking_depthAttachment{};
  16. object_picking_depthAttachment.format = find_depth_format();
  17. object_picking_depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
  18. object_picking_depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
  19. object_picking_depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
  20. object_picking_depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
  21. object_picking_depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
  22. object_picking_depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  23. object_picking_depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
  24.  
  25. VkAttachmentReference object_picking_colorAttachmentRef{};
  26. object_picking_colorAttachmentRef.attachment = 0;
  27. object_picking_colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
  28.  
  29. VkAttachmentReference object_picking_depthAttachmentRef{};
  30. object_picking_depthAttachmentRef.attachment = 1;
  31. object_picking_depthAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
  32.  
  33. VkSubpassDescription object_picking_subpass{};
  34. object_picking_subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
  35. object_picking_subpass.colorAttachmentCount = 1;
  36. object_picking_subpass.pColorAttachments = &object_picking_colorAttachmentRef;
  37. object_picking_subpass.pDepthStencilAttachment = &object_picking_depthAttachmentRef;
  38.  
  39. VkSubpassDependency object_picking_dependency{};
  40. object_picking_dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
  41. object_picking_dependency.dstSubpass = 0;
  42. object_picking_dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
  43. object_picking_dependency.srcAccessMask = 0;
  44. object_picking_dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
  45. object_picking_dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
  46.  
  47. std::array<VkAttachmentDescription, 2 > object_picking_attachments = { object_picking_colorAttachment,object_picking_depthAttachment };
  48. VkRenderPassCreateInfo object_picking_renderPassInfo{};
  49. object_picking_renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
  50. object_picking_renderPassInfo.attachmentCount = static_cast<uint32_t>(object_picking_attachments.size());
  51. object_picking_renderPassInfo.pAttachments = object_picking_attachments.data();
  52. object_picking_renderPassInfo.subpassCount = 1;
  53. object_picking_renderPassInfo.pSubpasses = &object_picking_subpass;
  54. object_picking_renderPassInfo.dependencyCount = 1;
  55. object_picking_renderPassInfo.pDependencies = &object_picking_dependency;
  56.  
  57. if (vkCreateRenderPass(device, &object_picking_renderPassInfo, nullptr, &object_picking_pass) != VK_SUCCESS)
  58. {
  59.     throw std::runtime_error("failed to create render pass!");
  60. }
Add Comment
Please, Sign In to add comment