Flutter Engine
The Flutter Engine
GrVkRenderPass.h
Go to the documentation of this file.
1/*
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 "include/gpu/GrTypes.h"
15
16#include <cinttypes>
17
18class GrVkGpu;
20namespace skgpu {
21class KeyBuilder;
22}
23
25public:
26 struct LoadStoreOps {
29
31 : fLoadOp(loadOp)
32 , fStoreOp(storeOp) {}
33
34 bool operator==(const LoadStoreOps& right) const {
35 return fLoadOp == right.fLoadOp && fStoreOp == right.fStoreOp;
36 }
37
38 bool operator!=(const LoadStoreOps& right) const {
39 return !(*this == right);
40 }
41 };
42
43 // Used when importing an external render pass. In this case we have to explicitly be told the
44 // color attachment index
45 explicit GrVkRenderPass(const GrVkGpu* gpu, VkRenderPass renderPass,
46 uint32_t colorAttachmentIndex)
47 : INHERITED(gpu)
48 , fRenderPass(renderPass)
49 , fAttachmentFlags(kExternal_AttachmentFlag)
50 , fSelfDepFlags(SelfDependencyFlags::kNone)
51 , fLoadFromResolve(LoadFromResolve::kNo)
52 , fClearValueCount(0)
53 , fColorAttachmentIndex(colorAttachmentIndex) {}
54
60
63 , fSamples(0)
65 bool operator==(const AttachmentDesc& right) const {
66 return (fFormat == right.fFormat &&
67 fSamples == right.fSamples &&
68 fLoadStoreOps == right.fLoadStoreOps);
69 }
70 bool operator!=(const AttachmentDesc& right) const {
71 return !(*this == right);
72 }
73 bool isCompatible(const AttachmentDesc& desc) const {
74 return (fFormat == desc.fFormat && fSamples == desc.fSamples);
75 }
76 };
81 };
82
83 enum AttachmentFlags : uint32_t {
87 // The external attachment flag signals that this render pass is imported from an external
88 // client. Since we don't know every attachment on the render pass we don't set any of the
89 // specific attachment flags when using external. However, the external render pass must
90 // at least have a color attachment.
92 };
94
96 kNone = 0,
97 kForInputAttachment = 1 << 0,
98 kForNonCoherentAdvBlend = 1 << 1,
99 };
101
102 enum class LoadFromResolve {
103 kNo,
104 kLoad,
105 };
106
108 AttachmentsDescriptor*,
110 SelfDependencyFlags selfDepFlags,
113 const GrVkRenderPass& compatibleRenderPass,
114 const LoadStoreOps& colorOp,
115 const LoadStoreOps& resolveOp,
116 const LoadStoreOps& stencilOp);
117
118 // The following return the index of the render pass attachment array for the given attachment.
119 // If the render pass does not have the given attachment it will return false and not set the
120 // index value.
121 bool colorAttachmentIndex(uint32_t* index) const;
122 bool stencilAttachmentIndex(uint32_t* index) const;
123 bool hasStencilAttachment() const { return fAttachmentFlags & kStencil_AttachmentFlag; }
124 bool hasResolveAttachment() const { return fAttachmentFlags & kResolve_AttachmentFlag; }
125
126 SelfDependencyFlags selfDependencyFlags() const { return fSelfDepFlags; }
127 LoadFromResolve loadFromResolve() const { return fLoadFromResolve; }
128
129 // Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in
130 // this object. Specifically this compares that the number of attachments, format of
131 // attachments, and sample counts are all the same. This function is used in the creation of
132 // basic RenderPasses that can be used when creating a VkFrameBuffer object.
134 SelfDependencyFlags selfDepFlags,
135 LoadFromResolve) const;
136
137 bool isCompatible(const GrVkRenderPass& renderPass) const;
138
139 bool isCompatible(const AttachmentsDescriptor&,
140 const AttachmentFlags&,
141 SelfDependencyFlags selfDepFlags,
142 LoadFromResolve) const;
143
144 bool isCompatibleExternalRP(VkRenderPass) const;
145
146 SkDEBUGCODE(bool isExternal() const { return fAttachmentFlags & kExternal_AttachmentFlag; })
147
148 bool equalLoadStoreOps(const LoadStoreOps& colorOps,
150 const LoadStoreOps& stencilOps) const;
151
152 VkRenderPass vkRenderPass() const { return fRenderPass; }
153
154 const VkExtent2D& granularity() const { return fGranularity; }
155
156 // Returns the number of clear colors needed to begin this render pass. Currently this will
157 // either only be 0 or 1 since we only ever clear the color attachment.
158 uint32_t clearValueCount() const { return fClearValueCount; }
159
160
161 void genKey(skgpu::KeyBuilder*) const;
162
163 static void GenKey(skgpu::KeyBuilder*,
165 const AttachmentsDescriptor&,
166 SelfDependencyFlags selfDepFlags,
168 uint64_t externalRenderPass);
169
170#ifdef SK_TRACE_MANAGED_RESOURCES
171 void dumpInfo() const override {
172 SkDebugf("GrVkRenderPass: %" PRIdPTR " (%d refs)\n",
173 (intptr_t)fRenderPass, this->getRefCnt());
174 }
175#endif
176
177private:
178 GrVkRenderPass(const GrVkGpu*, VkRenderPass, AttachmentFlags, const AttachmentsDescriptor&,
180 uint32_t clearValueCount);
181
182 static GrVkRenderPass* Create(GrVkGpu* gpu,
184 AttachmentsDescriptor*,
185 const LoadStoreOps& colorOps,
186 const LoadStoreOps& resolveOp,
187 const LoadStoreOps& stencilOps,
188 SelfDependencyFlags selfDepFlags,
190
191 void freeGPUData() const override;
192
193 VkRenderPass fRenderPass;
194 AttachmentFlags fAttachmentFlags;
195 AttachmentsDescriptor fAttachmentsDescriptor;
196 SelfDependencyFlags fSelfDepFlags;
197 LoadFromResolve fLoadFromResolve;
198 VkExtent2D fGranularity;
199 uint32_t fClearValueCount;
200 // For internally created render passes we assume the color attachment index is always 0.
201 uint32_t fColorAttachmentIndex = 0;
202
203 using INHERITED = GrVkManagedResource;
204};
205
208
209#endif
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition: GrTypes.h:42
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SK_MAKE_BITFIELD_OPS(X)
Definition: SkMacros.h:66
#define SK_DECL_BITFIELD_OPS_FRIENDS(X)
Definition: SkMacros.h:86
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
static bool right(const SkPoint &p0, const SkPoint &p1)
GrVkManagedResource(const GrVkGpu *gpu)
GrVkRenderPass(const GrVkGpu *gpu, VkRenderPass renderPass, uint32_t colorAttachmentIndex)
bool colorAttachmentIndex(uint32_t *index) const
void genKey(skgpu::KeyBuilder *) const
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(SelfDependencyFlags)
SkDEBUGCODE(bool isExternal() const { return fAttachmentFlags &kExternal_AttachmentFlag;}) bool equalLoadStoreOps(const LoadStoreOps &colorOps
const VkExtent2D & granularity() const
LoadFromResolve loadFromResolve() const
bool isCompatible(GrVkRenderTarget *target, SelfDependencyFlags selfDepFlags, LoadFromResolve) const
static void GenKey(skgpu::KeyBuilder *, AttachmentFlags, const AttachmentsDescriptor &, SelfDependencyFlags selfDepFlags, LoadFromResolve, uint64_t externalRenderPass)
bool isCompatibleExternalRP(VkRenderPass) const
bool stencilAttachmentIndex(uint32_t *index) const
SelfDependencyFlags selfDependencyFlags() const
static GrVkRenderPass * Create(GrVkGpu *, const GrVkRenderPass &compatibleRenderPass, const LoadStoreOps &colorOp, const LoadStoreOps &resolveOp, const LoadStoreOps &stencilOp)
static GrVkRenderPass * CreateSimple(GrVkGpu *, AttachmentsDescriptor *, AttachmentFlags, SelfDependencyFlags selfDepFlags, LoadFromResolve)
const LoadStoreOps & resolveOps
bool hasStencilAttachment() const
uint32_t clearValueCount() const
VkRenderPass vkRenderPass() const
bool hasResolveAttachment() const
uint32_t * target
Definition: GpuTools.h:21
bool operator==(const AttachmentDesc &right) const
bool isCompatible(const AttachmentDesc &desc) const
bool operator!=(const AttachmentDesc &right) const
VkAttachmentStoreOp fStoreOp
bool operator!=(const LoadStoreOps &right) const
bool operator==(const LoadStoreOps &right) const
LoadStoreOps(VkAttachmentLoadOp loadOp, VkAttachmentStoreOp storeOp)
VkAttachmentLoadOp fLoadOp
VkFormat
Definition: vulkan_core.h:1458
@ VK_FORMAT_UNDEFINED
Definition: vulkan_core.h:1459
VkAttachmentLoadOp
Definition: vulkan_core.h:2147
@ VK_ATTACHMENT_LOAD_OP_LOAD
Definition: vulkan_core.h:2148
VkAttachmentStoreOp
Definition: vulkan_core.h:2155
@ VK_ATTACHMENT_STORE_OP_STORE
Definition: vulkan_core.h:2156