| 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 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/private/base/SkAssert.h" |
| 13 |
#include "include/private/base/SkDebug.h" |
| 14 |
#include "include/private/gpu/vk/SkiaVulkan.h" |
| 15 |
#include "src/gpu/ganesh/GrManagedResource.h" |
| 16 |
#include "src/gpu/ganesh/vk/GrVkManagedResource.h" |
| 17 |
#include "src/gpu/ganesh/vk/GrVkResourceProvider.h" |
| 18 |
|
| 19 |
#include <cinttypes> |
| 20 |
#include <cstdint> |
| 21 |
#include <memory> |
| 22 |
|
| 23 |
class GrVkGpu; |
| 24 |
class GrVkImage; |
| 25 |
class GrVkRenderPass; |
| 26 |
class GrVkSecondaryCommandBuffer; |
| 27 |
struct SkISize; |
| 28 |
|
| 29 |
class GrVkFramebuffer : public GrVkManagedResource { |
| 30 |
public: |
| 31 |
static sk_sp<const GrVkFramebuffer> Make(GrVkGpu* gpu, |
| 32 |
SkISize dimensions, |
| 33 |
sk_sp<const GrVkRenderPass> compatibleRenderPass, |
| 34 |
GrVkImage* colorAttachment, |
| 35 |
GrVkImage* resolveAttachment, |
| 36 |
GrVkImage* stencilAttachment, |
| 37 |
GrVkResourceProvider::CompatibleRPHandle); |
| 38 |
|
| 39 |
// Used for wrapped external secondary command buffers |
| 40 |
GrVkFramebuffer(const GrVkGpu* gpu, |
| 41 |
sk_sp<GrVkImage> colorAttachment, |
| 42 |
sk_sp<const GrVkRenderPass> renderPass, |
| 43 |
std::unique_ptr<GrVkSecondaryCommandBuffer>); |
| 44 |
|
| 45 |
VkFramebuffer framebuffer() const { |
| 46 |
SkASSERT(!this->isExternal()); |
| 47 |
return fFramebuffer; |
| 48 |
} |
| 49 |
|
| 50 |
bool isExternal() const { return fExternalRenderPass.get(); } |
| 51 |
const GrVkRenderPass* externalRenderPass() const { return fExternalRenderPass.get(); } |
| 52 |
std::unique_ptr<GrVkSecondaryCommandBuffer> externalCommandBuffer(); |
| 53 |
|
| 54 |
// When we wrap a secondary command buffer, we will record GrManagedResources onto it which need |
| 55 |
// to be kept alive till the command buffer gets submitted and the GPU has finished. However, in |
| 56 |
// the wrapped case, we don't know when the command buffer gets submitted and when it is |
| 57 |
// finished on the GPU since the client is in charge of that. However, we do require that the |
| 58 |
// client keeps the GrVkSecondaryCBDrawContext alive and call releaseResources on it once the |
| 59 |
// GPU is finished all the work. Thus we can use this to manage the lifetime of our |
| 60 |
// GrVkSecondaryCommandBuffers. By storing them on the external GrVkFramebuffer owned by the |
| 61 |
// GrVkRenderTarget, which is owned by the SkGpuDevice on the GrVkSecondaryCBDrawContext, we |
| 62 |
// assure that the GrManagedResources held by the GrVkSecondaryCommandBuffer don't get deleted |
| 63 |
// before they are allowed to. |
| 64 |
void returnExternalGrSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>); |
| 65 |
|
| 66 |
#ifdef SK_TRACE_MANAGED_RESOURCES |
| 67 |
void dumpInfo() const override { |
| 68 |
SkDebugf("GrVkFramebuffer: %" PRIdPTR " (%d refs)\n", |
| 69 |
(intptr_t)fFramebuffer, this->getRefCnt()); |
| 70 |
} |
| 71 |
#endif |
| 72 |
|
| 73 |
const GrVkRenderPass* compatibleRenderPass() const { return fCompatibleRenderPass.get(); } |
| 74 |
|
| 75 |
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const { |
| 76 |
return fCompatibleRenderPassHandle; |
| 77 |
} |
| 78 |
|
| 79 |
GrVkImage* colorAttachment() { return fColorAttachment.get(); } |
| 80 |
GrVkImage* resolveAttachment() { return fResolveAttachment.get(); } |
| 81 |
GrVkImage* stencilAttachment() { return fStencilAttachment.get(); } |
| 82 |
|
| 83 |
private: |
| 84 |
GrVkFramebuffer(const GrVkGpu* gpu, |
| 85 |
VkFramebuffer framebuffer, |
| 86 |
sk_sp<GrVkImage> colorAttachment, |
| 87 |
sk_sp<GrVkImage> resolveAttachment, |
| 88 |
sk_sp<GrVkImage> stencilAttachment, |
| 89 |
sk_sp<const GrVkRenderPass> compatibleRenderPass, |
| 90 |
GrVkResourceProvider::CompatibleRPHandle); |
| 91 |
|
| 92 |
~GrVkFramebuffer() override; |
| 93 |
|
| 94 |
void freeGPUData() const override; |
| 95 |
void releaseResources(); |
| 96 |
|
| 97 |
VkFramebuffer fFramebuffer = VK_NULL_HANDLE; |
| 98 |
|
| 99 |
sk_sp<GrVkImage> fColorAttachment; |
| 100 |
sk_sp<GrVkImage> fResolveAttachment; |
| 101 |
sk_sp<GrVkImage> fStencilAttachment; |
| 102 |
|
| 103 |
sk_sp<const GrVkRenderPass> fCompatibleRenderPass; |
| 104 |
GrVkResourceProvider::CompatibleRPHandle fCompatibleRenderPassHandle; |
| 105 |
|
| 106 |
sk_sp<const GrVkRenderPass> fExternalRenderPass; |
| 107 |
std::unique_ptr<GrVkSecondaryCommandBuffer> fExternalCommandBuffer; |
| 108 |
}; |
| 109 |
|
| 110 |
#endif |