blob: b6e44977313dc5efaf1c1144d35cd45702ea7ba6 [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"
Greg Daniel164a9f02016-02-22 09:56:40 -050012#include "GrVkResource.h"
Greg Daniel487132b2018-12-20 14:09:36 -050013#include "vk/GrVkTypes.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014
egdaniel22281c12016-03-23 13:49:40 -070015class GrProcessorKeyBuilder;
Greg Daniel164a9f02016-02-22 09:56:40 -050016class GrVkGpu;
17class GrVkRenderTarget;
18
19class GrVkRenderPass : public GrVkResource {
20public:
Greg Daniel77a86f82017-01-23 11:04:45 -050021 GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE), fClearValueCount(0) {}
egdaniel2feb0932016-06-08 06:48:09 -070022
Greg Danielb46add82019-01-02 14:51:29 -050023 // Used when importing an external render pass. In this case we have to explicitly be told the
24 // color attachment index
25 explicit GrVkRenderPass(VkRenderPass renderPass, uint32_t colorAttachmentIndex)
26 : INHERITED()
27 , fRenderPass(renderPass)
28 , fAttachmentFlags(kExternal_AttachmentFlag)
29 , fClearValueCount(0)
30 , fColorAttachmentIndex(colorAttachmentIndex) {}
31
egdaniel2feb0932016-06-08 06:48:09 -070032 struct LoadStoreOps {
33 VkAttachmentLoadOp fLoadOp;
34 VkAttachmentStoreOp fStoreOp;
35
36 LoadStoreOps(VkAttachmentLoadOp loadOp, VkAttachmentStoreOp storeOp)
37 : fLoadOp(loadOp)
38 , fStoreOp(storeOp) {}
39
40 bool operator==(const LoadStoreOps& right) const {
41 return fLoadOp == right.fLoadOp && fStoreOp == right.fStoreOp;
42 }
43
44 bool operator!=(const LoadStoreOps& right) const {
45 return !(*this == right);
46 }
47 };
48
Greg Daniel164a9f02016-02-22 09:56:40 -050049 void initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& target);
egdaniel2feb0932016-06-08 06:48:09 -070050 void init(const GrVkGpu* gpu,
51 const GrVkRenderTarget& target,
52 const LoadStoreOps& colorOp,
egdaniel2feb0932016-06-08 06:48:09 -070053 const LoadStoreOps& stencilOp);
54
55 void init(const GrVkGpu* gpu,
56 const GrVkRenderPass& compatibleRenderPass,
57 const LoadStoreOps& colorOp,
egdaniel2feb0932016-06-08 06:48:09 -070058 const LoadStoreOps& stencilOp);
Greg Daniel164a9f02016-02-22 09:56:40 -050059
60 struct AttachmentsDescriptor {
61 struct AttachmentDesc {
62 VkFormat fFormat;
63 int fSamples;
egdaniel2feb0932016-06-08 06:48:09 -070064 LoadStoreOps fLoadStoreOps;
egdanield62e28b2016-06-07 08:43:30 -070065
66 AttachmentDesc()
67 : fFormat(VK_FORMAT_UNDEFINED)
68 , fSamples(0)
egdaniel2feb0932016-06-08 06:48:09 -070069 , fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {}
Greg Daniel164a9f02016-02-22 09:56:40 -050070 bool operator==(const AttachmentDesc& right) const {
egdanield62e28b2016-06-07 08:43:30 -070071 return (fFormat == right.fFormat &&
72 fSamples == right.fSamples &&
egdaniel2feb0932016-06-08 06:48:09 -070073 fLoadStoreOps == right.fLoadStoreOps);
Greg Daniel164a9f02016-02-22 09:56:40 -050074 }
75 bool operator!=(const AttachmentDesc& right) const {
76 return !(*this == right);
77 }
egdanield62e28b2016-06-07 08:43:30 -070078 bool isCompatible(const AttachmentDesc& desc) const {
79 return (fFormat == desc.fFormat && fSamples == desc.fSamples);
80 }
Greg Daniel164a9f02016-02-22 09:56:40 -050081 };
82 AttachmentDesc fColor;
Greg Daniel164a9f02016-02-22 09:56:40 -050083 AttachmentDesc fStencil;
84 uint32_t fAttachmentCount;
85 };
86
87 enum AttachmentFlags {
88 kColor_AttachmentFlag = 0x1,
egdanielce3bfb12016-08-26 11:05:13 -070089 kStencil_AttachmentFlag = 0x2,
Greg Danielb46add82019-01-02 14:51:29 -050090 // The external attachment flag signals that this render pass is imported from an external
91 // client. Since we don't know every attachment on the render pass we don't set any of the
92 // specific attachment flags when using external. However, the external render pass must
93 // at least have a color attachment.
94 kExternal_AttachmentFlag = 0x4,
Greg Daniel164a9f02016-02-22 09:56:40 -050095 };
96 GR_DECL_BITFIELD_OPS_FRIENDS(AttachmentFlags);
97
98 // The following return the index of the render pass attachment array for the given attachment.
99 // If the render pass does not have the given attachment it will return false and not set the
100 // index value.
101 bool colorAttachmentIndex(uint32_t* index) const;
Greg Daniel164a9f02016-02-22 09:56:40 -0500102 bool stencilAttachmentIndex(uint32_t* index) const;
103
Greg Daniel164a9f02016-02-22 09:56:40 -0500104 // Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in
105 // this object. Specifically this compares that the number of attachments, format of
106 // attachments, and sample counts are all the same. This function is used in the creation of
107 // basic RenderPasses that can be used when creating a VkFrameBuffer object.
108 bool isCompatible(const GrVkRenderTarget& target) const;
109
egdaniel9a6cf802016-06-08 08:22:05 -0700110 bool isCompatible(const GrVkRenderPass& renderPass) const;
111
Greg Danielb46add82019-01-02 14:51:29 -0500112 bool isCompatibleExternalRP(VkRenderPass) const;
113
egdaniel2feb0932016-06-08 06:48:09 -0700114 bool equalLoadStoreOps(const LoadStoreOps& colorOps,
egdaniel2feb0932016-06-08 06:48:09 -0700115 const LoadStoreOps& stencilOps) const;
116
Greg Daniel164a9f02016-02-22 09:56:40 -0500117 VkRenderPass vkRenderPass() const { return fRenderPass; }
118
egdaniel27bb2842016-07-07 11:58:35 -0700119 const VkExtent2D& granularity() const { return fGranularity; }
120
Greg Daniel77a86f82017-01-23 11:04:45 -0500121 // Returns the number of clear colors needed to begin this render pass. Currently this will
122 // either only be 0 or 1 since we only ever clear the color attachment.
123 uint32_t clearValueCount() const { return fClearValueCount; }
124
125
egdaniel22281c12016-03-23 13:49:40 -0700126 void genKey(GrProcessorKeyBuilder* b) const;
127
jvanverth7ec92412016-07-06 09:24:57 -0700128#ifdef SK_TRACE_VK_RESOURCES
129 void dumpInfo() const override {
130 SkDebugf("GrVkRenderPass: %d (%d refs)\n", fRenderPass, this->getRefCnt());
131 }
132#endif
133
Greg Daniel164a9f02016-02-22 09:56:40 -0500134private:
135 GrVkRenderPass(const GrVkRenderPass&);
Greg Daniel164a9f02016-02-22 09:56:40 -0500136
egdaniel2feb0932016-06-08 06:48:09 -0700137 void init(const GrVkGpu* gpu,
138 const LoadStoreOps& colorOps,
egdaniel2feb0932016-06-08 06:48:09 -0700139 const LoadStoreOps& stencilOps);
140
egdaniel9a6cf802016-06-08 08:22:05 -0700141 bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const;
142
Ethan Nicholas8e265a72018-12-12 16:22:40 -0500143 void freeGPUData(GrVkGpu* gpu) const override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500144
145 VkRenderPass fRenderPass;
146 AttachmentFlags fAttachmentFlags;
147 AttachmentsDescriptor fAttachmentsDescriptor;
egdaniel27bb2842016-07-07 11:58:35 -0700148 VkExtent2D fGranularity;
Greg Daniel77a86f82017-01-23 11:04:45 -0500149 uint32_t fClearValueCount;
Greg Danielb46add82019-01-02 14:51:29 -0500150 // For internally created render passes we assume the color attachment index is always 0.
151 uint32_t fColorAttachmentIndex = 0;
Greg Daniel164a9f02016-02-22 09:56:40 -0500152
153 typedef GrVkResource INHERITED;
154};
155
156GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags);
157
jvanverth9846ef22016-03-02 12:08:22 -0800158#endif