• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrVkAttachment_DEFINED
9 #define GrVkAttachment_DEFINED
10 
11 #include "include/gpu/vk/GrVkTypes.h"
12 #include "src/gpu/GrAttachment.h"
13 #include "src/gpu/GrRefCnt.h"
14 #include "src/gpu/vk/GrVkDescriptorSet.h"
15 #include "src/gpu/vk/GrVkImage.h"
16 
17 class GrVkImageView;
18 class GrVkGpu;
19 
20 class GrVkAttachment : public GrAttachment, public GrVkImage {
21 public:
22     static sk_sp<GrVkAttachment> MakeStencil(GrVkGpu* gpu,
23                                              SkISize dimensions,
24                                              int sampleCnt,
25                                              VkFormat format);
26 
27     static sk_sp<GrVkAttachment> MakeMSAA(GrVkGpu* gpu,
28                                           SkISize dimensions,
29                                           int numSamples,
30                                           VkFormat format,
31                                           GrProtected isProtected);
32 
33     static sk_sp<GrVkAttachment> MakeTexture(GrVkGpu* gpu,
34                                              SkISize dimensions,
35                                              VkFormat format,
36                                              uint32_t mipLevels,
37                                              GrRenderable renderable,
38                                              int numSamples,
39                                              SkBudgeted budgeted,
40                                              GrProtected isProtected);
41 
42     static sk_sp<GrVkAttachment> MakeWrapped(GrVkGpu* gpu,
43                                              SkISize dimensions,
44                                              const GrVkImageInfo&,
45                                              sk_sp<GrBackendSurfaceMutableStateImpl>,
46                                              UsageFlags attachmentUsages,
47                                              GrWrapOwnership,
48                                              GrWrapCacheable,
49                                              bool forSecondaryCB = false);
50 
51     ~GrVkAttachment() override;
52 
backendFormat()53     GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
54 
imageResource()55     const GrManagedResource* imageResource() const { return this->resource(); }
framebufferView()56     const GrVkImageView* framebufferView() const { return fFramebufferView.get(); }
textureView()57     const GrVkImageView* textureView() const { return fTextureView.get(); }
58 
59     // So that we don't need to rewrite descriptor sets each time, we keep cached input descriptor
60     // sets on the attachment and simply reuse those descriptor sets for this attachment only. These
61     // calls will fail if the attachment does not support being used as an input attachment. These
62     // calls do not ref the GrVkDescriptorSet so they called will need to manually ref them if they
63     // need to be kept alive.
64     gr_rp<const GrVkDescriptorSet> inputDescSetForBlending(GrVkGpu* gpu);
65     // Input descripotr set used when needing to read a resolve attachment to load data into a
66     // discardable msaa attachment.
67     gr_rp<const GrVkDescriptorSet> inputDescSetForMSAALoad(GrVkGpu* gpu);
68 
69 protected:
70     void onRelease() override;
71     void onAbandon() override;
72 
73 private:
74     static sk_sp<GrVkAttachment> Make(GrVkGpu* gpu,
75                                       SkISize dimensions,
76                                       UsageFlags attachmentUsages,
77                                       int sampleCnt,
78                                       VkFormat format,
79                                       uint32_t mipLevels,
80                                       VkImageUsageFlags vkUsageFlags,
81                                       GrProtected isProtected,
82                                       SkBudgeted);
83 
84     GrVkAttachment(GrVkGpu* gpu,
85                    SkISize dimensions,
86                    UsageFlags supportedUsages,
87                    const GrVkImageInfo&,
88                    sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
89                    sk_sp<const GrVkImageView> framebufferView,
90                    sk_sp<const GrVkImageView> textureView,
91                    SkBudgeted);
92 
93     GrVkAttachment(GrVkGpu* gpu,
94                    SkISize dimensions,
95                    UsageFlags supportedUsages,
96                    const GrVkImageInfo&,
97                    sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
98                    sk_sp<const GrVkImageView> framebufferView,
99                    sk_sp<const GrVkImageView> textureView,
100                    GrBackendObjectOwnership,
101                    GrWrapCacheable,
102                    bool forSecondaryCB);
103 
104     GrVkGpu* getVkGpu() const;
105 
106     void release();
107 
108     sk_sp<const GrVkImageView> fFramebufferView;
109     sk_sp<const GrVkImageView> fTextureView;
110 
111     // Descriptor set used when this is used as an input attachment for reading the dst in blending.
112     gr_rp<const GrVkDescriptorSet> fCachedBlendingInputDescSet;
113     // Descriptor set used when this is used as an input attachment for loading an msaa attachment.
114     gr_rp<const GrVkDescriptorSet> fCachedMSAALoadInputDescSet;
115 };
116 
117 #endif
118