1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci* Copyright 2016 Google Inc.
3cb93a386Sopenharmony_ci*
4cb93a386Sopenharmony_ci* Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci* found in the LICENSE file.
6cb93a386Sopenharmony_ci*/
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef GrVkResourceProvider_DEFINED
9cb93a386Sopenharmony_ci#define GrVkResourceProvider_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/gpu/vk/GrVkTypes.h"
12cb93a386Sopenharmony_ci#include "include/private/SkMutex.h"
13cb93a386Sopenharmony_ci#include "include/private/SkTArray.h"
14cb93a386Sopenharmony_ci#include "src/core/SkLRUCache.h"
15cb93a386Sopenharmony_ci#include "src/core/SkTDynamicHash.h"
16cb93a386Sopenharmony_ci#include "src/core/SkTInternalLList.h"
17cb93a386Sopenharmony_ci#include "src/gpu/GrGpu.h"
18cb93a386Sopenharmony_ci#include "src/gpu/GrManagedResource.h"
19cb93a386Sopenharmony_ci#include "src/gpu/GrProgramDesc.h"
20cb93a386Sopenharmony_ci#include "src/gpu/GrResourceHandle.h"
21cb93a386Sopenharmony_ci#include "src/gpu/GrThreadSafePipelineBuilder.h"
22cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkDescriptorPool.h"
23cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkDescriptorSetManager.h"
24cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkPipelineStateBuilder.h"
25cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkRenderPass.h"
26cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkSampler.h"
27cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkSamplerYcbcrConversion.h"
28cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkUtil.h"
29cb93a386Sopenharmony_ci
30cb93a386Sopenharmony_ciclass GrVkCommandPool;
31cb93a386Sopenharmony_ciclass GrVkGpu;
32cb93a386Sopenharmony_ciclass GrVkPipeline;
33cb93a386Sopenharmony_ciclass GrVkPipelineState;
34cb93a386Sopenharmony_ciclass GrVkPrimaryCommandBuffer;
35cb93a386Sopenharmony_ciclass GrVkRenderTarget;
36cb93a386Sopenharmony_ciclass GrVkSecondaryCommandBuffer;
37cb93a386Sopenharmony_ciclass GrVkUniformHandler;
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ciclass GrVkResourceProvider {
40cb93a386Sopenharmony_cipublic:
41cb93a386Sopenharmony_ci    GrVkResourceProvider(GrVkGpu* gpu);
42cb93a386Sopenharmony_ci    ~GrVkResourceProvider();
43cb93a386Sopenharmony_ci
44cb93a386Sopenharmony_ci    GrThreadSafePipelineBuilder* pipelineStateCache() {
45cb93a386Sopenharmony_ci        return fPipelineStateCache.get();
46cb93a386Sopenharmony_ci    }
47cb93a386Sopenharmony_ci
48cb93a386Sopenharmony_ci    sk_sp<GrThreadSafePipelineBuilder> refPipelineStateCache() {
49cb93a386Sopenharmony_ci        return fPipelineStateCache;
50cb93a386Sopenharmony_ci    }
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ci    // Set up any initial vk objects
53cb93a386Sopenharmony_ci    void init();
54cb93a386Sopenharmony_ci
55cb93a386Sopenharmony_ci    sk_sp<const GrVkPipeline> makePipeline(const GrProgramInfo&,
56cb93a386Sopenharmony_ci                                           VkPipelineShaderStageCreateInfo* shaderStageInfo,
57cb93a386Sopenharmony_ci                                           int shaderStageCount,
58cb93a386Sopenharmony_ci                                           VkRenderPass compatibleRenderPass,
59cb93a386Sopenharmony_ci                                           VkPipelineLayout layout,
60cb93a386Sopenharmony_ci                                           uint32_t subpass);
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ci    GR_DEFINE_RESOURCE_HANDLE_CLASS(CompatibleRPHandle);
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_ci    using SelfDependencyFlags = GrVkRenderPass::SelfDependencyFlags;
65cb93a386Sopenharmony_ci    using LoadFromResolve = GrVkRenderPass::LoadFromResolve;
66cb93a386Sopenharmony_ci
67cb93a386Sopenharmony_ci    // Finds or creates a simple render pass that matches the target, increments the refcount,
68cb93a386Sopenharmony_ci    // and returns. The caller can optionally pass in a pointer to a CompatibleRPHandle. If this is
69cb93a386Sopenharmony_ci    // non null it will be set to a handle that can be used in the furutre to quickly return a
70cb93a386Sopenharmony_ci    // compatible GrVkRenderPasses without the need inspecting a GrVkRenderTarget.
71cb93a386Sopenharmony_ci    const GrVkRenderPass* findCompatibleRenderPass(GrVkRenderTarget* target,
72cb93a386Sopenharmony_ci                                                   CompatibleRPHandle* compatibleHandle,
73cb93a386Sopenharmony_ci                                                   bool withResolve,
74cb93a386Sopenharmony_ci                                                   bool withStencil,
75cb93a386Sopenharmony_ci                                                   SelfDependencyFlags selfDepFlags,
76cb93a386Sopenharmony_ci                                                   LoadFromResolve);
77cb93a386Sopenharmony_ci    const GrVkRenderPass* findCompatibleRenderPass(GrVkRenderPass::AttachmentsDescriptor*,
78cb93a386Sopenharmony_ci                                                   GrVkRenderPass::AttachmentFlags,
79cb93a386Sopenharmony_ci                                                   SelfDependencyFlags selfDepFlags,
80cb93a386Sopenharmony_ci                                                   LoadFromResolve,
81cb93a386Sopenharmony_ci                                                   CompatibleRPHandle* compatibleHandle = nullptr);
82cb93a386Sopenharmony_ci
83cb93a386Sopenharmony_ci    const GrVkRenderPass* findCompatibleExternalRenderPass(VkRenderPass,
84cb93a386Sopenharmony_ci                                                           uint32_t colorAttachmentIndex);
85cb93a386Sopenharmony_ci
86cb93a386Sopenharmony_ci
87cb93a386Sopenharmony_ci    // Finds or creates a render pass that matches the target and LoadStoreOps, increments the
88cb93a386Sopenharmony_ci    // refcount, and returns. The caller can optionally pass in a pointer to a CompatibleRPHandle.
89cb93a386Sopenharmony_ci    // If this is non null it will be set to a handle that can be used in the future to quickly
90cb93a386Sopenharmony_ci    // return a GrVkRenderPass without the need to inspect a GrVkRenderTarget.
91cb93a386Sopenharmony_ci    // TODO: sk_sp?
92cb93a386Sopenharmony_ci    const GrVkRenderPass* findRenderPass(GrVkRenderTarget* target,
93cb93a386Sopenharmony_ci                                         const GrVkRenderPass::LoadStoreOps& colorOps,
94cb93a386Sopenharmony_ci                                         const GrVkRenderPass::LoadStoreOps& resolveOps,
95cb93a386Sopenharmony_ci                                         const GrVkRenderPass::LoadStoreOps& stencilOps,
96cb93a386Sopenharmony_ci                                         CompatibleRPHandle* compatibleHandle,
97cb93a386Sopenharmony_ci                                         bool withResolve,
98cb93a386Sopenharmony_ci                                         bool withStencil,
99cb93a386Sopenharmony_ci                                         SelfDependencyFlags selfDepFlags,
100cb93a386Sopenharmony_ci                                         LoadFromResolve);
101cb93a386Sopenharmony_ci
102cb93a386Sopenharmony_ci    // The CompatibleRPHandle must be a valid handle previously set by a call to findRenderPass or
103cb93a386Sopenharmony_ci    // findCompatibleRenderPass.
104cb93a386Sopenharmony_ci    const GrVkRenderPass* findRenderPass(const CompatibleRPHandle& compatibleHandle,
105cb93a386Sopenharmony_ci                                         const GrVkRenderPass::LoadStoreOps& colorOps,
106cb93a386Sopenharmony_ci                                         const GrVkRenderPass::LoadStoreOps& resolveOps,
107cb93a386Sopenharmony_ci                                         const GrVkRenderPass::LoadStoreOps& stencilOps);
108cb93a386Sopenharmony_ci
109cb93a386Sopenharmony_ci    GrVkCommandPool* findOrCreateCommandPool();
110cb93a386Sopenharmony_ci
111cb93a386Sopenharmony_ci    void checkCommandBuffers();
112cb93a386Sopenharmony_ci
113cb93a386Sopenharmony_ci    void forceSyncAllCommandBuffers();
114cb93a386Sopenharmony_ci
115cb93a386Sopenharmony_ci    // We must add the finishedProc to all active command buffers since we may have flushed work
116cb93a386Sopenharmony_ci    // that the client cares about before they explicitly called flush and the GPU may reorder
117cb93a386Sopenharmony_ci    // command execution. So we make sure all previously submitted work finishes before we call the
118cb93a386Sopenharmony_ci    // finishedProc.
119cb93a386Sopenharmony_ci    void addFinishedProcToActiveCommandBuffers(sk_sp<GrRefCntedCallback> finishedCallback);
120cb93a386Sopenharmony_ci
121cb93a386Sopenharmony_ci    // Finds or creates a compatible GrVkDescriptorPool for the requested type and count.
122cb93a386Sopenharmony_ci    // The refcount is incremented and a pointer returned.
123cb93a386Sopenharmony_ci    // TODO: Currently this will just create a descriptor pool without holding onto a ref itself
124cb93a386Sopenharmony_ci    //       so we currently do not reuse them. Rquires knowing if another draw is currently using
125cb93a386Sopenharmony_ci    //       the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out
126cb93a386Sopenharmony_ci    //       of our cache of GrVkDescriptorPools.
127cb93a386Sopenharmony_ci    GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool(VkDescriptorType type, uint32_t count);
128cb93a386Sopenharmony_ci
129cb93a386Sopenharmony_ci    // Finds or creates a compatible GrVkSampler based on the GrSamplerState and
130cb93a386Sopenharmony_ci    // GrVkYcbcrConversionInfo. The refcount is incremented and a pointer returned.
131cb93a386Sopenharmony_ci    GrVkSampler* findOrCreateCompatibleSampler(GrSamplerState,
132cb93a386Sopenharmony_ci                                               const GrVkYcbcrConversionInfo& ycbcrInfo);
133cb93a386Sopenharmony_ci
134cb93a386Sopenharmony_ci    // Finds or creates a compatible GrVkSamplerYcbcrConversion based on the GrSamplerState and
135cb93a386Sopenharmony_ci    // GrVkYcbcrConversionInfo. The refcount is incremented and a pointer returned.
136cb93a386Sopenharmony_ci    GrVkSamplerYcbcrConversion* findOrCreateCompatibleSamplerYcbcrConversion(
137cb93a386Sopenharmony_ci            const GrVkYcbcrConversionInfo& ycbcrInfo);
138cb93a386Sopenharmony_ci
139cb93a386Sopenharmony_ci    GrVkPipelineState* findOrCreateCompatiblePipelineState(
140cb93a386Sopenharmony_ci            GrRenderTarget*,
141cb93a386Sopenharmony_ci            const GrProgramInfo&,
142cb93a386Sopenharmony_ci            VkRenderPass compatibleRenderPass,
143cb93a386Sopenharmony_ci            bool overrideSubpassForResolveLoad);
144cb93a386Sopenharmony_ci
145cb93a386Sopenharmony_ci    GrVkPipelineState* findOrCreateCompatiblePipelineState(
146cb93a386Sopenharmony_ci            const GrProgramDesc&,
147cb93a386Sopenharmony_ci            const GrProgramInfo&,
148cb93a386Sopenharmony_ci            VkRenderPass compatibleRenderPass,
149cb93a386Sopenharmony_ci            GrThreadSafePipelineBuilder::Stats::ProgramCacheResult* stat);
150cb93a386Sopenharmony_ci
151cb93a386Sopenharmony_ci    sk_sp<const GrVkPipeline> findOrCreateMSAALoadPipeline(
152cb93a386Sopenharmony_ci            const GrVkRenderPass& renderPass,
153cb93a386Sopenharmony_ci            int numSamples,
154cb93a386Sopenharmony_ci            VkPipelineShaderStageCreateInfo*,
155cb93a386Sopenharmony_ci            VkPipelineLayout);
156cb93a386Sopenharmony_ci
157cb93a386Sopenharmony_ci    void getSamplerDescriptorSetHandle(VkDescriptorType type,
158cb93a386Sopenharmony_ci                                       const GrVkUniformHandler&,
159cb93a386Sopenharmony_ci                                       GrVkDescriptorSetManager::Handle* handle);
160cb93a386Sopenharmony_ci
161cb93a386Sopenharmony_ci    // This is a convenience function to return a descriptor set for zero sammples. When making a
162cb93a386Sopenharmony_ci    // VkPipelineLayout we must pass in an array of valid descriptor set handles. However, we have
163cb93a386Sopenharmony_ci    // set up our system to have the descriptor sets be in the order uniform, sampler, input. So
164cb93a386Sopenharmony_ci    // if we have a uniform and input we will need to have a valid handle for the sampler as well.
165cb93a386Sopenharmony_ci    // When using the GrVkMSAALoadManager this is the case, but we also don't have a
166cb93a386Sopenharmony_ci    // GrVkUniformHandler to pass into the more general function. Thus we use this call instead.
167cb93a386Sopenharmony_ci    void getZeroSamplerDescriptorSetHandle(GrVkDescriptorSetManager::Handle* handle);
168cb93a386Sopenharmony_ci
169cb93a386Sopenharmony_ci    // Returns the compatible VkDescriptorSetLayout to use for uniform buffers. The caller does not
170cb93a386Sopenharmony_ci    // own the VkDescriptorSetLayout and thus should not delete it. This function should be used
171cb93a386Sopenharmony_ci    // when the caller needs the layout to create a VkPipelineLayout.
172cb93a386Sopenharmony_ci    VkDescriptorSetLayout getUniformDSLayout() const;
173cb93a386Sopenharmony_ci
174cb93a386Sopenharmony_ci    // Returns the compatible VkDescriptorSetLayout to use for input attachments. The caller does
175cb93a386Sopenharmony_ci    // not own the VkDescriptorSetLayout and thus should not delete it. This function should be used
176cb93a386Sopenharmony_ci    // when the caller needs the layout to create a VkPipelineLayout.
177cb93a386Sopenharmony_ci    VkDescriptorSetLayout getInputDSLayout() const;
178cb93a386Sopenharmony_ci
179cb93a386Sopenharmony_ci    // Returns the compatible VkDescriptorSetLayout to use for a specific sampler handle. The caller
180cb93a386Sopenharmony_ci    // does not own the VkDescriptorSetLayout and thus should not delete it. This function should be
181cb93a386Sopenharmony_ci    // used when the caller needs the layout to create a VkPipelineLayout.
182cb93a386Sopenharmony_ci    VkDescriptorSetLayout getSamplerDSLayout(const GrVkDescriptorSetManager::Handle&) const;
183cb93a386Sopenharmony_ci
184cb93a386Sopenharmony_ci    // Returns a GrVkDescriptorSet that can be used for uniform buffers. The GrVkDescriptorSet
185cb93a386Sopenharmony_ci    // is already reffed for the caller.
186cb93a386Sopenharmony_ci    const GrVkDescriptorSet* getUniformDescriptorSet();
187cb93a386Sopenharmony_ci
188cb93a386Sopenharmony_ci    // Returns a GrVkDescriptorSet that can be used for sampler descriptors that are compatible with
189cb93a386Sopenharmony_ci    // the GrVkDescriptorSetManager::Handle passed in. The GrVkDescriptorSet is already reffed for
190cb93a386Sopenharmony_ci    // the caller.
191cb93a386Sopenharmony_ci    const GrVkDescriptorSet* getSamplerDescriptorSet(const GrVkDescriptorSetManager::Handle&);
192cb93a386Sopenharmony_ci
193cb93a386Sopenharmony_ci    // Returns a GrVkDescriptorSet that can be used for input attachments. The GrVkDescriptorSet
194cb93a386Sopenharmony_ci    // is already reffed for the caller.
195cb93a386Sopenharmony_ci    const GrVkDescriptorSet* getInputDescriptorSet();
196cb93a386Sopenharmony_ci
197cb93a386Sopenharmony_ci    // Signals that the descriptor set passed it, which is compatible with the passed in handle,
198cb93a386Sopenharmony_ci    // can be reused by the next allocation request.
199cb93a386Sopenharmony_ci    void recycleDescriptorSet(const GrVkDescriptorSet* descSet,
200cb93a386Sopenharmony_ci                              const GrVkDescriptorSetManager::Handle&);
201cb93a386Sopenharmony_ci
202cb93a386Sopenharmony_ci    void storePipelineCacheData();
203cb93a386Sopenharmony_ci
204cb93a386Sopenharmony_ci    // Destroy any cached resources. To be called before destroying the VkDevice.
205cb93a386Sopenharmony_ci    // The assumption is that all queues are idle and all command buffers are finished.
206cb93a386Sopenharmony_ci    // For resource tracing to work properly, this should be called after unrefing all other
207cb93a386Sopenharmony_ci    // resource usages.
208cb93a386Sopenharmony_ci    void destroyResources();
209cb93a386Sopenharmony_ci
210cb93a386Sopenharmony_ci    // Currently we just release available command pools (which also releases their buffers). The
211cb93a386Sopenharmony_ci    // command buffers and pools take up the most memory. Other objects (e.g. samples,
212cb93a386Sopenharmony_ci    // ycbcr conversions, etc.) tend to be fairly light weight and not worth the effort to remove
213cb93a386Sopenharmony_ci    // them and then possibly remake them. Additionally many of those objects have refs/handles that
214cb93a386Sopenharmony_ci    // are held by other objects that aren't deleted here. Thus the memory wins for removing these
215cb93a386Sopenharmony_ci    // objects from the cache are probably not worth the complexity of safely releasing them.
216cb93a386Sopenharmony_ci    void releaseUnlockedBackendObjects();
217cb93a386Sopenharmony_ci
218cb93a386Sopenharmony_ci    void backgroundReset(GrVkCommandPool* pool);
219cb93a386Sopenharmony_ci
220cb93a386Sopenharmony_ci    void reset(GrVkCommandPool* pool);
221cb93a386Sopenharmony_ci
222cb93a386Sopenharmony_ci#if GR_TEST_UTILS
223cb93a386Sopenharmony_ci    void resetShaderCacheForTesting() const { fPipelineStateCache->release(); }
224cb93a386Sopenharmony_ci#endif
225cb93a386Sopenharmony_ci
226cb93a386Sopenharmony_ciprivate:
227cb93a386Sopenharmony_ci    class PipelineStateCache : public GrThreadSafePipelineBuilder {
228cb93a386Sopenharmony_ci    public:
229cb93a386Sopenharmony_ci        PipelineStateCache(GrVkGpu* gpu);
230cb93a386Sopenharmony_ci        ~PipelineStateCache() override;
231cb93a386Sopenharmony_ci
232cb93a386Sopenharmony_ci        void release();
233cb93a386Sopenharmony_ci        GrVkPipelineState* findOrCreatePipelineState(GrRenderTarget*,
234cb93a386Sopenharmony_ci                                                     const GrProgramInfo&,
235cb93a386Sopenharmony_ci                                                     VkRenderPass compatibleRenderPass,
236cb93a386Sopenharmony_ci                                                     bool overrideSubpassForResolveLoad);
237cb93a386Sopenharmony_ci        GrVkPipelineState* findOrCreatePipelineState(const GrProgramDesc& desc,
238cb93a386Sopenharmony_ci                                                     const GrProgramInfo& programInfo,
239cb93a386Sopenharmony_ci                                                     VkRenderPass compatibleRenderPass,
240cb93a386Sopenharmony_ci                                                     Stats::ProgramCacheResult* stat) {
241cb93a386Sopenharmony_ci            return this->findOrCreatePipelineStateImpl(desc, programInfo, compatibleRenderPass,
242cb93a386Sopenharmony_ci                                                       false, stat);
243cb93a386Sopenharmony_ci        }
244cb93a386Sopenharmony_ci
245cb93a386Sopenharmony_ci    private:
246cb93a386Sopenharmony_ci        struct Entry;
247cb93a386Sopenharmony_ci
248cb93a386Sopenharmony_ci        GrVkPipelineState* findOrCreatePipelineStateImpl(const GrProgramDesc&,
249cb93a386Sopenharmony_ci                                                         const GrProgramInfo&,
250cb93a386Sopenharmony_ci                                                         VkRenderPass compatibleRenderPass,
251cb93a386Sopenharmony_ci                                                         bool overrideSubpassForResolveLoad,
252cb93a386Sopenharmony_ci                                                         Stats::ProgramCacheResult*);
253cb93a386Sopenharmony_ci
254cb93a386Sopenharmony_ci        struct DescHash {
255cb93a386Sopenharmony_ci            uint32_t operator()(const GrProgramDesc& desc) const {
256cb93a386Sopenharmony_ci                return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
257cb93a386Sopenharmony_ci            }
258cb93a386Sopenharmony_ci        };
259cb93a386Sopenharmony_ci
260cb93a386Sopenharmony_ci        SkLRUCache<const GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
261cb93a386Sopenharmony_ci
262cb93a386Sopenharmony_ci        GrVkGpu*                    fGpu;
263cb93a386Sopenharmony_ci    };
264cb93a386Sopenharmony_ci
265cb93a386Sopenharmony_ci    class CompatibleRenderPassSet {
266cb93a386Sopenharmony_ci    public:
267cb93a386Sopenharmony_ci        // This will always construct the basic load store render pass (all attachments load and
268cb93a386Sopenharmony_ci        // store their data) so that there is at least one compatible VkRenderPass that can be used
269cb93a386Sopenharmony_ci        // with this set.
270cb93a386Sopenharmony_ci        CompatibleRenderPassSet(GrVkRenderPass* renderPass);
271cb93a386Sopenharmony_ci
272cb93a386Sopenharmony_ci        bool isCompatible(const GrVkRenderPass::AttachmentsDescriptor&,
273cb93a386Sopenharmony_ci                          GrVkRenderPass::AttachmentFlags,
274cb93a386Sopenharmony_ci                          SelfDependencyFlags selfDepFlags,
275cb93a386Sopenharmony_ci                          LoadFromResolve) const;
276cb93a386Sopenharmony_ci
277cb93a386Sopenharmony_ci        const GrVkRenderPass* getCompatibleRenderPass() const {
278cb93a386Sopenharmony_ci            // The first GrVkRenderpass should always exist since we create the basic load store
279cb93a386Sopenharmony_ci            // render pass on create
280cb93a386Sopenharmony_ci            SkASSERT(fRenderPasses[0]);
281cb93a386Sopenharmony_ci            return fRenderPasses[0];
282cb93a386Sopenharmony_ci        }
283cb93a386Sopenharmony_ci
284cb93a386Sopenharmony_ci        GrVkRenderPass* getRenderPass(GrVkGpu* gpu,
285cb93a386Sopenharmony_ci                                      const GrVkRenderPass::LoadStoreOps& colorOps,
286cb93a386Sopenharmony_ci                                      const GrVkRenderPass::LoadStoreOps& resolveOps,
287cb93a386Sopenharmony_ci                                      const GrVkRenderPass::LoadStoreOps& stencilOps);
288cb93a386Sopenharmony_ci
289cb93a386Sopenharmony_ci        void releaseResources();
290cb93a386Sopenharmony_ci
291cb93a386Sopenharmony_ci    private:
292cb93a386Sopenharmony_ci        SkSTArray<4, GrVkRenderPass*> fRenderPasses;
293cb93a386Sopenharmony_ci        int                           fLastReturnedIndex;
294cb93a386Sopenharmony_ci    };
295cb93a386Sopenharmony_ci
296cb93a386Sopenharmony_ci    VkPipelineCache pipelineCache();
297cb93a386Sopenharmony_ci
298cb93a386Sopenharmony_ci    GrVkGpu* fGpu;
299cb93a386Sopenharmony_ci
300cb93a386Sopenharmony_ci    // Central cache for creating pipelines
301cb93a386Sopenharmony_ci    VkPipelineCache fPipelineCache;
302cb93a386Sopenharmony_ci    //CAUTION: should only used in GrVkResourceProvider
303cb93a386Sopenharmony_ci    size_t fPipelineCacheSize;
304cb93a386Sopenharmony_ci
305cb93a386Sopenharmony_ci    struct MSAALoadPipeline {
306cb93a386Sopenharmony_ci        sk_sp<const GrVkPipeline> fPipeline;
307cb93a386Sopenharmony_ci        const GrVkRenderPass* fRenderPass;
308cb93a386Sopenharmony_ci    };
309cb93a386Sopenharmony_ci
310cb93a386Sopenharmony_ci    // Cache of previously created msaa load pipelines
311cb93a386Sopenharmony_ci    SkTArray<MSAALoadPipeline> fMSAALoadPipelines;
312cb93a386Sopenharmony_ci
313cb93a386Sopenharmony_ci    SkSTArray<4, CompatibleRenderPassSet> fRenderPassArray;
314cb93a386Sopenharmony_ci
315cb93a386Sopenharmony_ci    SkTArray<const GrVkRenderPass*> fExternalRenderPasses;
316cb93a386Sopenharmony_ci
317cb93a386Sopenharmony_ci    // Array of command pools that we are waiting on
318cb93a386Sopenharmony_ci    SkSTArray<4, GrVkCommandPool*, true> fActiveCommandPools;
319cb93a386Sopenharmony_ci
320cb93a386Sopenharmony_ci    SkMutex fBackgroundMutex;
321cb93a386Sopenharmony_ci
322cb93a386Sopenharmony_ci    // Array of available command pools that are not in flight
323cb93a386Sopenharmony_ci    SkSTArray<4, GrVkCommandPool*, true> fAvailableCommandPools SK_GUARDED_BY(fBackgroundMutex);
324cb93a386Sopenharmony_ci
325cb93a386Sopenharmony_ci    // Stores GrVkSampler objects that we've already created so we can reuse them across multiple
326cb93a386Sopenharmony_ci    // GrVkPipelineStates
327cb93a386Sopenharmony_ci    SkTDynamicHash<GrVkSampler, GrVkSampler::Key> fSamplers;
328cb93a386Sopenharmony_ci
329cb93a386Sopenharmony_ci    // Stores GrVkSamplerYcbcrConversion objects that we've already created so we can reuse them.
330cb93a386Sopenharmony_ci    SkTDynamicHash<GrVkSamplerYcbcrConversion, GrVkSamplerYcbcrConversion::Key> fYcbcrConversions;
331cb93a386Sopenharmony_ci
332cb93a386Sopenharmony_ci    // Cache of GrVkPipelineStates
333cb93a386Sopenharmony_ci    sk_sp<PipelineStateCache> fPipelineStateCache;
334cb93a386Sopenharmony_ci
335cb93a386Sopenharmony_ci    SkSTArray<4, std::unique_ptr<GrVkDescriptorSetManager>> fDescriptorSetManagers;
336cb93a386Sopenharmony_ci
337cb93a386Sopenharmony_ci    GrVkDescriptorSetManager::Handle fUniformDSHandle;
338cb93a386Sopenharmony_ci    GrVkDescriptorSetManager::Handle fInputDSHandle;
339cb93a386Sopenharmony_ci};
340cb93a386Sopenharmony_ci
341cb93a386Sopenharmony_ci#endif
342