• 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 
getPrimaryCommandBuffer()32     GrVkPrimaryCommandBuffer* getPrimaryCommandBuffer() { return fPrimaryCommandBuffer.get(); }
33 
34     std::unique_ptr<GrVkSecondaryCommandBuffer> findOrCreateSecondaryCommandBuffer(GrVkGpu* gpu);
35 
36     void recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer);
37 
38     // marks that we are finished with this command pool; it is not legal to continue creating or
39     // writing to command buffers in a closed pool
40     void close();
41 
42     // returns true if close() has not been called
isOpen()43     bool isOpen() const { return fOpen; }
44 
45 #ifdef SK_TRACE_MANAGED_RESOURCES
dumpInfo()46     void dumpInfo() const override {
47         SkDebugf("GrVkCommandPool: %" PRIdPTR " (%d refs)\n",
48                  (intptr_t)fCommandPool, this->getRefCnt());
49     }
50 #endif
51 
52 private:
53     GrVkCommandPool() = delete;
54 
55     GrVkCommandPool(GrVkGpu* gpu, VkCommandPool commandPool, GrVkPrimaryCommandBuffer*);
56 
57     void releaseResources();
58 
59     void freeGPUData() const override;
60 
61     bool fOpen = true;
62 
63     VkCommandPool fCommandPool;
64 
65     std::unique_ptr<GrVkPrimaryCommandBuffer> fPrimaryCommandBuffer;
66 
67     // Array of available secondary command buffers that are not in flight
68     SkSTArray<4, std::unique_ptr<GrVkSecondaryCommandBuffer>, true> fAvailableSecondaryBuffers;
69     int fMaxCachedSecondaryCommandBuffers;
70 };
71 
72 #endif
73