| 971 | } |
| 972 | |
| 973 | VkResult CreateRenderPass(VkDevice vk_device, VkSampleCountFlagBits vk_sample_flags, |
| 974 | RenderPassAttachment* colorAttachments, uint8_t numColorAttachments, |
| 975 | RenderPassAttachment* depthStencilAttachment, |
| 976 | RenderPassAttachment* resolveAttachment, |
| 977 | VkRenderPass* renderPassOut) |
| 978 | { |
| 979 | assert(*renderPassOut == VK_NULL_HANDLE); |
| 980 | |
| 981 | const uint8_t num_depth_attachments = (depthStencilAttachment ? 1 : 0); |
| 982 | const uint8_t num_attachments = numColorAttachments + num_depth_attachments + (resolveAttachment ? 1 : 0); |
| 983 | VkAttachmentDescription* vk_attachment_desc = new VkAttachmentDescription[num_attachments]; |
| 984 | VkAttachmentReference* vk_attachment_color_ref = new VkAttachmentReference[numColorAttachments]; |
| 985 | VkAttachmentReference vk_attachment_depth_ref = {}; |
| 986 | VkAttachmentReference vk_attachment_resolve_ref = {}; |
| 987 | |
| 988 | memset(vk_attachment_desc, 0, sizeof(VkAttachmentDescription) * num_attachments); |
| 989 | memset(vk_attachment_color_ref, 0, sizeof(VkAttachmentReference) * numColorAttachments); |
| 990 | |
| 991 | for (uint16_t i=0; i < numColorAttachments; i++) |
| 992 | { |
| 993 | VkAttachmentDescription& attachment_color = vk_attachment_desc[i]; |
| 994 | |
| 995 | attachment_color.format = colorAttachments[i].m_Format; |
| 996 | attachment_color.samples = vk_sample_flags; |
| 997 | attachment_color.loadOp = colorAttachments[i].m_LoadOp; |
| 998 | attachment_color.storeOp = colorAttachments[i].m_StoreOp; |
| 999 | attachment_color.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 1000 | attachment_color.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 1001 | attachment_color.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 1002 | attachment_color.finalLayout = colorAttachments[i].m_ImageLayout; |
| 1003 | |
| 1004 | if (colorAttachments[i].m_LoadOp != VK_ATTACHMENT_LOAD_OP_DONT_CARE) |
| 1005 | { |
| 1006 | attachment_color.initialLayout = colorAttachments[i].m_ImageLayoutInitial; |
| 1007 | } |
| 1008 | |
| 1009 | VkAttachmentReference& ref = vk_attachment_color_ref[i]; |
| 1010 | ref.attachment = i; |
| 1011 | ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1012 | } |
| 1013 | |
| 1014 | if (depthStencilAttachment) |
| 1015 | { |
| 1016 | VkAttachmentDescription& attachment_depth = vk_attachment_desc[numColorAttachments]; |
| 1017 | |
| 1018 | attachment_depth.format = depthStencilAttachment->m_Format; |
| 1019 | attachment_depth.samples = vk_sample_flags; |
| 1020 | attachment_depth.loadOp = depthStencilAttachment->m_LoadOp; |
| 1021 | attachment_depth.storeOp = depthStencilAttachment->m_StoreOp; |
| 1022 | // Keep depth and stencil load ops in sync for packed depth/stencil attachments so |
| 1023 | // the render-pass CLEAR fast path actually clears stencil too. |
| 1024 | attachment_depth.stencilLoadOp = depthStencilAttachment->m_LoadOp; |
| 1025 | attachment_depth.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 1026 | attachment_depth.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 1027 | attachment_depth.finalLayout = depthStencilAttachment->m_ImageLayout; |
| 1028 | |
| 1029 | if (depthStencilAttachment->m_LoadOp != VK_ATTACHMENT_LOAD_OP_DONT_CARE) |
| 1030 | { |
no test coverage detected