blob: fd44d62e9443f3774bdb712441bffb4b95ab5839 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/vk/GrVkInterface.h"
12#include "src/gpu/vk/GrVkResource.h"
13#include "src/gpu/vk/GrVkResourceProvider.h"
Ethan Nicholas8e265a72018-12-12 16:22:40 -050014
15class GrVkPrimaryCommandBuffer;
16class GrVkSecondaryCommandBuffer;
17class GrVkGpu;
18
19class GrVkCommandPool : public GrVkResource {
20public:
21 static GrVkCommandPool* Create(const GrVkGpu* gpu);
22
23 VkCommandPool vkCommandPool() const {
24 return fCommandPool;
25 }
26
27 void reset(GrVkGpu* gpu);
28
29 void releaseResources(GrVkGpu* gpu);
30
Greg Daniel8daf3b72019-07-30 09:57:26 -040031 GrVkPrimaryCommandBuffer* getPrimaryCommandBuffer() { return fPrimaryCommandBuffer.get(); }
Ethan Nicholas8e265a72018-12-12 16:22:40 -050032
Greg Daniel8daf3b72019-07-30 09:57:26 -040033 std::unique_ptr<GrVkSecondaryCommandBuffer> findOrCreateSecondaryCommandBuffer(GrVkGpu* gpu);
Ethan Nicholas8e265a72018-12-12 16:22:40 -050034
35 void recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer);
36
37 // marks that we are finished with this command pool; it is not legal to continue creating or
38 // writing to command buffers in a closed pool
39 void close();
40
41 // returns true if close() has not been called
42 bool isOpen() const { return fOpen; }
43
44#ifdef SK_DEBUG
45 void dumpInfo() const override {
46 SkDebugf("GrVkCommandPool: %p (%d refs)\n", fCommandPool, this->getRefCnt());
47 }
48#endif
49
50private:
51 GrVkCommandPool() = delete;
52
53 GrVkCommandPool(const GrVkGpu* gpu, VkCommandPool commandPool);
54
55 void abandonGPUData() const override;
56
57 void freeGPUData(GrVkGpu* gpu) const override;
58
59 bool fOpen = true;
60
61 VkCommandPool fCommandPool;
62
Greg Daniel8daf3b72019-07-30 09:57:26 -040063 std::unique_ptr<GrVkPrimaryCommandBuffer> fPrimaryCommandBuffer;
Ethan Nicholas8e265a72018-12-12 16:22:40 -050064
65 // Array of available secondary command buffers that are not in flight
Greg Daniel8daf3b72019-07-30 09:57:26 -040066 SkSTArray<4, std::unique_ptr<GrVkSecondaryCommandBuffer>, true> fAvailableSecondaryBuffers;
Ethan Nicholas8e265a72018-12-12 16:22:40 -050067};
68
69#endif