Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 1 | /* Copyright (c) 2015-2019 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2019 Valve Corporation |
| 3 | * Copyright (c) 2015-2019 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2019 Google Inc. |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Tobias Hector <@tobski> |
| 19 | */ |
| 20 | |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 21 | #include "convert_to_renderpass2.h" |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 22 | |
| 23 | #include <vector> |
| 24 | |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 25 | #include "vk_format_utils.h" |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 26 | #include "vk_typemap_helper.h" |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 27 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 28 | static safe_VkAttachmentDescription2KHR ToV2KHR(const VkAttachmentDescription& in_struct) { |
| 29 | safe_VkAttachmentDescription2KHR v2; |
| 30 | v2.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR; |
| 31 | v2.pNext = nullptr; |
| 32 | v2.flags = in_struct.flags; |
| 33 | v2.format = in_struct.format; |
| 34 | v2.samples = in_struct.samples; |
| 35 | v2.loadOp = in_struct.loadOp; |
| 36 | v2.storeOp = in_struct.storeOp; |
| 37 | v2.stencilLoadOp = in_struct.stencilLoadOp; |
| 38 | v2.stencilStoreOp = in_struct.stencilStoreOp; |
| 39 | v2.initialLayout = in_struct.initialLayout; |
| 40 | v2.finalLayout = in_struct.finalLayout; |
| 41 | |
| 42 | return v2; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 45 | static safe_VkAttachmentReference2KHR ToV2KHR(const VkAttachmentReference& in_struct, const VkImageAspectFlags aspectMask = 0) { |
| 46 | safe_VkAttachmentReference2KHR v2; |
| 47 | v2.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR; |
| 48 | v2.pNext = nullptr; |
| 49 | v2.attachment = in_struct.attachment; |
| 50 | v2.layout = in_struct.layout; |
| 51 | v2.aspectMask = aspectMask; |
| 52 | |
| 53 | return v2; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 56 | static safe_VkSubpassDescription2KHR ToV2KHR(const VkSubpassDescription& in_struct, const uint32_t viewMask, |
| 57 | const VkImageAspectFlags* input_attachment_aspect_masks) { |
| 58 | safe_VkSubpassDescription2KHR v2; |
| 59 | v2.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR; |
| 60 | v2.pNext = nullptr; |
| 61 | v2.flags = in_struct.flags; |
| 62 | v2.pipelineBindPoint = in_struct.pipelineBindPoint; |
| 63 | v2.viewMask = viewMask; |
| 64 | v2.inputAttachmentCount = in_struct.inputAttachmentCount; |
| 65 | v2.pInputAttachments = nullptr; // to be filled |
| 66 | v2.colorAttachmentCount = in_struct.colorAttachmentCount; |
| 67 | v2.pColorAttachments = nullptr; // to be filled |
| 68 | v2.pResolveAttachments = nullptr; // to be filled |
| 69 | v2.pDepthStencilAttachment = nullptr; // to be filled |
| 70 | v2.preserveAttachmentCount = in_struct.preserveAttachmentCount; |
| 71 | v2.pPreserveAttachments = nullptr; // to be filled |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 72 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 73 | if (v2.inputAttachmentCount && in_struct.pInputAttachments) { |
| 74 | v2.pInputAttachments = new safe_VkAttachmentReference2KHR[v2.inputAttachmentCount]; |
| 75 | for (uint32_t i = 0; i < v2.inputAttachmentCount; ++i) { |
| 76 | v2.pInputAttachments[i] = ToV2KHR(in_struct.pInputAttachments[i], input_attachment_aspect_masks[i]); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 77 | } |
| 78 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 79 | if (v2.colorAttachmentCount && in_struct.pColorAttachments) { |
| 80 | v2.pColorAttachments = new safe_VkAttachmentReference2KHR[v2.colorAttachmentCount]; |
| 81 | for (uint32_t i = 0; i < v2.colorAttachmentCount; ++i) { |
| 82 | v2.pColorAttachments[i] = ToV2KHR(in_struct.pColorAttachments[i]); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 83 | } |
| 84 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 85 | if (v2.colorAttachmentCount && in_struct.pResolveAttachments) { |
| 86 | v2.pResolveAttachments = new safe_VkAttachmentReference2KHR[v2.colorAttachmentCount]; |
| 87 | for (uint32_t i = 0; i < v2.colorAttachmentCount; ++i) { |
| 88 | v2.pResolveAttachments[i] = ToV2KHR(in_struct.pResolveAttachments[i]); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 89 | } |
| 90 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 91 | if (in_struct.pDepthStencilAttachment) { |
| 92 | v2.pDepthStencilAttachment = new safe_VkAttachmentReference2KHR(); |
| 93 | *v2.pDepthStencilAttachment = ToV2KHR(*in_struct.pDepthStencilAttachment); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 94 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 95 | if (v2.preserveAttachmentCount && in_struct.pPreserveAttachments) { |
| 96 | auto preserve_attachments = new uint32_t[v2.preserveAttachmentCount]; |
| 97 | for (uint32_t i = 0; i < v2.preserveAttachmentCount; ++i) { |
| 98 | preserve_attachments[i] = in_struct.pPreserveAttachments[i]; |
| 99 | } |
| 100 | v2.pPreserveAttachments = preserve_attachments; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 101 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 102 | |
| 103 | return v2; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 106 | static safe_VkSubpassDependency2KHR ToV2KHR(const VkSubpassDependency& in_struct, int32_t viewOffset = 0) { |
| 107 | safe_VkSubpassDependency2KHR v2; |
| 108 | v2.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2_KHR; |
| 109 | v2.pNext = nullptr; |
| 110 | v2.srcSubpass = in_struct.srcSubpass; |
| 111 | v2.dstSubpass = in_struct.dstSubpass; |
| 112 | v2.srcStageMask = in_struct.srcStageMask; |
| 113 | v2.dstStageMask = in_struct.dstStageMask; |
| 114 | v2.srcAccessMask = in_struct.srcAccessMask; |
| 115 | v2.dstAccessMask = in_struct.dstAccessMask; |
| 116 | v2.dependencyFlags = in_struct.dependencyFlags; |
| 117 | v2.viewOffset = viewOffset; |
| 118 | |
| 119 | return v2; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 122 | void ConvertVkRenderPassCreateInfoToV2KHR(const VkRenderPassCreateInfo& in_struct, safe_VkRenderPassCreateInfo2KHR* out_struct) { |
| 123 | using std::vector; |
| 124 | const auto multiview_info = lvl_find_in_chain<VkRenderPassMultiviewCreateInfo>(in_struct.pNext); |
| 125 | const auto* input_attachment_aspect_info = lvl_find_in_chain<VkRenderPassInputAttachmentAspectCreateInfo>(in_struct.pNext); |
| 126 | |
| 127 | out_struct->~safe_VkRenderPassCreateInfo2KHR(); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 128 | out_struct->sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR; |
| 129 | out_struct->pNext = nullptr; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 130 | out_struct->flags = in_struct.flags; |
| 131 | out_struct->attachmentCount = in_struct.attachmentCount; |
| 132 | out_struct->pAttachments = nullptr; // to be filled |
| 133 | out_struct->subpassCount = in_struct.subpassCount; |
| 134 | out_struct->pSubpasses = nullptr; // to be filled |
| 135 | out_struct->dependencyCount = in_struct.dependencyCount; |
| 136 | out_struct->pDependencies = nullptr; // to be filled |
| 137 | out_struct->correlatedViewMaskCount = multiview_info ? multiview_info->correlationMaskCount : 0; |
| 138 | out_struct->pCorrelatedViewMasks = nullptr; // to be filled |
| 139 | |
| 140 | // TODO: This should support VkRenderPassFragmentDensityMapCreateInfoEXT somehow |
| 141 | // see https://github.com/KhronosGroup/Vulkan-Docs/issues/1027 |
| 142 | |
| 143 | if (out_struct->attachmentCount && in_struct.pAttachments) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 144 | out_struct->pAttachments = new safe_VkAttachmentDescription2KHR[out_struct->attachmentCount]; |
| 145 | for (uint32_t i = 0; i < out_struct->attachmentCount; ++i) { |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 146 | out_struct->pAttachments[i] = ToV2KHR(in_struct.pAttachments[i]); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 147 | } |
| 148 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 149 | |
| 150 | // translate VkRenderPassInputAttachmentAspectCreateInfo into vector |
| 151 | vector<vector<VkImageAspectFlags>> input_attachment_aspect_masks(out_struct->subpassCount); |
| 152 | // set defaults |
| 153 | for (uint32_t si = 0; si < out_struct->subpassCount; ++si) { |
| 154 | if (in_struct.pSubpasses) { |
| 155 | input_attachment_aspect_masks[si].resize(in_struct.pSubpasses[si].inputAttachmentCount, 0); |
| 156 | |
| 157 | for (uint32_t iai = 0; iai < in_struct.pSubpasses[si].inputAttachmentCount; ++iai) { |
| 158 | if (out_struct->pAttachments && in_struct.pSubpasses[si].pInputAttachments) { |
| 159 | const auto& input_attachment = in_struct.pSubpasses[si].pInputAttachments[iai]; |
| 160 | const auto format = out_struct->pAttachments[input_attachment.attachment].format; |
| 161 | |
| 162 | if (FormatIsColor(format)) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_COLOR_BIT; |
| 163 | if (FormatHasDepth(format)) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 164 | if (FormatHasStencil(format)) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 165 | if (FormatPlaneCount(format) > 1) { |
| 166 | input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_PLANE_0_BIT; |
| 167 | input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 168 | } |
| 169 | if (FormatPlaneCount(format) > 2) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | // translate VkRenderPassInputAttachmentAspectCreateInfo |
| 175 | if (input_attachment_aspect_info && input_attachment_aspect_info->pAspectReferences) { |
| 176 | for (uint32_t i = 0; i < input_attachment_aspect_info->aspectReferenceCount; ++i) { |
| 177 | const uint32_t subpass = input_attachment_aspect_info->pAspectReferences[i].subpass; |
| 178 | const uint32_t input_attachment = input_attachment_aspect_info->pAspectReferences[i].inputAttachmentIndex; |
| 179 | const VkImageAspectFlags aspectMask = input_attachment_aspect_info->pAspectReferences[i].aspectMask; |
| 180 | |
| 181 | if (subpass < input_attachment_aspect_masks.size() && |
| 182 | input_attachment < input_attachment_aspect_masks[subpass].size()) { |
| 183 | input_attachment_aspect_masks[subpass][input_attachment] = aspectMask; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | const bool has_viewMask = multiview_info && multiview_info->subpassCount && multiview_info->pViewMasks; |
| 189 | if (out_struct->subpassCount && in_struct.pSubpasses) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 190 | out_struct->pSubpasses = new safe_VkSubpassDescription2KHR[out_struct->subpassCount]; |
| 191 | for (uint32_t i = 0; i < out_struct->subpassCount; ++i) { |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 192 | const uint32_t viewMask = has_viewMask ? multiview_info->pViewMasks[i] : 0; |
| 193 | out_struct->pSubpasses[i] = ToV2KHR(in_struct.pSubpasses[i], viewMask, input_attachment_aspect_masks[i].data()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 194 | } |
| 195 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 196 | |
| 197 | const bool has_viewOffset = multiview_info && multiview_info->dependencyCount && multiview_info->pViewOffsets; |
| 198 | if (out_struct->dependencyCount && in_struct.pDependencies) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 199 | out_struct->pDependencies = new safe_VkSubpassDependency2KHR[out_struct->dependencyCount]; |
| 200 | for (uint32_t i = 0; i < out_struct->dependencyCount; ++i) { |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 201 | const int32_t viewOffset = has_viewOffset ? multiview_info->pViewOffsets[i] : 0; |
| 202 | out_struct->pDependencies[i] = ToV2KHR(in_struct.pDependencies[i], viewOffset); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 206 | if (out_struct->correlatedViewMaskCount && multiview_info->pCorrelationMasks) { |
| 207 | auto correlated_view_masks = new uint32_t[out_struct->correlatedViewMaskCount]; |
| 208 | for (uint32_t i = 0; i < out_struct->correlatedViewMaskCount; ++i) { |
| 209 | correlated_view_masks[i] = multiview_info->pCorrelationMasks[i]; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 210 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame^] | 211 | out_struct->pCorrelatedViewMasks = correlated_view_masks; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 212 | } |
| 213 | } |