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: |
jvanverth | 9846ef2 | 2016-03-02 12:08:22 -0800 | [diff] [blame] | 23 | GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE) {} |
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, |
| 46 | const LoadStoreOps& resolveOp, |
| 47 | const LoadStoreOps& stencilOp); |
| 48 | |
| 49 | void init(const GrVkGpu* gpu, |
| 50 | const GrVkRenderPass& compatibleRenderPass, |
| 51 | const LoadStoreOps& colorOp, |
| 52 | const LoadStoreOps& resolveOp, |
| 53 | const LoadStoreOps& stencilOp); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 54 | |
| 55 | struct AttachmentsDescriptor { |
| 56 | struct AttachmentDesc { |
| 57 | VkFormat fFormat; |
| 58 | int fSamples; |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 59 | LoadStoreOps fLoadStoreOps; |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 60 | |
| 61 | AttachmentDesc() |
| 62 | : fFormat(VK_FORMAT_UNDEFINED) |
| 63 | , fSamples(0) |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 64 | , fLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE) {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 65 | bool operator==(const AttachmentDesc& right) const { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 66 | return (fFormat == right.fFormat && |
| 67 | fSamples == right.fSamples && |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 68 | fLoadStoreOps == right.fLoadStoreOps); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 69 | } |
| 70 | bool operator!=(const AttachmentDesc& right) const { |
| 71 | return !(*this == right); |
| 72 | } |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 73 | bool isCompatible(const AttachmentDesc& desc) const { |
| 74 | return (fFormat == desc.fFormat && fSamples == desc.fSamples); |
| 75 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 76 | }; |
| 77 | AttachmentDesc fColor; |
| 78 | AttachmentDesc fResolve; |
| 79 | AttachmentDesc fStencil; |
| 80 | uint32_t fAttachmentCount; |
| 81 | }; |
| 82 | |
| 83 | enum AttachmentFlags { |
| 84 | kColor_AttachmentFlag = 0x1, |
| 85 | kResolve_AttachmentFlag = 0x2, |
| 86 | kStencil_AttachmentFlag = 0x4, |
| 87 | }; |
| 88 | GR_DECL_BITFIELD_OPS_FRIENDS(AttachmentFlags); |
| 89 | |
| 90 | // The following return the index of the render pass attachment array for the given attachment. |
| 91 | // If the render pass does not have the given attachment it will return false and not set the |
| 92 | // index value. |
| 93 | bool colorAttachmentIndex(uint32_t* index) const; |
| 94 | bool resolveAttachmentIndex(uint32_t* index) const; |
| 95 | bool stencilAttachmentIndex(uint32_t* index) const; |
| 96 | |
| 97 | // Sets the VkRenderPassBeginInfo and VkRenderPassContents need to begin a render pass. |
| 98 | // TODO: In the future I expect this function will also take an optional render area instead of |
| 99 | // defaulting to the entire render target. |
| 100 | // TODO: Figure out if load clear values should be passed into this function or should be stored |
| 101 | // on the GrVkRenderPass at create time since we'll know at that point if we want to do a load |
| 102 | // clear. |
| 103 | void getBeginInfo(const GrVkRenderTarget& target, |
| 104 | VkRenderPassBeginInfo* beginInfo, |
| 105 | VkSubpassContents* contents) const; |
| 106 | |
| 107 | // Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in |
| 108 | // this object. Specifically this compares that the number of attachments, format of |
| 109 | // attachments, and sample counts are all the same. This function is used in the creation of |
| 110 | // basic RenderPasses that can be used when creating a VkFrameBuffer object. |
| 111 | bool isCompatible(const GrVkRenderTarget& target) const; |
| 112 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 113 | bool isCompatible(const GrVkRenderPass& renderPass) const; |
| 114 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 115 | bool equalLoadStoreOps(const LoadStoreOps& colorOps, |
| 116 | const LoadStoreOps& resolveOps, |
| 117 | const LoadStoreOps& stencilOps) const; |
| 118 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 119 | VkRenderPass vkRenderPass() const { return fRenderPass; } |
| 120 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 121 | void genKey(GrProcessorKeyBuilder* b) const; |
| 122 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 123 | private: |
| 124 | GrVkRenderPass(const GrVkRenderPass&); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 125 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 126 | void init(const GrVkGpu* gpu, |
| 127 | const LoadStoreOps& colorOps, |
| 128 | const LoadStoreOps& resolveOps, |
| 129 | const LoadStoreOps& stencilOps); |
| 130 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 131 | bool isCompatible(const AttachmentsDescriptor&, const AttachmentFlags&) const; |
| 132 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 133 | void freeGPUData(const GrVkGpu* gpu) const override; |
| 134 | |
| 135 | VkRenderPass fRenderPass; |
| 136 | AttachmentFlags fAttachmentFlags; |
| 137 | AttachmentsDescriptor fAttachmentsDescriptor; |
| 138 | |
| 139 | typedef GrVkResource INHERITED; |
| 140 | }; |
| 141 | |
| 142 | GR_MAKE_BITFIELD_OPS(GrVkRenderPass::AttachmentFlags); |
| 143 | |
jvanverth | 9846ef2 | 2016-03-02 12:08:22 -0800 | [diff] [blame] | 144 | #endif |