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" |
| 12 | |
| 13 | #include "GrVkResource.h" |
| 14 | |
jvanverth | e50f3e7 | 2016-03-28 07:03:06 -0700 | [diff] [blame] | 15 | #include "vk/GrVkDefines.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 16 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 17 | class GrProcessorKeyBuilder; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 18 | class GrVkGpu; |
| 19 | class GrVkRenderTarget; |
| 20 | |
| 21 | class GrVkRenderPass : public GrVkResource { |
| 22 | public: |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 23 | GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE), fClearValueCount(0) {} |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 24 | |
| 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 42 | void initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& target); |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 43 | void init(const GrVkGpu* gpu, |
| 44 | const GrVkRenderTarget& target, |
| 45 | const LoadStoreOps& colorOp, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 46 | const LoadStoreOps& stencilOp); |
| 47 | |
| 48 | void init(const GrVkGpu* gpu, |
| 49 | const GrVkRenderPass& compatibleRenderPass, |
| 50 | const LoadStoreOps& colorOp, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 51 | const LoadStoreOps& stencilOp); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | |
| 53 | struct AttachmentsDescriptor { |
| 54 | struct AttachmentDesc { |
| 55 | VkFormat fFormat; |
| 56 | int fSamples; |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 57 | LoadStoreOps fLoadStoreOps; |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 58 | |
| 59 | AttachmentDesc() |
| 60 | : fFormat(VK_FORMAT_UNDEFINED) |
| 61 | , fSamples(0) |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 62 | , fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 63 | bool operator==(const AttachmentDesc& right) const { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 64 | return (fFormat == right.fFormat && |
| 65 | fSamples == right.fSamples && |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 66 | fLoadStoreOps == right.fLoadStoreOps); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 67 | } |
| 68 | bool operator!=(const AttachmentDesc& right) const { |
| 69 | return !(*this == right); |
| 70 | } |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 71 | bool isCompatible(const AttachmentDesc& desc) const { |
| 72 | return (fFormat == desc.fFormat && fSamples == desc.fSamples); |
| 73 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 74 | }; |
| 75 | AttachmentDesc fColor; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 76 | AttachmentDesc fStencil; |
| 77 | uint32_t fAttachmentCount; |
| 78 | }; |
| 79 | |
| 80 | enum AttachmentFlags { |
| 81 | kColor_AttachmentFlag = 0x1, |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 82 | kStencil_AttachmentFlag = 0x2, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 83 | }; |
| 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 90 | bool stencilAttachmentIndex(uint32_t* index) const; |
| 91 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 92 | // 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 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 98 | bool isCompatible(const GrVkRenderPass& renderPass) const; |
| 99 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 100 | bool equalLoadStoreOps(const LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 101 | const LoadStoreOps& stencilOps) const; |
| 102 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 103 | VkRenderPass vkRenderPass() const { return fRenderPass; } |
| 104 | |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 105 | const VkExtent2D& granularity() const { return fGranularity; } |
| 106 | |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 107 | // 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 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 112 | void genKey(GrProcessorKeyBuilder* b) const; |
| 113 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 114 | #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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 120 | private: |
| 121 | GrVkRenderPass(const GrVkRenderPass&); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 122 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 123 | void init(const GrVkGpu* gpu, |
| 124 | const LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 125 | const LoadStoreOps& stencilOps); |
| 126 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 127 | bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const; |
| 128 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 129 | void freeGPUData(const GrVkGpu* gpu) const override; |
| 130 | |
| 131 | VkRenderPass fRenderPass; |
| 132 | AttachmentFlags fAttachmentFlags; |
| 133 | AttachmentsDescriptor fAttachmentsDescriptor; |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 134 | VkExtent2D fGranularity; |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 135 | uint32_t fClearValueCount; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 136 | |
| 137 | typedef GrVkResource INHERITED; |
| 138 | }; |
| 139 | |
| 140 | GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags); |
| 141 | |
jvanverth | 9846ef2 | 2016-03-02 12:08:22 -0800 | [diff] [blame] | 142 | #endif |