Tony-LunarG | 7371999 | 2020-01-15 10:20:28 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2020 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2020 Valve Corporation |
| 3 | * Copyright (c) 2015-2020 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2020 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 | |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 28 | static safe_VkAttachmentDescription2 ToV2KHR(const VkAttachmentDescription& in_struct) { |
| 29 | safe_VkAttachmentDescription2 v2; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 30 | v2.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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 | |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 45 | static safe_VkAttachmentReference2 ToV2KHR(const VkAttachmentReference& in_struct, const VkImageAspectFlags aspectMask = 0) { |
| 46 | safe_VkAttachmentReference2 v2; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 47 | v2.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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 | |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 56 | static safe_VkSubpassDescription2 ToV2KHR(const VkSubpassDescription& in_struct, const uint32_t viewMask, |
| 57 | const VkImageAspectFlags* input_attachment_aspect_masks) { |
| 58 | safe_VkSubpassDescription2 v2; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 59 | v2.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 74 | v2.pInputAttachments = new safe_VkAttachmentReference2[v2.inputAttachmentCount]; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 80 | v2.pColorAttachments = new safe_VkAttachmentReference2[v2.colorAttachmentCount]; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 86 | v2.pResolveAttachments = new safe_VkAttachmentReference2[v2.colorAttachmentCount]; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 92 | v2.pDepthStencilAttachment = new safe_VkAttachmentReference2(); |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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 | |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 106 | static safe_VkSubpassDependency2 ToV2KHR(const VkSubpassDependency& in_struct, int32_t viewOffset = 0) { |
| 107 | safe_VkSubpassDependency2 v2; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 108 | v2.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 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 | |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 122 | void ConvertVkRenderPassCreateInfoToV2KHR(const VkRenderPassCreateInfo& in_struct, safe_VkRenderPassCreateInfo2* out_struct) { |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 123 | using std::vector; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 124 | const auto multiview_info = LvlFindInChain<VkRenderPassMultiviewCreateInfo>(in_struct.pNext); |
| 125 | const auto* input_attachment_aspect_info = LvlFindInChain<VkRenderPassInputAttachmentAspectCreateInfo>(in_struct.pNext); |
| 126 | const auto fragment_density_map_info = LvlFindInChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(in_struct.pNext); |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 127 | |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 128 | out_struct->~safe_VkRenderPassCreateInfo2(); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 129 | out_struct->sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2; |
Mark Lobodzinski | 799a92b | 2020-08-17 16:35:14 -0600 | [diff] [blame] | 130 | |
| 131 | // Fixup RPCI2 pNext chain. Only FDM2 is valid on both chains. |
| 132 | if (fragment_density_map_info) { |
| 133 | out_struct->pNext = SafePnextCopy(fragment_density_map_info); |
| 134 | auto base_struct = reinterpret_cast<const VkBaseOutStructure*>(out_struct->pNext); |
| 135 | const_cast<VkBaseOutStructure*>(base_struct)->pNext = nullptr; |
| 136 | } else { |
| 137 | out_struct->pNext = nullptr; |
| 138 | } |
| 139 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 140 | out_struct->flags = in_struct.flags; |
| 141 | out_struct->attachmentCount = in_struct.attachmentCount; |
| 142 | out_struct->pAttachments = nullptr; // to be filled |
| 143 | out_struct->subpassCount = in_struct.subpassCount; |
| 144 | out_struct->pSubpasses = nullptr; // to be filled |
| 145 | out_struct->dependencyCount = in_struct.dependencyCount; |
| 146 | out_struct->pDependencies = nullptr; // to be filled |
| 147 | out_struct->correlatedViewMaskCount = multiview_info ? multiview_info->correlationMaskCount : 0; |
| 148 | out_struct->pCorrelatedViewMasks = nullptr; // to be filled |
| 149 | |
| 150 | // TODO: This should support VkRenderPassFragmentDensityMapCreateInfoEXT somehow |
| 151 | // see https://github.com/KhronosGroup/Vulkan-Docs/issues/1027 |
| 152 | |
| 153 | if (out_struct->attachmentCount && in_struct.pAttachments) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 154 | out_struct->pAttachments = new safe_VkAttachmentDescription2[out_struct->attachmentCount]; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 155 | for (uint32_t i = 0; i < out_struct->attachmentCount; ++i) { |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 156 | out_struct->pAttachments[i] = ToV2KHR(in_struct.pAttachments[i]); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 157 | } |
| 158 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 159 | |
| 160 | // translate VkRenderPassInputAttachmentAspectCreateInfo into vector |
| 161 | vector<vector<VkImageAspectFlags>> input_attachment_aspect_masks(out_struct->subpassCount); |
| 162 | // set defaults |
| 163 | for (uint32_t si = 0; si < out_struct->subpassCount; ++si) { |
| 164 | if (in_struct.pSubpasses) { |
| 165 | input_attachment_aspect_masks[si].resize(in_struct.pSubpasses[si].inputAttachmentCount, 0); |
| 166 | |
| 167 | for (uint32_t iai = 0; iai < in_struct.pSubpasses[si].inputAttachmentCount; ++iai) { |
| 168 | if (out_struct->pAttachments && in_struct.pSubpasses[si].pInputAttachments) { |
| 169 | const auto& input_attachment = in_struct.pSubpasses[si].pInputAttachments[iai]; |
Tony-LunarG | f563bc7 | 2019-12-18 11:33:37 -0700 | [diff] [blame] | 170 | if (input_attachment.attachment != VK_ATTACHMENT_UNUSED) { |
| 171 | const auto format = out_struct->pAttachments[input_attachment.attachment].format; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 172 | |
Tony-LunarG | f563bc7 | 2019-12-18 11:33:37 -0700 | [diff] [blame] | 173 | if (FormatIsColor(format)) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_COLOR_BIT; |
| 174 | if (FormatHasDepth(format)) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 175 | if (FormatHasStencil(format)) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 176 | if (FormatPlaneCount(format) > 1) { |
| 177 | input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_PLANE_0_BIT; |
| 178 | input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 179 | } |
| 180 | if (FormatPlaneCount(format) > 2) input_attachment_aspect_masks[si][iai] |= VK_IMAGE_ASPECT_PLANE_2_BIT; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 181 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | // translate VkRenderPassInputAttachmentAspectCreateInfo |
| 187 | if (input_attachment_aspect_info && input_attachment_aspect_info->pAspectReferences) { |
| 188 | for (uint32_t i = 0; i < input_attachment_aspect_info->aspectReferenceCount; ++i) { |
| 189 | const uint32_t subpass = input_attachment_aspect_info->pAspectReferences[i].subpass; |
| 190 | const uint32_t input_attachment = input_attachment_aspect_info->pAspectReferences[i].inputAttachmentIndex; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 191 | const VkImageAspectFlags aspect_mask = input_attachment_aspect_info->pAspectReferences[i].aspectMask; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 192 | |
| 193 | if (subpass < input_attachment_aspect_masks.size() && |
| 194 | input_attachment < input_attachment_aspect_masks[subpass].size()) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 195 | input_attachment_aspect_masks[subpass][input_attachment] = aspect_mask; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 200 | const bool has_view_mask = multiview_info && multiview_info->subpassCount && multiview_info->pViewMasks; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 201 | if (out_struct->subpassCount && in_struct.pSubpasses) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 202 | out_struct->pSubpasses = new safe_VkSubpassDescription2[out_struct->subpassCount]; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 203 | for (uint32_t i = 0; i < out_struct->subpassCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 204 | const uint32_t view_mask = has_view_mask ? multiview_info->pViewMasks[i] : 0; |
| 205 | out_struct->pSubpasses[i] = ToV2KHR(in_struct.pSubpasses[i], view_mask, input_attachment_aspect_masks[i].data()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 206 | } |
| 207 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 208 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 209 | const bool has_view_offset = multiview_info && multiview_info->dependencyCount && multiview_info->pViewOffsets; |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 210 | if (out_struct->dependencyCount && in_struct.pDependencies) { |
Mike Schuchardt | f6f0049 | 2019-10-21 23:35:17 -0700 | [diff] [blame] | 211 | out_struct->pDependencies = new safe_VkSubpassDependency2[out_struct->dependencyCount]; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 212 | for (uint32_t i = 0; i < out_struct->dependencyCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 213 | const int32_t view_offset = has_view_offset ? multiview_info->pViewOffsets[i] : 0; |
| 214 | out_struct->pDependencies[i] = ToV2KHR(in_struct.pDependencies[i], view_offset); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 218 | if (out_struct->correlatedViewMaskCount && multiview_info->pCorrelationMasks) { |
| 219 | auto correlated_view_masks = new uint32_t[out_struct->correlatedViewMaskCount]; |
| 220 | for (uint32_t i = 0; i < out_struct->correlatedViewMaskCount; ++i) { |
| 221 | correlated_view_masks[i] = multiview_info->pCorrelationMasks[i]; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 222 | } |
Petr Kraus | cbabebd | 2019-08-24 02:40:41 +0200 | [diff] [blame] | 223 | out_struct->pCorrelatedViewMasks = correlated_view_masks; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 224 | } |
| 225 | } |