blob: 997989d07318738d662f2403b3e94671a11f1614 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
2* Copyright 2015 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
8#ifndef GrVkRenderPass_DEFINED
9#define GrVkRenderPass_DEFINED
10
11#include "GrTypes.h"
12
13#include "GrVkResource.h"
14
jvanverthe50f3e72016-03-28 07:03:06 -070015#include "vk/GrVkDefines.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050016
egdaniel22281c12016-03-23 13:49:40 -070017class GrProcessorKeyBuilder;
Greg Daniel164a9f02016-02-22 09:56:40 -050018class GrVkGpu;
19class GrVkRenderTarget;
20
21class GrVkRenderPass : public GrVkResource {
22public:
jvanverth9846ef22016-03-02 12:08:22 -080023 GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE) {}
egdaniel2feb0932016-06-08 06:48:09 -070024
25 struct LoadStoreOps {
26 VkAttachmentLoadOp fLoadOp;
27 VkAttachmentStoreOp fStoreOp;
28
29 LoadStoreOps(VkAttachmentLoadOp loadOp, VkAttachmentStoreOp storeOp)
30 : fLoadOp(loadOp)
31 , fStoreOp(storeOp) {}
32
33 bool operator==(const LoadStoreOps& right) const {
34 return fLoadOp == right.fLoadOp && fStoreOp == right.fStoreOp;
35 }
36
37 bool operator!=(const LoadStoreOps& right) const {
38 return !(*this == right);
39 }
40 };
41
Greg Daniel164a9f02016-02-22 09:56:40 -050042 void initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& target);
egdaniel2feb0932016-06-08 06:48:09 -070043 void init(const GrVkGpu* gpu,
44 const GrVkRenderTarget& target,
45 const LoadStoreOps& colorOp,
46 const LoadStoreOps& resolveOp,
47 const LoadStoreOps& stencilOp);
48
49 void init(const GrVkGpu* gpu,
50 const GrVkRenderPass& compatibleRenderPass,
51 const LoadStoreOps& colorOp,
52 const LoadStoreOps& resolveOp,
53 const LoadStoreOps& stencilOp);
Greg Daniel164a9f02016-02-22 09:56:40 -050054
55 struct AttachmentsDescriptor {
56 struct AttachmentDesc {
57 VkFormat fFormat;
58 int fSamples;
egdaniel2feb0932016-06-08 06:48:09 -070059 LoadStoreOps fLoadStoreOps;
egdanield62e28b2016-06-07 08:43:30 -070060
61 AttachmentDesc()
62 : fFormat(VK_FORMAT_UNDEFINED)
63 , fSamples(0)
egdaniel2feb0932016-06-08 06:48:09 -070064 , fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {}
Greg Daniel164a9f02016-02-22 09:56:40 -050065 bool operator==(const AttachmentDesc& right) const {
egdanield62e28b2016-06-07 08:43:30 -070066 return (fFormat == right.fFormat &&
67 fSamples == right.fSamples &&
egdaniel2feb0932016-06-08 06:48:09 -070068 fLoadStoreOps == right.fLoadStoreOps);
Greg Daniel164a9f02016-02-22 09:56:40 -050069 }
70 bool operator!=(const AttachmentDesc& right) const {
71 return !(*this == right);
72 }
egdanield62e28b2016-06-07 08:43:30 -070073 bool isCompatible(const AttachmentDesc& desc) const {
74 return (fFormat == desc.fFormat && fSamples == desc.fSamples);
75 }
Greg Daniel164a9f02016-02-22 09:56:40 -050076 };
77 AttachmentDesc fColor;
78 AttachmentDesc fResolve;
79 AttachmentDesc fStencil;
80 uint32_t fAttachmentCount;
81 };
82
83 enum AttachmentFlags {
84 kColor_AttachmentFlag = 0x1,
85 kResolve_AttachmentFlag = 0x2,
86 kStencil_AttachmentFlag = 0x4,
87 };
88 GR_DECL_BITFIELD_OPS_FRIENDS(AttachmentFlags);
89
90 // The following return the index of the render pass attachment array for the given attachment.
91 // If the render pass does not have the given attachment it will return false and not set the
92 // index value.
93 bool colorAttachmentIndex(uint32_t* index) const;
94 bool resolveAttachmentIndex(uint32_t* index) const;
95 bool stencilAttachmentIndex(uint32_t* index) const;
96
97 // Sets the VkRenderPassBeginInfo and VkRenderPassContents need to begin a render pass.
98 // TODO: In the future I expect this function will also take an optional render area instead of
99 // defaulting to the entire render target.
100 // TODO: Figure out if load clear values should be passed into this function or should be stored
101 // on the GrVkRenderPass at create time since we'll know at that point if we want to do a load
102 // clear.
103 void getBeginInfo(const GrVkRenderTarget& target,
104 VkRenderPassBeginInfo* beginInfo,
105 VkSubpassContents* contents) const;
106
107 // Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in
108 // this object. Specifically this compares that the number of attachments, format of
109 // attachments, and sample counts are all the same. This function is used in the creation of
110 // basic RenderPasses that can be used when creating a VkFrameBuffer object.
111 bool isCompatible(const GrVkRenderTarget& target) const;
112
egdaniel9a6cf802016-06-08 08:22:05 -0700113 bool isCompatible(const GrVkRenderPass& renderPass) const;
114
egdaniel2feb0932016-06-08 06:48:09 -0700115 bool equalLoadStoreOps(const LoadStoreOps& colorOps,
116 const LoadStoreOps& resolveOps,
117 const LoadStoreOps& stencilOps) const;
118
Greg Daniel164a9f02016-02-22 09:56:40 -0500119 VkRenderPass vkRenderPass() const { return fRenderPass; }
120
egdaniel22281c12016-03-23 13:49:40 -0700121 void genKey(GrProcessorKeyBuilder* b) const;
122
Greg Daniel164a9f02016-02-22 09:56:40 -0500123private:
124 GrVkRenderPass(const GrVkRenderPass&);
Greg Daniel164a9f02016-02-22 09:56:40 -0500125
egdaniel2feb0932016-06-08 06:48:09 -0700126 void init(const GrVkGpu* gpu,
127 const LoadStoreOps& colorOps,
128 const LoadStoreOps& resolveOps,
129 const LoadStoreOps& stencilOps);
130
egdaniel9a6cf802016-06-08 08:22:05 -0700131 bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const;
132
Greg Daniel164a9f02016-02-22 09:56:40 -0500133 void freeGPUData(const GrVkGpu* gpu) const override;
134
135 VkRenderPass fRenderPass;
136 AttachmentFlags fAttachmentFlags;
137 AttachmentsDescriptor fAttachmentsDescriptor;
138
139 typedef GrVkResource INHERITED;
140};
141
142GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags);
143
jvanverth9846ef22016-03-02 12:08:22 -0800144#endif