Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 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 "GrTypes.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 12 | #include "GrVkResource.h" |
Greg Daniel | 487132b | 2018-12-20 14:09:36 -0500 | [diff] [blame] | 13 | #include "vk/GrVkTypes.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 15 | class GrProcessorKeyBuilder; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 16 | class GrVkGpu; |
| 17 | class GrVkRenderTarget; |
| 18 | |
| 19 | class GrVkRenderPass : public GrVkResource { |
| 20 | public: |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 21 | GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE), fClearValueCount(0) {} |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 22 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 23 | // 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 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 32 | 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 49 | void initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& target); |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 50 | void init(const GrVkGpu* gpu, |
| 51 | const GrVkRenderTarget& target, |
| 52 | const LoadStoreOps& colorOp, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 53 | const LoadStoreOps& stencilOp); |
| 54 | |
| 55 | void init(const GrVkGpu* gpu, |
| 56 | const GrVkRenderPass& compatibleRenderPass, |
| 57 | const LoadStoreOps& colorOp, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 58 | const LoadStoreOps& stencilOp); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 59 | |
| 60 | struct AttachmentsDescriptor { |
| 61 | struct AttachmentDesc { |
| 62 | VkFormat fFormat; |
| 63 | int fSamples; |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 64 | LoadStoreOps fLoadStoreOps; |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 65 | |
| 66 | AttachmentDesc() |
| 67 | : fFormat(VK_FORMAT_UNDEFINED) |
| 68 | , fSamples(0) |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 69 | , fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 70 | bool operator==(const AttachmentDesc& right) const { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 71 | return (fFormat == right.fFormat && |
| 72 | fSamples == right.fSamples && |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 73 | fLoadStoreOps == right.fLoadStoreOps); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 74 | } |
| 75 | bool operator!=(const AttachmentDesc& right) const { |
| 76 | return !(*this == right); |
| 77 | } |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 78 | bool isCompatible(const AttachmentDesc& desc) const { |
| 79 | return (fFormat == desc.fFormat && fSamples == desc.fSamples); |
| 80 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 81 | }; |
| 82 | AttachmentDesc fColor; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 83 | AttachmentDesc fStencil; |
| 84 | uint32_t fAttachmentCount; |
| 85 | }; |
| 86 | |
| 87 | enum AttachmentFlags { |
| 88 | kColor_AttachmentFlag = 0x1, |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 89 | kStencil_AttachmentFlag = 0x2, |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 90 | // 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 95 | }; |
| 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 102 | bool stencilAttachmentIndex(uint32_t* index) const; |
| 103 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 104 | // 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 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 110 | bool isCompatible(const GrVkRenderPass& renderPass) const; |
| 111 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 112 | bool isCompatibleExternalRP(VkRenderPass) const; |
| 113 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 114 | bool equalLoadStoreOps(const LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 115 | const LoadStoreOps& stencilOps) const; |
| 116 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 117 | VkRenderPass vkRenderPass() const { return fRenderPass; } |
| 118 | |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 119 | const VkExtent2D& granularity() const { return fGranularity; } |
| 120 | |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 121 | // 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 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 126 | void genKey(GrProcessorKeyBuilder* b) const; |
| 127 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 128 | #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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 134 | private: |
| 135 | GrVkRenderPass(const GrVkRenderPass&); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 136 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 137 | void init(const GrVkGpu* gpu, |
| 138 | const LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 139 | const LoadStoreOps& stencilOps); |
| 140 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 141 | bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const; |
| 142 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 143 | void freeGPUData(GrVkGpu* gpu) const override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 144 | |
| 145 | VkRenderPass fRenderPass; |
| 146 | AttachmentFlags fAttachmentFlags; |
| 147 | AttachmentsDescriptor fAttachmentsDescriptor; |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 148 | VkExtent2D fGranularity; |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 149 | uint32_t fClearValueCount; |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 150 | // For internally created render passes we assume the color attachment index is always 0. |
| 151 | uint32_t fColorAttachmentIndex = 0; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 152 | |
| 153 | typedef GrVkResource INHERITED; |
| 154 | }; |
| 155 | |
| 156 | GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags); |
| 157 | |
jvanverth | 9846ef2 | 2016-03-02 12:08:22 -0800 | [diff] [blame] | 158 | #endif |