Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrVkFramebuffer_DEFINED |
| 9 | #define GrVkFramebuffer_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrTypes.h" |
| 12 | #include "include/gpu/vk/GrVkTypes.h" |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 13 | #include "src/gpu/vk/GrVkManagedResource.h" |
Greg Daniel | a92d787 | 2021-04-07 11:08:36 -0400 | [diff] [blame] | 14 | #include "src/gpu/vk/GrVkResourceProvider.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | |
John Stiles | 7bf7999 | 2021-06-25 11:05:20 -0400 | [diff] [blame] | 16 | #include <cinttypes> |
| 17 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 18 | class GrVkGpu; |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 19 | class GrVkImage; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 20 | class GrVkImageView; |
| 21 | class GrVkRenderPass; |
| 22 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 23 | class GrVkFramebuffer : public GrVkManagedResource { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 24 | public: |
Greg Daniel | 805c622 | 2021-04-20 12:44:48 -0400 | [diff] [blame] | 25 | static sk_sp<const GrVkFramebuffer> Make(GrVkGpu* gpu, |
| 26 | SkISize dimensions, |
| 27 | sk_sp<const GrVkRenderPass> compatibleRenderPass, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 28 | GrVkImage* colorAttachment, |
| 29 | GrVkImage* resolveAttachment, |
| 30 | GrVkImage* stencilAttachment, |
Greg Daniel | 805c622 | 2021-04-20 12:44:48 -0400 | [diff] [blame] | 31 | GrVkResourceProvider::CompatibleRPHandle); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 33 | // Used for wrapped external secondary command buffers |
| 34 | GrVkFramebuffer(const GrVkGpu* gpu, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 35 | sk_sp<GrVkImage> colorAttachment, |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 36 | sk_sp<const GrVkRenderPass> renderPass, |
| 37 | std::unique_ptr<GrVkSecondaryCommandBuffer>); |
| 38 | |
Greg Daniel | 60ec617 | 2021-04-16 11:31:58 -0400 | [diff] [blame] | 39 | VkFramebuffer framebuffer() const { |
| 40 | SkASSERT(!this->isExternal()); |
| 41 | return fFramebuffer; |
| 42 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | |
Greg Daniel | 60ec617 | 2021-04-16 11:31:58 -0400 | [diff] [blame] | 44 | bool isExternal() const { return fExternalRenderPass.get(); } |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 45 | const GrVkRenderPass* externalRenderPass() const { return fExternalRenderPass.get(); } |
| 46 | std::unique_ptr<GrVkSecondaryCommandBuffer> externalCommandBuffer(); |
| 47 | |
| 48 | // When we wrap a secondary command buffer, we will record GrManagedResources onto it which need |
| 49 | // to be kept alive till the command buffer gets submitted and the GPU has finished. However, in |
| 50 | // the wrapped case, we don't know when the command buffer gets submitted and when it is |
| 51 | // finished on the GPU since the client is in charge of that. However, we do require that the |
| 52 | // client keeps the GrVkSecondaryCBDrawContext alive and call releaseResources on it once the |
| 53 | // GPU is finished all the work. Thus we can use this to manage the lifetime of our |
| 54 | // GrVkSecondaryCommandBuffers. By storing them on the external GrVkFramebuffer owned by the |
| 55 | // GrVkRenderTarget, which is owned by the SkGpuDevice on the GrVkSecondaryCBDrawContext, we |
| 56 | // assure that the GrManagedResources held by the GrVkSecondaryCommandBuffer don't get deleted |
| 57 | // before they are allowed to. |
| 58 | void returnExternalGrSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>); |
| 59 | |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 60 | #ifdef SK_TRACE_MANAGED_RESOURCES |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 61 | void dumpInfo() const override { |
John Stiles | 7bf7999 | 2021-06-25 11:05:20 -0400 | [diff] [blame] | 62 | SkDebugf("GrVkFramebuffer: %" PRIdPTR " (%d refs)\n", |
| 63 | (intptr_t)fFramebuffer, this->getRefCnt()); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | |
Greg Daniel | 805c622 | 2021-04-20 12:44:48 -0400 | [diff] [blame] | 67 | const GrVkRenderPass* compatibleRenderPass() const { return fCompatibleRenderPass.get(); } |
| 68 | |
Greg Daniel | a92d787 | 2021-04-07 11:08:36 -0400 | [diff] [blame] | 69 | GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const { |
| 70 | return fCompatibleRenderPassHandle; |
| 71 | } |
| 72 | |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 73 | GrVkImage* colorAttachment() { return fColorAttachment.get(); } |
| 74 | GrVkImage* resolveAttachment() { return fResolveAttachment.get(); } |
| 75 | GrVkImage* stencilAttachment() { return fStencilAttachment.get(); } |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 76 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 77 | private: |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 78 | GrVkFramebuffer(const GrVkGpu* gpu, |
| 79 | VkFramebuffer framebuffer, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 80 | sk_sp<GrVkImage> colorAttachment, |
| 81 | sk_sp<GrVkImage> resolveAttachment, |
| 82 | sk_sp<GrVkImage> stencilAttachment, |
Greg Daniel | 805c622 | 2021-04-20 12:44:48 -0400 | [diff] [blame] | 83 | sk_sp<const GrVkRenderPass> compatibleRenderPass, |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 84 | GrVkResourceProvider::CompatibleRPHandle); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 85 | |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 86 | ~GrVkFramebuffer() override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 87 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 88 | void freeGPUData() const override; |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 89 | void releaseResources(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 90 | |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 91 | VkFramebuffer fFramebuffer = VK_NULL_HANDLE; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 92 | |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 93 | sk_sp<GrVkImage> fColorAttachment; |
| 94 | sk_sp<GrVkImage> fResolveAttachment; |
| 95 | sk_sp<GrVkImage> fStencilAttachment; |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 96 | |
Greg Daniel | 805c622 | 2021-04-20 12:44:48 -0400 | [diff] [blame] | 97 | sk_sp<const GrVkRenderPass> fCompatibleRenderPass; |
Greg Daniel | a92d787 | 2021-04-07 11:08:36 -0400 | [diff] [blame] | 98 | GrVkResourceProvider::CompatibleRPHandle fCompatibleRenderPassHandle; |
| 99 | |
Greg Daniel | de4bbdb | 2021-04-13 14:23:23 -0400 | [diff] [blame] | 100 | sk_sp<const GrVkRenderPass> fExternalRenderPass; |
| 101 | std::unique_ptr<GrVkSecondaryCommandBuffer> fExternalCommandBuffer; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 102 | }; |
| 103 | |
jvanverth | e50f3e7 | 2016-03-28 07:03:06 -0700 | [diff] [blame] | 104 | #endif |