1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrVkRenderPass_DEFINED
#define GrVkRenderPass_DEFINED
#include "GrTypes.h"
#include "GrVkResource.h"
#include "vk/GrVkDefines.h"
class GrProcessorKeyBuilder;
class GrVkGpu;
class GrVkRenderTarget;
class GrVkRenderPass : public GrVkResource {
public:
GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE) {}
struct LoadStoreOps {
VkAttachmentLoadOp fLoadOp;
VkAttachmentStoreOp fStoreOp;
LoadStoreOps(VkAttachmentLoadOp loadOp, VkAttachmentStoreOp storeOp)
: fLoadOp(loadOp)
, fStoreOp(storeOp) {}
bool operator==(const LoadStoreOps& right) const {
return fLoadOp == right.fLoadOp && fStoreOp == right.fStoreOp;
}
bool operator!=(const LoadStoreOps& right) const {
return !(*this == right);
}
};
void initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& target);
void init(const GrVkGpu* gpu,
const GrVkRenderTarget& target,
const LoadStoreOps& colorOp,
const LoadStoreOps& stencilOp);
void init(const GrVkGpu* gpu,
const GrVkRenderPass& compatibleRenderPass,
const LoadStoreOps& colorOp,
const LoadStoreOps& stencilOp);
struct AttachmentsDescriptor {
struct AttachmentDesc {
VkFormat fFormat;
int fSamples;
LoadStoreOps fLoadStoreOps;
AttachmentDesc()
: fFormat(VK_FORMAT_UNDEFINED)
, fSamples(0)
, fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {}
bool operator==(const AttachmentDesc& right) const {
return (fFormat == right.fFormat &&
fSamples == right.fSamples &&
fLoadStoreOps == right.fLoadStoreOps);
}
bool operator!=(const AttachmentDesc& right) const {
return !(*this == right);
}
bool isCompatible(const AttachmentDesc& desc) const {
return (fFormat == desc.fFormat && fSamples == desc.fSamples);
}
};
AttachmentDesc fColor;
AttachmentDesc fStencil;
uint32_t fAttachmentCount;
};
enum AttachmentFlags {
kColor_AttachmentFlag = 0x1,
kStencil_AttachmentFlag = 0x2,
};
GR_DECL_BITFIELD_OPS_FRIENDS(AttachmentFlags);
// The following return the index of the render pass attachment array for the given attachment.
// If the render pass does not have the given attachment it will return false and not set the
// index value.
bool colorAttachmentIndex(uint32_t* index) const;
bool stencilAttachmentIndex(uint32_t* index) const;
// Sets the VkRenderPassBeginInfo and VkRenderPassContents need to begin a render pass.
// TODO: In the future I expect this function will also take an optional render area instead of
// defaulting to the entire render target.
// TODO: Figure out if load clear values should be passed into this function or should be stored
// on the GrVkRenderPass at create time since we'll know at that point if we want to do a load
// clear.
void getBeginInfo(const GrVkRenderTarget& target,
VkRenderPassBeginInfo* beginInfo,
VkSubpassContents* contents) const;
// Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in
// this object. Specifically this compares that the number of attachments, format of
// attachments, and sample counts are all the same. This function is used in the creation of
// basic RenderPasses that can be used when creating a VkFrameBuffer object.
bool isCompatible(const GrVkRenderTarget& target) const;
bool isCompatible(const GrVkRenderPass& renderPass) const;
bool equalLoadStoreOps(const LoadStoreOps& colorOps,
const LoadStoreOps& stencilOps) const;
VkRenderPass vkRenderPass() const { return fRenderPass; }
const VkExtent2D& granularity() const { return fGranularity; }
void genKey(GrProcessorKeyBuilder* b) const;
#ifdef SK_TRACE_VK_RESOURCES
void dumpInfo() const override {
SkDebugf("GrVkRenderPass: %d (%d refs)\n", fRenderPass, this->getRefCnt());
}
#endif
private:
GrVkRenderPass(const GrVkRenderPass&);
void init(const GrVkGpu* gpu,
const LoadStoreOps& colorOps,
const LoadStoreOps& stencilOps);
bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const;
void freeGPUData(const GrVkGpu* gpu) const override;
VkRenderPass fRenderPass;
AttachmentFlags fAttachmentFlags;
AttachmentsDescriptor fAttachmentsDescriptor;
VkExtent2D fGranularity;
typedef GrVkResource INHERITED;
};
GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags);
#endif
|