blob: 3f02f6be22b73eb5d4e90e230429d0e1de693033 [file] [log] [blame]
Alexis Hetub16f9892018-11-15 15:18:41 -05001// 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 Forbes65b1e972019-05-13 11:01:56 -070020#include <vector>
21
Nicolas Capens157ba262019-12-10 17:49:14 -050022namespace vk {
Alexis Hetub16f9892018-11-15 15:18:41 -050023
24class RenderPass : public Object<RenderPass, VkRenderPass>
25{
26public:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000027 RenderPass(const VkRenderPassCreateInfo *pCreateInfo, void *mem);
Alexis Hetu9f8337e2020-02-07 11:07:43 -050028 RenderPass(const VkRenderPassCreateInfo2KHR *pCreateInfo, void *mem);
Ben Clayton2ed93ab2019-12-17 20:38:03 +000029 void destroy(const VkAllocationCallbacks *pAllocator);
Alexis Hetub16f9892018-11-15 15:18:41 -050030
Ben Clayton2ed93ab2019-12-17 20:38:03 +000031 static size_t ComputeRequiredAllocationSize(const VkRenderPassCreateInfo *pCreateInfo);
Alexis Hetu9f8337e2020-02-07 11:07:43 -050032 static size_t ComputeRequiredAllocationSize(const VkRenderPassCreateInfo2KHR *pCreateInfo);
Alexis Hetub16f9892018-11-15 15:18:41 -050033
Ben Clayton2ed93ab2019-12-17 20:38:03 +000034 void getRenderAreaGranularity(VkExtent2D *pGranularity) const;
Alexis Hetu6d74ab82019-02-15 14:42:38 -050035
Alexis Hetu238af152019-01-18 10:35:51 -050036 uint32_t getAttachmentCount() const
37 {
38 return attachmentCount;
39 }
40
Chris Forbesd6dc4b72019-08-23 08:23:27 -070041 VkAttachmentDescription getAttachment(uint32_t attachmentIndex) const
Alexis Hetu238af152019-01-18 10:35:51 -050042 {
Chris Forbesd6dc4b72019-08-23 08:23:27 -070043 return attachments[attachmentIndex];
Alexis Hetu238af152019-01-18 10:35:51 -050044 }
45
46 uint32_t getSubpassCount() const
47 {
48 return subpassCount;
49 }
50
Ben Clayton2ed93ab2019-12-17 20:38:03 +000051 VkSubpassDescription const &getSubpass(uint32_t subpassIndex) const
Alexis Hetu238af152019-01-18 10:35:51 -050052 {
Chris Forbesd6dc4b72019-08-23 08:23:27 -070053 return subpasses[subpassIndex];
Alexis Hetu238af152019-01-18 10:35:51 -050054 }
55
56 uint32_t getDependencyCount() const
57 {
58 return dependencyCount;
59 }
60
61 VkSubpassDependency getDependency(uint32_t i) const
62 {
63 return dependencies[i];
64 }
65
Chris Forbes65b1e972019-05-13 11:01:56 -070066 bool isAttachmentUsed(uint32_t i) const
67 {
68 return attachmentFirstUse[i] >= 0;
69 }
70
Chris Forbesd6dc4b72019-08-23 08:23:27 -070071 uint32_t getViewMask(uint32_t subpassIndex) const
Chris Forbes02d4c0d2019-08-21 12:04:34 -070072 {
Chris Forbesd6dc4b72019-08-23 08:23:27 -070073 return viewMasks ? viewMasks[subpassIndex] : 1;
Chris Forbes02d4c0d2019-08-21 12:04:34 -070074 }
75
76 bool isMultiView() const
77 {
78 return viewMasks != nullptr;
79 }
80
Chris Forbesd6dc4b72019-08-23 08:23:27 -070081 uint32_t getAttachmentViewMask(uint32_t attachmentIndex) const
Chris Forbes02d4c0d2019-08-21 12:04:34 -070082 {
Chris Forbesd6dc4b72019-08-23 08:23:27 -070083 return attachmentViewMasks[attachmentIndex];
Chris Forbes02d4c0d2019-08-21 12:04:34 -070084 }
85
Alexis Hetub16f9892018-11-15 15:18:41 -050086private:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000087 uint32_t attachmentCount = 0;
88 VkAttachmentDescription *attachments = nullptr;
89 uint32_t subpassCount = 0;
90 VkSubpassDescription *subpasses = nullptr;
91 uint32_t dependencyCount = 0;
92 VkSubpassDependency *dependencies = nullptr;
93 int *attachmentFirstUse = nullptr;
94 uint32_t *viewMasks = nullptr;
95 uint32_t *attachmentViewMasks = nullptr;
Chris Forbes02d4c0d2019-08-21 12:04:34 -070096
97 void MarkFirstUse(int attachment, int subpass);
Alexis Hetu9f8337e2020-02-07 11:07:43 -050098 template<class T>
99 void init(const T *pCreateInfo, void *mem);
Alexis Hetub16f9892018-11-15 15:18:41 -0500100};
101
Ben Clayton2ed93ab2019-12-17 20:38:03 +0000102static inline RenderPass *Cast(VkRenderPass object)
Alexis Hetub16f9892018-11-15 15:18:41 -0500103{
Alexis Hetubd4cf812019-06-14 15:14:07 -0400104 return RenderPass::Cast(object);
Alexis Hetub16f9892018-11-15 15:18:41 -0500105}
106
Nicolas Capens157ba262019-12-10 17:49:14 -0500107} // namespace vk
Alexis Hetub16f9892018-11-15 15:18:41 -0500108
Ben Clayton2ed93ab2019-12-17 20:38:03 +0000109#endif // VK_RENDER_PASS_HPP_