1 #ifndef _VKTRENDERPASSTESTSUTIL_HPP 2 #define _VKTRENDERPASSTESTSUTIL_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2018 The Khronos Group Inc. 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief RenderPass test utils 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "vkRef.hpp" 28 #include "vkDefs.hpp" 29 #include "vkMemUtil.hpp" 30 #include "vkTypeUtil.hpp" 31 32 #include <vector> 33 34 namespace vkt 35 { 36 namespace renderpass 37 { 38 39 using namespace vk; 40 41 enum RenderPassType 42 { 43 RENDERPASS_TYPE_LEGACY = 0, 44 RENDERPASS_TYPE_RENDERPASS2, 45 }; 46 47 class AttachmentDescription1 : public vk::VkAttachmentDescription 48 { 49 public: 50 AttachmentDescription1 (const void* pNext, 51 VkAttachmentDescriptionFlags flags, 52 VkFormat format, 53 VkSampleCountFlagBits samples, 54 VkAttachmentLoadOp loadOp, 55 VkAttachmentStoreOp storeOp, 56 VkAttachmentLoadOp stencilLoadOp, 57 VkAttachmentStoreOp stencilStoreOp, 58 VkImageLayout initialLayout, 59 VkImageLayout finalLayout); 60 }; 61 62 class AttachmentDescription2 : public vk::VkAttachmentDescription2KHR 63 { 64 public: 65 AttachmentDescription2 (const void* pNext, 66 VkAttachmentDescriptionFlags flags, 67 VkFormat format, 68 VkSampleCountFlagBits samples, 69 VkAttachmentLoadOp loadOp, 70 VkAttachmentStoreOp storeOp, 71 VkAttachmentLoadOp stencilLoadOp, 72 VkAttachmentStoreOp stencilStoreOp, 73 VkImageLayout initialLayout, 74 VkImageLayout finalLayout); 75 }; 76 77 class AttachmentReference1 : public vk::VkAttachmentReference 78 { 79 public: 80 AttachmentReference1 (const void* pNext, 81 deUint32 attachment, 82 VkImageLayout layout, 83 VkImageAspectFlags aspectMask); 84 }; 85 86 class AttachmentReference2 : public vk::VkAttachmentReference2KHR 87 { 88 public: 89 AttachmentReference2 (const void* pNext, 90 deUint32 attachment, 91 VkImageLayout layout, 92 VkImageAspectFlags aspectMask); 93 }; 94 95 class SubpassDescription1 : public vk::VkSubpassDescription 96 { 97 public: 98 SubpassDescription1 (const void* pNext, 99 VkSubpassDescriptionFlags flags, 100 VkPipelineBindPoint pipelineBindPoint, 101 deUint32 viewMask, 102 deUint32 inputAttachmentCount, 103 const VkAttachmentReference* pInputAttachments, 104 deUint32 colorAttachmentCount, 105 const VkAttachmentReference* pColorAttachments, 106 const VkAttachmentReference* pResolveAttachments, 107 const VkAttachmentReference* pDepthStencilAttachment, 108 deUint32 preserveAttachmentCount, 109 const deUint32* pPreserveAttachments); 110 }; 111 112 class SubpassDescription2 : public vk::VkSubpassDescription2KHR 113 { 114 public: 115 SubpassDescription2 (const void* pNext, 116 VkSubpassDescriptionFlags flags, 117 VkPipelineBindPoint pipelineBindPoint, 118 deUint32 viewMask, 119 deUint32 inputAttachmentCount, 120 const VkAttachmentReference2KHR* pInputAttachments, 121 deUint32 colorAttachmentCount, 122 const VkAttachmentReference2KHR* pColorAttachments, 123 const VkAttachmentReference2KHR* pResolveAttachments, 124 const VkAttachmentReference2KHR* pDepthStencilAttachment, 125 deUint32 preserveAttachmentCount, 126 const deUint32* pPreserveAttachments); 127 }; 128 129 class SubpassDependency1 : public vk::VkSubpassDependency 130 { 131 public: 132 SubpassDependency1 (const void* pNext, 133 deUint32 srcSubpass, 134 deUint32 dstSubpass, 135 VkPipelineStageFlags srcStageMask, 136 VkPipelineStageFlags dstStageMask, 137 VkAccessFlags srcAccessMask, 138 VkAccessFlags dstAccessMask, 139 VkDependencyFlags dependencyFlags, 140 deInt32 viewOffset); 141 }; 142 143 class SubpassDependency2 : public vk::VkSubpassDependency2KHR 144 { 145 public: 146 SubpassDependency2 (const void* pNext, 147 deUint32 srcSubpass, 148 deUint32 dstSubpass, 149 VkPipelineStageFlags srcStageMask, 150 VkPipelineStageFlags dstStageMask, 151 VkAccessFlags srcAccessMask, 152 VkAccessFlags dstAccessMask, 153 VkDependencyFlags dependencyFlags, 154 deInt32 viewOffset); 155 }; 156 157 class RenderPassCreateInfo1 : public VkRenderPassCreateInfo 158 { 159 public: 160 RenderPassCreateInfo1 (const void* pNext, 161 VkRenderPassCreateFlags flags, 162 deUint32 attachmentCount, 163 const VkAttachmentDescription* pAttachments, 164 deUint32 subpassCount, 165 const VkSubpassDescription* pSubpasses, 166 deUint32 dependencyCount, 167 const VkSubpassDependency* pDependencies, 168 deUint32 correlatedViewMaskCount, 169 const deUint32* pCorrelatedViewMasks); 170 171 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk, 172 VkDevice device) const; 173 }; 174 175 class RenderPassCreateInfo2 : public VkRenderPassCreateInfo2KHR 176 { 177 public: 178 RenderPassCreateInfo2 (const void* pNext, 179 VkRenderPassCreateFlags flags, 180 deUint32 attachmentCount, 181 const VkAttachmentDescription2KHR* pAttachments, 182 deUint32 subpassCount, 183 const VkSubpassDescription2KHR* pSubpasses, 184 deUint32 dependencyCount, 185 const VkSubpassDependency2KHR* pDependencies, 186 deUint32 correlatedViewMaskCount, 187 const deUint32* pCorrelatedViewMasks); 188 189 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk, 190 VkDevice device) const; 191 }; 192 193 class SubpassBeginInfo1 194 { 195 public: 196 SubpassBeginInfo1 (const void* pNext, 197 VkSubpassContents contents); 198 199 VkSubpassContents contents; 200 }; 201 202 class SubpassBeginInfo2 : public VkSubpassBeginInfoKHR 203 { 204 public: 205 SubpassBeginInfo2 (const void* pNext, 206 VkSubpassContents contents); 207 }; 208 209 class SubpassEndInfo1 210 { 211 public: 212 SubpassEndInfo1 (const void* pNext); 213 }; 214 215 class SubpassEndInfo2 : public VkSubpassEndInfoKHR 216 { 217 public: 218 SubpassEndInfo2 (const void* pNext); 219 }; 220 221 class RenderpassSubpass1 222 { 223 public: 224 typedef SubpassBeginInfo1 SubpassBeginInfo; 225 typedef SubpassEndInfo1 SubpassEndInfo; 226 227 static void cmdBeginRenderPass (const DeviceInterface& vk, 228 VkCommandBuffer cmdBuffer, 229 const VkRenderPassBeginInfo* pRenderPassBegin, 230 const SubpassBeginInfo* pSubpassBeginInfo); 231 232 static void cmdNextSubpass (const DeviceInterface& vk, 233 VkCommandBuffer cmdBuffer, 234 const SubpassBeginInfo* pSubpassBeginInfo, 235 const SubpassEndInfo* pSubpassEndInfo); 236 237 static void cmdEndRenderPass (const DeviceInterface& vk, 238 VkCommandBuffer cmdBuffer, 239 const SubpassEndInfo* pSubpassEndInfo); 240 }; 241 242 class RenderpassSubpass2 243 { 244 public: 245 typedef SubpassBeginInfo2 SubpassBeginInfo; 246 typedef SubpassEndInfo2 SubpassEndInfo; 247 248 static void cmdBeginRenderPass (const DeviceInterface& vk, 249 VkCommandBuffer cmdBuffer, 250 const VkRenderPassBeginInfo* pRenderPassBegin, 251 const SubpassBeginInfo* pSubpassBeginInfo); 252 253 static void cmdNextSubpass (const DeviceInterface& vk, 254 VkCommandBuffer cmdBuffer, 255 const SubpassBeginInfo* pSubpassBeginInfo, 256 const SubpassEndInfo* pSubpassEndInfo); 257 258 static void cmdEndRenderPass (const DeviceInterface& vk, 259 VkCommandBuffer cmdBuffer, 260 const SubpassEndInfo* pSubpassEndInfo); 261 }; 262 263 // For internal to RP/RP2 conversions 264 265 class AttachmentReference 266 { 267 public: 268 AttachmentReference (deUint32 attachment, 269 VkImageLayout layout, 270 VkImageAspectFlags aspectMask = static_cast<VkImageAspectFlags>(0u)); 271 272 deUint32 getAttachment (void) const; 273 VkImageLayout getImageLayout (void) const; 274 VkImageAspectFlags getAspectMask (void) const; 275 void setImageLayout (VkImageLayout layout); 276 277 private: 278 deUint32 m_attachment; 279 VkImageLayout m_layout; 280 VkImageAspectFlags m_aspectMask; 281 }; 282 283 class Subpass 284 { 285 public: 286 Subpass (VkPipelineBindPoint pipelineBindPoint, 287 VkSubpassDescriptionFlags flags, 288 const std::vector<AttachmentReference>& inputAttachments, 289 const std::vector<AttachmentReference>& colorAttachments, 290 const std::vector<AttachmentReference>& resolveAttachments, 291 AttachmentReference depthStencilAttachment, 292 const std::vector<deUint32>& preserveAttachments, 293 bool omitBlendState = false); 294 295 VkPipelineBindPoint getPipelineBindPoint (void) const; 296 VkSubpassDescriptionFlags getFlags (void) const; 297 const std::vector<AttachmentReference>& getInputAttachments (void) const; 298 const std::vector<AttachmentReference>& getColorAttachments (void) const; 299 const std::vector<AttachmentReference>& getResolveAttachments (void) const; 300 const AttachmentReference& getDepthStencilAttachment (void) const; 301 const std::vector<deUint32>& getPreserveAttachments (void) const; 302 bool getOmitBlendState (void) const; 303 304 private: 305 VkPipelineBindPoint m_pipelineBindPoint; 306 VkSubpassDescriptionFlags m_flags; 307 308 std::vector<AttachmentReference> m_inputAttachments; 309 std::vector<AttachmentReference> m_colorAttachments; 310 std::vector<AttachmentReference> m_resolveAttachments; 311 AttachmentReference m_depthStencilAttachment; 312 313 std::vector<deUint32> m_preserveAttachments; 314 bool m_omitBlendState; 315 }; 316 317 class SubpassDependency 318 { 319 public: 320 SubpassDependency (deUint32 srcPass, 321 deUint32 dstPass, 322 323 VkPipelineStageFlags srcStageMask, 324 VkPipelineStageFlags dstStageMask, 325 326 VkAccessFlags srcAccessMask, 327 VkAccessFlags dstAccessMask, 328 329 VkDependencyFlags flags); 330 331 deUint32 getSrcPass (void) const; 332 deUint32 getDstPass (void) const; 333 334 VkPipelineStageFlags getSrcStageMask (void) const; 335 VkPipelineStageFlags getDstStageMask (void) const; 336 337 VkAccessFlags getSrcAccessMask (void) const; 338 VkAccessFlags getDstAccessMask (void) const; 339 340 VkDependencyFlags getFlags (void) const; 341 342 private: 343 deUint32 m_srcPass; 344 deUint32 m_dstPass; 345 346 VkPipelineStageFlags m_srcStageMask; 347 VkPipelineStageFlags m_dstStageMask; 348 349 VkAccessFlags m_srcAccessMask; 350 VkAccessFlags m_dstAccessMask; 351 VkDependencyFlags m_flags; 352 }; 353 354 class Attachment 355 { 356 public: 357 Attachment (VkFormat format, 358 VkSampleCountFlagBits samples, 359 360 VkAttachmentLoadOp loadOp, 361 VkAttachmentStoreOp storeOp, 362 363 VkAttachmentLoadOp stencilLoadOp, 364 VkAttachmentStoreOp stencilStoreOp, 365 366 VkImageLayout initialLayout, 367 VkImageLayout finalLayout); 368 369 VkFormat getFormat (void) const; 370 VkSampleCountFlagBits getSamples (void) const; 371 372 VkAttachmentLoadOp getLoadOp (void) const; 373 VkAttachmentStoreOp getStoreOp (void) const; 374 375 VkAttachmentLoadOp getStencilLoadOp (void) const; 376 VkAttachmentStoreOp getStencilStoreOp (void) const; 377 378 VkImageLayout getInitialLayout (void) const; 379 VkImageLayout getFinalLayout (void) const; 380 381 private: 382 VkFormat m_format; 383 VkSampleCountFlagBits m_samples; 384 385 VkAttachmentLoadOp m_loadOp; 386 VkAttachmentStoreOp m_storeOp; 387 388 VkAttachmentLoadOp m_stencilLoadOp; 389 VkAttachmentStoreOp m_stencilStoreOp; 390 391 VkImageLayout m_initialLayout; 392 VkImageLayout m_finalLayout; 393 }; 394 395 class RenderPass 396 { 397 public: 398 RenderPass (const std::vector<Attachment>& attachments, 399 const std::vector<Subpass>& subpasses, 400 const std::vector<SubpassDependency>& dependencies, 401 const std::vector<VkInputAttachmentAspectReference> inputAspects = std::vector<VkInputAttachmentAspectReference>()); 402 403 const std::vector<Attachment>& getAttachments (void) const; 404 const std::vector<Subpass>& getSubpasses (void) const; 405 const std::vector<SubpassDependency>& getDependencies (void) const; 406 const std::vector<VkInputAttachmentAspectReference>& getInputAspects (void) const; 407 408 private: 409 std::vector<Attachment> m_attachments; 410 std::vector<Subpass> m_subpasses; 411 std::vector<SubpassDependency> m_dependencies; 412 std::vector<VkInputAttachmentAspectReference> m_inputAspects; 413 }; 414 415 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk, 416 VkDevice device, 417 const RenderPass& renderPassInfo, 418 const RenderPassType renderPassType); 419 420 } // renderpass 421 422 } // vkt 423 424 #endif // _VKTRENDERPASSTESTSUTIL_HPP 425