blob: b3b6092a5e6832ca82bade9618fc74afe5b39afd [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:
Greg Daniel77a86f82017-01-23 11:04:45 -050023 GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE), fClearValueCount(0) {}
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,
egdaniel2feb0932016-06-08 06:48:09 -070046 const LoadStoreOps& stencilOp);
47
48 void init(const GrVkGpu* gpu,
49 const GrVkRenderPass& compatibleRenderPass,
50 const LoadStoreOps& colorOp,
egdaniel2feb0932016-06-08 06:48:09 -070051 const LoadStoreOps& stencilOp);
Greg Daniel164a9f02016-02-22 09:56:40 -050052
53 struct AttachmentsDescriptor {
54 struct AttachmentDesc {
55 VkFormat fFormat;
56 int fSamples;
egdaniel2feb0932016-06-08 06:48:09 -070057 LoadStoreOps fLoadStoreOps;
egdanield62e28b2016-06-07 08:43:30 -070058
59 AttachmentDesc()
60 : fFormat(VK_FORMAT_UNDEFINED)
61 , fSamples(0)
egdaniel2feb0932016-06-08 06:48:09 -070062 , fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {}
Greg Daniel164a9f02016-02-22 09:56:40 -050063 bool operator==(const AttachmentDesc& right) const {
egdanield62e28b2016-06-07 08:43:30 -070064 return (fFormat == right.fFormat &&
65 fSamples == right.fSamples &&
egdaniel2feb0932016-06-08 06:48:09 -070066 fLoadStoreOps == right.fLoadStoreOps);
Greg Daniel164a9f02016-02-22 09:56:40 -050067 }
68 bool operator!=(const AttachmentDesc& right) const {
69 return !(*this == right);
70 }
egdanield62e28b2016-06-07 08:43:30 -070071 bool isCompatible(const AttachmentDesc& desc) const {
72 return (fFormat == desc.fFormat && fSamples == desc.fSamples);
73 }
Greg Daniel164a9f02016-02-22 09:56:40 -050074 };
75 AttachmentDesc fColor;
Greg Daniel164a9f02016-02-22 09:56:40 -050076 AttachmentDesc fStencil;
77 uint32_t fAttachmentCount;
78 };
79
80 enum AttachmentFlags {
81 kColor_AttachmentFlag = 0x1,
egdanielce3bfb12016-08-26 11:05:13 -070082 kStencil_AttachmentFlag = 0x2,
Greg Daniel164a9f02016-02-22 09:56:40 -050083 };
84 GR_DECL_BITFIELD_OPS_FRIENDS(AttachmentFlags);
85
86 // The following return the index of the render pass attachment array for the given attachment.
87 // If the render pass does not have the given attachment it will return false and not set the
88 // index value.
89 bool colorAttachmentIndex(uint32_t* index) const;
Greg Daniel164a9f02016-02-22 09:56:40 -050090 bool stencilAttachmentIndex(uint32_t* index) const;
91
Greg Daniel164a9f02016-02-22 09:56:40 -050092 // Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in
93 // this object. Specifically this compares that the number of attachments, format of
94 // attachments, and sample counts are all the same. This function is used in the creation of
95 // basic RenderPasses that can be used when creating a VkFrameBuffer object.
96 bool isCompatible(const GrVkRenderTarget& target) const;
97
egdaniel9a6cf802016-06-08 08:22:05 -070098 bool isCompatible(const GrVkRenderPass& renderPass) const;
99
egdaniel2feb0932016-06-08 06:48:09 -0700100 bool equalLoadStoreOps(const LoadStoreOps& colorOps,
egdaniel2feb0932016-06-08 06:48:09 -0700101 const LoadStoreOps& stencilOps) const;
102
Greg Daniel164a9f02016-02-22 09:56:40 -0500103 VkRenderPass vkRenderPass() const { return fRenderPass; }
104
egdaniel27bb2842016-07-07 11:58:35 -0700105 const VkExtent2D& granularity() const { return fGranularity; }
106
Greg Daniel77a86f82017-01-23 11:04:45 -0500107 // Returns the number of clear colors needed to begin this render pass. Currently this will
108 // either only be 0 or 1 since we only ever clear the color attachment.
109 uint32_t clearValueCount() const { return fClearValueCount; }
110
111
egdaniel22281c12016-03-23 13:49:40 -0700112 void genKey(GrProcessorKeyBuilder* b) const;
113
jvanverth7ec92412016-07-06 09:24:57 -0700114#ifdef SK_TRACE_VK_RESOURCES
115 void dumpInfo() const override {
116 SkDebugf("GrVkRenderPass: %d (%d refs)\n", fRenderPass, this->getRefCnt());
117 }
118#endif
119
Greg Daniel164a9f02016-02-22 09:56:40 -0500120private:
121 GrVkRenderPass(const GrVkRenderPass&);
Greg Daniel164a9f02016-02-22 09:56:40 -0500122
egdaniel2feb0932016-06-08 06:48:09 -0700123 void init(const GrVkGpu* gpu,
124 const LoadStoreOps& colorOps,
egdaniel2feb0932016-06-08 06:48:09 -0700125 const LoadStoreOps& stencilOps);
126
egdaniel9a6cf802016-06-08 08:22:05 -0700127 bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const;
128
Greg Daniel164a9f02016-02-22 09:56:40 -0500129 void freeGPUData(const GrVkGpu* gpu) const override;
130
131 VkRenderPass fRenderPass;
132 AttachmentFlags fAttachmentFlags;
133 AttachmentsDescriptor fAttachmentsDescriptor;
egdaniel27bb2842016-07-07 11:58:35 -0700134 VkExtent2D fGranularity;
Greg Daniel77a86f82017-01-23 11:04:45 -0500135 uint32_t fClearValueCount;
Greg Daniel164a9f02016-02-22 09:56:40 -0500136
137 typedef GrVkResource INHERITED;
138};
139
140GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags);
141
jvanverth9846ef22016-03-02 12:08:22 -0800142#endif