blob: 623fe78e8b3585c9bceb74fd717cc17afeb24523 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrTypes.h"
12#include "include/gpu/vk/GrVkTypes.h"
Jim Van Verth5082df12020-03-11 16:14:51 -040013#include "src/gpu/vk/GrVkManagedResource.h"
Greg Daniela92d7872021-04-07 11:08:36 -040014#include "src/gpu/vk/GrVkResourceProvider.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050015
John Stiles7bf79992021-06-25 11:05:20 -040016#include <cinttypes>
17
Greg Daniel164a9f02016-02-22 09:56:40 -050018class GrVkGpu;
Greg Daniel2bc96d62021-09-13 13:08:02 -040019class GrVkImage;
Greg Daniel164a9f02016-02-22 09:56:40 -050020class GrVkImageView;
21class GrVkRenderPass;
22
Jim Van Verth5082df12020-03-11 16:14:51 -040023class GrVkFramebuffer : public GrVkManagedResource {
Greg Daniel164a9f02016-02-22 09:56:40 -050024public:
Greg Daniel805c6222021-04-20 12:44:48 -040025 static sk_sp<const GrVkFramebuffer> Make(GrVkGpu* gpu,
26 SkISize dimensions,
27 sk_sp<const GrVkRenderPass> compatibleRenderPass,
Greg Daniel2bc96d62021-09-13 13:08:02 -040028 GrVkImage* colorAttachment,
29 GrVkImage* resolveAttachment,
30 GrVkImage* stencilAttachment,
Greg Daniel805c6222021-04-20 12:44:48 -040031 GrVkResourceProvider::CompatibleRPHandle);
Greg Daniel164a9f02016-02-22 09:56:40 -050032
Greg Danielde4bbdb2021-04-13 14:23:23 -040033 // Used for wrapped external secondary command buffers
34 GrVkFramebuffer(const GrVkGpu* gpu,
Greg Daniel2bc96d62021-09-13 13:08:02 -040035 sk_sp<GrVkImage> colorAttachment,
Greg Danielde4bbdb2021-04-13 14:23:23 -040036 sk_sp<const GrVkRenderPass> renderPass,
37 std::unique_ptr<GrVkSecondaryCommandBuffer>);
38
Greg Daniel60ec6172021-04-16 11:31:58 -040039 VkFramebuffer framebuffer() const {
40 SkASSERT(!this->isExternal());
41 return fFramebuffer;
42 }
Greg Daniel164a9f02016-02-22 09:56:40 -050043
Greg Daniel60ec6172021-04-16 11:31:58 -040044 bool isExternal() const { return fExternalRenderPass.get(); }
Greg Danielde4bbdb2021-04-13 14:23:23 -040045 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 Verth3e192162020-03-10 16:23:16 -040060#ifdef SK_TRACE_MANAGED_RESOURCES
jvanverth7ec92412016-07-06 09:24:57 -070061 void dumpInfo() const override {
John Stiles7bf79992021-06-25 11:05:20 -040062 SkDebugf("GrVkFramebuffer: %" PRIdPTR " (%d refs)\n",
63 (intptr_t)fFramebuffer, this->getRefCnt());
jvanverth7ec92412016-07-06 09:24:57 -070064 }
65#endif
66
Greg Daniel805c6222021-04-20 12:44:48 -040067 const GrVkRenderPass* compatibleRenderPass() const { return fCompatibleRenderPass.get(); }
68
Greg Daniela92d7872021-04-07 11:08:36 -040069 GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const {
70 return fCompatibleRenderPassHandle;
71 }
72
Greg Daniel2bc96d62021-09-13 13:08:02 -040073 GrVkImage* colorAttachment() { return fColorAttachment.get(); }
74 GrVkImage* resolveAttachment() { return fResolveAttachment.get(); }
75 GrVkImage* stencilAttachment() { return fStencilAttachment.get(); }
Greg Danielde4bbdb2021-04-13 14:23:23 -040076
Greg Daniel164a9f02016-02-22 09:56:40 -050077private:
Greg Daniel38517c22021-03-29 16:01:19 -040078 GrVkFramebuffer(const GrVkGpu* gpu,
79 VkFramebuffer framebuffer,
Greg Daniel2bc96d62021-09-13 13:08:02 -040080 sk_sp<GrVkImage> colorAttachment,
81 sk_sp<GrVkImage> resolveAttachment,
82 sk_sp<GrVkImage> stencilAttachment,
Greg Daniel805c6222021-04-20 12:44:48 -040083 sk_sp<const GrVkRenderPass> compatibleRenderPass,
Greg Danielde4bbdb2021-04-13 14:23:23 -040084 GrVkResourceProvider::CompatibleRPHandle);
Greg Daniel164a9f02016-02-22 09:56:40 -050085
Greg Daniel38517c22021-03-29 16:01:19 -040086 ~GrVkFramebuffer() override;
Greg Daniel164a9f02016-02-22 09:56:40 -050087
Jim Van Verth5082df12020-03-11 16:14:51 -040088 void freeGPUData() const override;
Greg Danielde4bbdb2021-04-13 14:23:23 -040089 void releaseResources();
Greg Daniel164a9f02016-02-22 09:56:40 -050090
Greg Danielde4bbdb2021-04-13 14:23:23 -040091 VkFramebuffer fFramebuffer = VK_NULL_HANDLE;
Greg Daniel164a9f02016-02-22 09:56:40 -050092
Greg Daniel2bc96d62021-09-13 13:08:02 -040093 sk_sp<GrVkImage> fColorAttachment;
94 sk_sp<GrVkImage> fResolveAttachment;
95 sk_sp<GrVkImage> fStencilAttachment;
Greg Daniel38517c22021-03-29 16:01:19 -040096
Greg Daniel805c6222021-04-20 12:44:48 -040097 sk_sp<const GrVkRenderPass> fCompatibleRenderPass;
Greg Daniela92d7872021-04-07 11:08:36 -040098 GrVkResourceProvider::CompatibleRPHandle fCompatibleRenderPassHandle;
99
Greg Danielde4bbdb2021-04-13 14:23:23 -0400100 sk_sp<const GrVkRenderPass> fExternalRenderPass;
101 std::unique_ptr<GrVkSecondaryCommandBuffer> fExternalCommandBuffer;
Greg Daniel164a9f02016-02-22 09:56:40 -0500102};
103
jvanverthe50f3e72016-03-28 07:03:06 -0700104#endif