blob: f65acfca9e38d595322c5050783c7a53f0e695da [file] [log] [blame]
Ethan Nicholas8e265a72018-12-12 16:22:40 -05001/*
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 "GrVkGpuCommandBuffer.h"
12#include "GrVkInterface.h"
13#include "GrVkResource.h"
14#include "GrVkResourceProvider.h"
15
16class GrVkPrimaryCommandBuffer;
17class GrVkSecondaryCommandBuffer;
18class GrVkGpu;
19
20class GrVkCommandPool : public GrVkResource {
21public:
22 static GrVkCommandPool* Create(const GrVkGpu* gpu);
23
24 VkCommandPool vkCommandPool() const {
25 return fCommandPool;
26 }
27
28 void reset(GrVkGpu* gpu);
29
30 void releaseResources(GrVkGpu* gpu);
31
32 GrVkPrimaryCommandBuffer* getPrimaryCommandBuffer() { return fPrimaryCommandBuffer; }
33
34 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
43 bool isOpen() const { return fOpen; }
44
45#ifdef SK_DEBUG
46 void dumpInfo() const override {
47 SkDebugf("GrVkCommandPool: %p (%d refs)\n", fCommandPool, this->getRefCnt());
48 }
49#endif
50
51private:
52 GrVkCommandPool() = delete;
53
54 GrVkCommandPool(const GrVkGpu* gpu, VkCommandPool commandPool);
55
56 void abandonGPUData() const override;
57
58 void freeGPUData(GrVkGpu* gpu) const override;
59
60 bool fOpen = true;
61
62 VkCommandPool fCommandPool;
63
64 GrVkPrimaryCommandBuffer* fPrimaryCommandBuffer;
65
66 // Array of available secondary command buffers that are not in flight
67 SkSTArray<4, GrVkSecondaryCommandBuffer*, true> fAvailableSecondaryBuffers;
68};
69
70#endif