• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 GrVkCommandPool_DEFINED
9 #define GrVkCommandPool_DEFINED
10 
11 #include "src/gpu/vk/GrVkInterface.h"
12 #include "src/gpu/vk/GrVkManagedResource.h"
13 #include "src/gpu/vk/GrVkResourceProvider.h"
14 
15 #include <cinttypes>
16 
17 class GrVkPrimaryCommandBuffer;
18 class GrVkSecondaryCommandBuffer;
19 class GrVkGpu;
20 
21 class GrVkCommandPool : public GrVkManagedResource {
22 public:
23     static GrVkCommandPool* Create(GrVkGpu* gpu);
24 
vkCommandPool()25     VkCommandPool vkCommandPool() const {
26         return fCommandPool;
27     }
28 
29     void reset(GrVkGpu* gpu);
30 
31     void releaseResources();
32 
getPrimaryCommandBuffer()33     GrVkPrimaryCommandBuffer* getPrimaryCommandBuffer() { return fPrimaryCommandBuffer.get(); }
34 
35     std::unique_ptr<GrVkSecondaryCommandBuffer> findOrCreateSecondaryCommandBuffer(GrVkGpu* gpu);
36 
37     void recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer);
38 
39     // marks that we are finished with this command pool; it is not legal to continue creating or
40     // writing to command buffers in a closed pool
41     void close();
42 
43     // returns true if close() has not been called
isOpen()44     bool isOpen() const { return fOpen; }
45 
46 #ifdef SK_TRACE_MANAGED_RESOURCES
dumpInfo()47     void dumpInfo() const override {
48         SkDebugf("GrVkCommandPool: %" PRIdPTR " (%d refs)\n",
49                  (intptr_t)fCommandPool, this->getRefCnt());
50     }
51 #endif
52 
53 private:
54     GrVkCommandPool() = delete;
55 
56     GrVkCommandPool(GrVkGpu* gpu, VkCommandPool commandPool, GrVkPrimaryCommandBuffer*);
57 
58     void freeGPUData() const override;
59 
60     bool fOpen = true;
61 
62     VkCommandPool fCommandPool;
63 
64     std::unique_ptr<GrVkPrimaryCommandBuffer> fPrimaryCommandBuffer;
65 
66     // Array of available secondary command buffers that are not in flight
67     SkSTArray<4, std::unique_ptr<GrVkSecondaryCommandBuffer>, true> fAvailableSecondaryBuffers;
68     int fMaxCachedSecondaryCommandBuffers;
69 };
70 
71 #endif
72