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 enum SynchronizationType 48 { 49 SYNCHRONIZATION_TYPE_LEGACY = 0, 50 SYNCHRONIZATION_TYPE_SYNCHRONIZATION2, 51 }; 52 53 class AttachmentDescription1 : public vk::VkAttachmentDescription 54 { 55 public: 56 AttachmentDescription1 (const void* pNext, 57 VkAttachmentDescriptionFlags flags, 58 VkFormat format, 59 VkSampleCountFlagBits samples, 60 VkAttachmentLoadOp loadOp, 61 VkAttachmentStoreOp storeOp, 62 VkAttachmentLoadOp stencilLoadOp, 63 VkAttachmentStoreOp stencilStoreOp, 64 VkImageLayout initialLayout, 65 VkImageLayout finalLayout); 66 }; 67 68 class AttachmentDescription2 : public vk::VkAttachmentDescription2 69 { 70 public: 71 AttachmentDescription2 (const void* pNext, 72 VkAttachmentDescriptionFlags flags, 73 VkFormat format, 74 VkSampleCountFlagBits samples, 75 VkAttachmentLoadOp loadOp, 76 VkAttachmentStoreOp storeOp, 77 VkAttachmentLoadOp stencilLoadOp, 78 VkAttachmentStoreOp stencilStoreOp, 79 VkImageLayout initialLayout, 80 VkImageLayout finalLayout); 81 }; 82 83 class AttachmentReference1 : public vk::VkAttachmentReference 84 { 85 public: 86 AttachmentReference1 (const void* pNext, 87 deUint32 attachment, 88 VkImageLayout layout, 89 VkImageAspectFlags aspectMask); 90 }; 91 92 class AttachmentReference2 : public vk::VkAttachmentReference2 93 { 94 public: 95 AttachmentReference2 (const void* pNext, 96 deUint32 attachment, 97 VkImageLayout layout, 98 VkImageAspectFlags aspectMask); 99 }; 100 101 class SubpassDescription1 : public vk::VkSubpassDescription 102 { 103 public: 104 SubpassDescription1 (const void* pNext, 105 VkSubpassDescriptionFlags flags, 106 VkPipelineBindPoint pipelineBindPoint, 107 deUint32 viewMask, 108 deUint32 inputAttachmentCount, 109 const VkAttachmentReference* pInputAttachments, 110 deUint32 colorAttachmentCount, 111 const VkAttachmentReference* pColorAttachments, 112 const VkAttachmentReference* pResolveAttachments, 113 const VkAttachmentReference* pDepthStencilAttachment, 114 deUint32 preserveAttachmentCount, 115 const deUint32* pPreserveAttachments); 116 }; 117 118 class SubpassDescription2 : public vk::VkSubpassDescription2 119 { 120 public: 121 SubpassDescription2 (const void* pNext, 122 VkSubpassDescriptionFlags flags, 123 VkPipelineBindPoint pipelineBindPoint, 124 deUint32 viewMask, 125 deUint32 inputAttachmentCount, 126 const VkAttachmentReference2* pInputAttachments, 127 deUint32 colorAttachmentCount, 128 const VkAttachmentReference2* pColorAttachments, 129 const VkAttachmentReference2* pResolveAttachments, 130 const VkAttachmentReference2* pDepthStencilAttachment, 131 deUint32 preserveAttachmentCount, 132 const deUint32* pPreserveAttachments); 133 }; 134 135 class SubpassDependency1 : public vk::VkSubpassDependency 136 { 137 public: 138 SubpassDependency1 (const void* pNext, 139 deUint32 srcSubpass, 140 deUint32 dstSubpass, 141 VkPipelineStageFlags srcStageMask, 142 VkPipelineStageFlags dstStageMask, 143 VkAccessFlags srcAccessMask, 144 VkAccessFlags dstAccessMask, 145 VkDependencyFlags dependencyFlags, 146 deInt32 viewOffset); 147 }; 148 149 class SubpassDependency2 : public vk::VkSubpassDependency2 150 { 151 public: 152 SubpassDependency2 (const void* pNext, 153 deUint32 srcSubpass, 154 deUint32 dstSubpass, 155 VkPipelineStageFlags srcStageMask, 156 VkPipelineStageFlags dstStageMask, 157 VkAccessFlags srcAccessMask, 158 VkAccessFlags dstAccessMask, 159 VkDependencyFlags dependencyFlags, 160 deInt32 viewOffset); 161 }; 162 163 class RenderPassCreateInfo1 : public VkRenderPassCreateInfo 164 { 165 public: 166 RenderPassCreateInfo1 (const void* pNext, 167 VkRenderPassCreateFlags flags, 168 deUint32 attachmentCount, 169 const VkAttachmentDescription* pAttachments, 170 deUint32 subpassCount, 171 const VkSubpassDescription* pSubpasses, 172 deUint32 dependencyCount, 173 const VkSubpassDependency* pDependencies, 174 deUint32 correlatedViewMaskCount, 175 const deUint32* pCorrelatedViewMasks); 176 177 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk, 178 VkDevice device) const; 179 }; 180 181 class RenderPassCreateInfo2 : public VkRenderPassCreateInfo2 182 { 183 public: 184 RenderPassCreateInfo2 (const void* pNext, 185 VkRenderPassCreateFlags flags, 186 deUint32 attachmentCount, 187 const VkAttachmentDescription2* pAttachments, 188 deUint32 subpassCount, 189 const VkSubpassDescription2* pSubpasses, 190 deUint32 dependencyCount, 191 const VkSubpassDependency2* pDependencies, 192 deUint32 correlatedViewMaskCount, 193 const deUint32* pCorrelatedViewMasks); 194 195 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk, 196 VkDevice device) const; 197 }; 198 199 class SubpassBeginInfo1 200 { 201 public: 202 SubpassBeginInfo1 (const void* pNext, 203 VkSubpassContents contents); 204 205 VkSubpassContents contents; 206 }; 207 208 class SubpassBeginInfo2 : public VkSubpassBeginInfo 209 { 210 public: 211 SubpassBeginInfo2 (const void* pNext, 212 VkSubpassContents contents); 213 }; 214 215 class SubpassEndInfo1 216 { 217 public: 218 SubpassEndInfo1 (const void* pNext); 219 }; 220 221 class SubpassEndInfo2 : public VkSubpassEndInfo 222 { 223 public: 224 SubpassEndInfo2 (const void* pNext); 225 }; 226 227 class RenderpassSubpass1 228 { 229 public: 230 typedef SubpassBeginInfo1 SubpassBeginInfo; 231 typedef SubpassEndInfo1 SubpassEndInfo; 232 233 static void cmdBeginRenderPass (const DeviceInterface& vk, 234 VkCommandBuffer cmdBuffer, 235 const VkRenderPassBeginInfo* pRenderPassBegin, 236 const SubpassBeginInfo* pSubpassBeginInfo); 237 238 static void cmdNextSubpass (const DeviceInterface& vk, 239 VkCommandBuffer cmdBuffer, 240 const SubpassBeginInfo* pSubpassBeginInfo, 241 const SubpassEndInfo* pSubpassEndInfo); 242 243 static void cmdEndRenderPass (const DeviceInterface& vk, 244 VkCommandBuffer cmdBuffer, 245 const SubpassEndInfo* pSubpassEndInfo); 246 }; 247 248 class RenderpassSubpass2 249 { 250 public: 251 typedef SubpassBeginInfo2 SubpassBeginInfo; 252 typedef SubpassEndInfo2 SubpassEndInfo; 253 254 static void cmdBeginRenderPass (const DeviceInterface& vk, 255 VkCommandBuffer cmdBuffer, 256 const VkRenderPassBeginInfo* pRenderPassBegin, 257 const SubpassBeginInfo* pSubpassBeginInfo); 258 259 static void cmdNextSubpass (const DeviceInterface& vk, 260 VkCommandBuffer cmdBuffer, 261 const SubpassBeginInfo* pSubpassBeginInfo, 262 const SubpassEndInfo* pSubpassEndInfo); 263 264 static void cmdEndRenderPass (const DeviceInterface& vk, 265 VkCommandBuffer cmdBuffer, 266 const SubpassEndInfo* pSubpassEndInfo); 267 }; 268 269 // For internal to RP/RP2 conversions 270 271 class AttachmentReference 272 { 273 public: 274 AttachmentReference (deUint32 attachment, 275 VkImageLayout layout, 276 VkImageAspectFlags aspectMask = static_cast<VkImageAspectFlags>(0u)); 277 278 deUint32 getAttachment (void) const; 279 VkImageLayout getImageLayout (void) const; 280 VkImageAspectFlags getAspectMask (void) const; 281 void setImageLayout (VkImageLayout layout); 282 283 private: 284 deUint32 m_attachment; 285 VkImageLayout m_layout; 286 VkImageAspectFlags m_aspectMask; 287 }; 288 289 class Subpass 290 { 291 public: 292 Subpass (VkPipelineBindPoint pipelineBindPoint, 293 VkSubpassDescriptionFlags flags, 294 const std::vector<AttachmentReference>& inputAttachments, 295 const std::vector<AttachmentReference>& colorAttachments, 296 const std::vector<AttachmentReference>& resolveAttachments, 297 AttachmentReference depthStencilAttachment, 298 const std::vector<deUint32>& preserveAttachments, 299 bool omitBlendState = false); 300 301 VkPipelineBindPoint getPipelineBindPoint (void) const; 302 VkSubpassDescriptionFlags getFlags (void) const; 303 const std::vector<AttachmentReference>& getInputAttachments (void) const; 304 const std::vector<AttachmentReference>& getColorAttachments (void) const; 305 const std::vector<AttachmentReference>& getResolveAttachments (void) const; 306 const AttachmentReference& getDepthStencilAttachment (void) const; 307 const std::vector<deUint32>& getPreserveAttachments (void) const; 308 bool getOmitBlendState (void) const; 309 310 private: 311 VkPipelineBindPoint m_pipelineBindPoint; 312 VkSubpassDescriptionFlags m_flags; 313 314 std::vector<AttachmentReference> m_inputAttachments; 315 std::vector<AttachmentReference> m_colorAttachments; 316 std::vector<AttachmentReference> m_resolveAttachments; 317 AttachmentReference m_depthStencilAttachment; 318 319 std::vector<deUint32> m_preserveAttachments; 320 bool m_omitBlendState; 321 }; 322 323 class SubpassDependency 324 { 325 public: 326 SubpassDependency (deUint32 srcPass, 327 deUint32 dstPass, 328 329 VkPipelineStageFlags srcStageMask, 330 VkPipelineStageFlags dstStageMask, 331 332 VkAccessFlags srcAccessMask, 333 VkAccessFlags dstAccessMask, 334 335 VkDependencyFlags flags); 336 337 deUint32 getSrcPass (void) const; 338 deUint32 getDstPass (void) const; 339 340 VkPipelineStageFlags getSrcStageMask (void) const; 341 VkPipelineStageFlags getDstStageMask (void) const; 342 343 VkAccessFlags getSrcAccessMask (void) const; 344 VkAccessFlags getDstAccessMask (void) const; 345 346 VkDependencyFlags getFlags (void) const; 347 348 private: 349 deUint32 m_srcPass; 350 deUint32 m_dstPass; 351 352 VkPipelineStageFlags m_srcStageMask; 353 VkPipelineStageFlags m_dstStageMask; 354 355 VkAccessFlags m_srcAccessMask; 356 VkAccessFlags m_dstAccessMask; 357 VkDependencyFlags m_flags; 358 }; 359 360 class Attachment 361 { 362 public: 363 Attachment (VkFormat format, 364 VkSampleCountFlagBits samples, 365 366 VkAttachmentLoadOp loadOp, 367 VkAttachmentStoreOp storeOp, 368 369 VkAttachmentLoadOp stencilLoadOp, 370 VkAttachmentStoreOp stencilStoreOp, 371 372 VkImageLayout initialLayout, 373 VkImageLayout finalLayout); 374 375 VkFormat getFormat (void) const; 376 VkSampleCountFlagBits getSamples (void) const; 377 378 VkAttachmentLoadOp getLoadOp (void) const; 379 VkAttachmentStoreOp getStoreOp (void) const; 380 381 VkAttachmentLoadOp getStencilLoadOp (void) const; 382 VkAttachmentStoreOp getStencilStoreOp (void) const; 383 384 VkImageLayout getInitialLayout (void) const; 385 VkImageLayout getFinalLayout (void) const; 386 387 private: 388 VkFormat m_format; 389 VkSampleCountFlagBits m_samples; 390 391 VkAttachmentLoadOp m_loadOp; 392 VkAttachmentStoreOp m_storeOp; 393 394 VkAttachmentLoadOp m_stencilLoadOp; 395 VkAttachmentStoreOp m_stencilStoreOp; 396 397 VkImageLayout m_initialLayout; 398 VkImageLayout m_finalLayout; 399 }; 400 401 class RenderPass 402 { 403 public: 404 RenderPass (const std::vector<Attachment>& attachments, 405 const std::vector<Subpass>& subpasses, 406 const std::vector<SubpassDependency>& dependencies, 407 const std::vector<VkInputAttachmentAspectReference> inputAspects = std::vector<VkInputAttachmentAspectReference>()); 408 409 const std::vector<Attachment>& getAttachments (void) const; 410 const std::vector<Subpass>& getSubpasses (void) const; 411 const std::vector<SubpassDependency>& getDependencies (void) const; 412 const std::vector<VkInputAttachmentAspectReference>& getInputAspects (void) const; 413 414 private: 415 std::vector<Attachment> m_attachments; 416 std::vector<Subpass> m_subpasses; 417 std::vector<SubpassDependency> m_dependencies; 418 std::vector<VkInputAttachmentAspectReference> m_inputAspects; 419 }; 420 421 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk, 422 VkDevice device, 423 const RenderPass& renderPassInfo, 424 RenderPassType renderPassType, 425 SynchronizationType synchronizationType = SYNCHRONIZATION_TYPE_LEGACY); 426 427 } // renderpass 428 429 } // vkt 430 431 #endif // _VKTRENDERPASSTESTSUTIL_HPP 432