- uint64_t key = hash<64>(static_cast<uint8_t>(clear | (discard*2) | (to_present*4)));
- for(FrameAttachment a: format)
- key = hash_update<64>(key, a);
-
- auto j = render_passes.find(key);
- if(j!=render_passes.end())
- return j->second;
-
- VkAttachmentDescription attachments[FrameFormat::MAX_ATTACHMENTS] = { };
- VkAttachmentReference color_refs[FrameFormat::MAX_ATTACHMENTS] = { };
- VkAttachmentReference depth_stencil_ref = { };
- depth_stencil_ref.attachment = VK_ATTACHMENT_UNUSED;
-
- VkSampleCountFlagBits vk_samples = static_cast<VkSampleCountFlagBits>(get_vulkan_samples(format.get_samples()));
-
- unsigned i = 0;
- unsigned color_count = 0;
- for(FrameAttachment a: format)
- {
- attachments[i].format = static_cast<VkFormat>(get_vulkan_pixelformat(get_attachment_pixelformat(a)));
- attachments[i].samples = vk_samples;
- attachments[i].loadOp = (clear ? discard ? VK_ATTACHMENT_LOAD_OP_DONT_CARE : VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD);
- attachments[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
- attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
- attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
- attachments[i].initialLayout = (clear ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
- attachments[i].finalLayout = (to_present ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
-
- unsigned attach_pt = get_attach_point(a);
- if(attach_pt==get_attach_point(COLOR_ATTACHMENT))
- {
- color_refs[color_count].attachment = i;
- color_refs[color_count].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
- ++color_count;
- }
- else if(attach_pt==get_attach_point(DEPTH_ATTACHMENT))
- {
- depth_stencil_ref.attachment = i;
- depth_stencil_ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
- }
-
- ++i;
- }
-
- VkSubpassDescription subpass = { };
- subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
- subpass.colorAttachmentCount = color_count;
- subpass.pColorAttachments = color_refs;
- subpass.pDepthStencilAttachment = &depth_stencil_ref;
-
- VkRenderPassCreateInfo render_pass_info = { };
- render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
- render_pass_info.attachmentCount = format.size();
- render_pass_info.pAttachments = attachments;
- render_pass_info.subpassCount = 1;
- render_pass_info.pSubpasses = &subpass;