Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef VK_RENDER_PASS_HPP_ |
| 16 | #define VK_RENDER_PASS_HPP_ |
| 17 | |
| 18 | #include "VkObject.hpp" |
| 19 | |
Chris Forbes | 65b1e97 | 2019-05-13 11:01:56 -0700 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 22 | namespace vk { |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 23 | |
| 24 | class RenderPass : public Object<RenderPass, VkRenderPass> |
| 25 | { |
| 26 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 27 | RenderPass(const VkRenderPassCreateInfo *pCreateInfo, void *mem); |
Alexis Hetu | 9f8337e | 2020-02-07 11:07:43 -0500 | [diff] [blame] | 28 | RenderPass(const VkRenderPassCreateInfo2KHR *pCreateInfo, void *mem); |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 29 | void destroy(const VkAllocationCallbacks *pAllocator); |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 30 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 31 | static size_t ComputeRequiredAllocationSize(const VkRenderPassCreateInfo *pCreateInfo); |
Alexis Hetu | 9f8337e | 2020-02-07 11:07:43 -0500 | [diff] [blame] | 32 | static size_t ComputeRequiredAllocationSize(const VkRenderPassCreateInfo2KHR *pCreateInfo); |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 33 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 34 | void getRenderAreaGranularity(VkExtent2D *pGranularity) const; |
Alexis Hetu | 6d74ab8 | 2019-02-15 14:42:38 -0500 | [diff] [blame] | 35 | |
Alexis Hetu | 238af15 | 2019-01-18 10:35:51 -0500 | [diff] [blame] | 36 | uint32_t getAttachmentCount() const |
| 37 | { |
| 38 | return attachmentCount; |
| 39 | } |
| 40 | |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 41 | VkAttachmentDescription getAttachment(uint32_t attachmentIndex) const |
Alexis Hetu | 238af15 | 2019-01-18 10:35:51 -0500 | [diff] [blame] | 42 | { |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 43 | return attachments[attachmentIndex]; |
Alexis Hetu | 238af15 | 2019-01-18 10:35:51 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | uint32_t getSubpassCount() const |
| 47 | { |
| 48 | return subpassCount; |
| 49 | } |
| 50 | |
Nicolas Capens | 7e1d67a | 2022-10-04 10:36:33 -0400 | [diff] [blame] | 51 | const VkSubpassDescription &getSubpass(uint32_t subpassIndex) const |
Alexis Hetu | 238af15 | 2019-01-18 10:35:51 -0500 | [diff] [blame] | 52 | { |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 53 | return subpasses[subpassIndex]; |
Alexis Hetu | 238af15 | 2019-01-18 10:35:51 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Sean Risser | 1d5174b | 2020-09-22 16:58:28 -0400 | [diff] [blame] | 56 | bool hasDepthStencilResolve() const |
| 57 | { |
| 58 | return subpassDepthStencilResolves != nullptr; |
| 59 | } |
| 60 | |
| 61 | VkSubpassDescriptionDepthStencilResolve getSubpassDepthStencilResolve(uint32_t subpassIndex) const |
| 62 | { |
| 63 | return subpassDepthStencilResolves[subpassIndex]; |
| 64 | } |
| 65 | |
Alexis Hetu | 238af15 | 2019-01-18 10:35:51 -0500 | [diff] [blame] | 66 | uint32_t getDependencyCount() const |
| 67 | { |
| 68 | return dependencyCount; |
| 69 | } |
| 70 | |
| 71 | VkSubpassDependency getDependency(uint32_t i) const |
| 72 | { |
| 73 | return dependencies[i]; |
| 74 | } |
| 75 | |
Chris Forbes | 65b1e97 | 2019-05-13 11:01:56 -0700 | [diff] [blame] | 76 | bool isAttachmentUsed(uint32_t i) const |
| 77 | { |
| 78 | return attachmentFirstUse[i] >= 0; |
| 79 | } |
| 80 | |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 81 | uint32_t getViewMask(uint32_t subpassIndex) const |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 82 | { |
Alexis Hetu | 310874c | 2022-02-23 10:57:58 -0500 | [diff] [blame] | 83 | return viewMasks ? viewMasks[subpassIndex] : 0; |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | bool isMultiView() const |
| 87 | { |
| 88 | return viewMasks != nullptr; |
| 89 | } |
| 90 | |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 91 | uint32_t getAttachmentViewMask(uint32_t attachmentIndex) const |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 92 | { |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 93 | return attachmentViewMasks[attachmentIndex]; |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 96 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 97 | uint32_t attachmentCount = 0; |
| 98 | VkAttachmentDescription *attachments = nullptr; |
| 99 | uint32_t subpassCount = 0; |
| 100 | VkSubpassDescription *subpasses = nullptr; |
Sean Risser | 1d5174b | 2020-09-22 16:58:28 -0400 | [diff] [blame] | 101 | VkSubpassDescriptionDepthStencilResolve *subpassDepthStencilResolves = nullptr; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 102 | uint32_t dependencyCount = 0; |
| 103 | VkSubpassDependency *dependencies = nullptr; |
| 104 | int *attachmentFirstUse = nullptr; |
| 105 | uint32_t *viewMasks = nullptr; |
| 106 | uint32_t *attachmentViewMasks = nullptr; |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 107 | |
| 108 | void MarkFirstUse(int attachment, int subpass); |
Alexis Hetu | 9f8337e | 2020-02-07 11:07:43 -0500 | [diff] [blame] | 109 | template<class T> |
Sean Risser | 1d5174b | 2020-09-22 16:58:28 -0400 | [diff] [blame] | 110 | void init(const T *pCreateInfo, void **mem); |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 111 | }; |
| 112 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 113 | static inline RenderPass *Cast(VkRenderPass object) |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 114 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 115 | return RenderPass::Cast(object); |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 116 | } |
| 117 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 118 | } // namespace vk |
Alexis Hetu | b16f989 | 2018-11-15 15:18:41 -0500 | [diff] [blame] | 119 | |
Sean Risser | 1d5174b | 2020-09-22 16:58:28 -0400 | [diff] [blame] | 120 | #endif // VK_RENDER_PASS_HPP_ |