Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/vk/GrVkInterface.h" |
| 12 | #include "src/gpu/vk/GrVkResource.h" |
| 13 | #include "src/gpu/vk/GrVkResourceProvider.h" |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 14 | |
| 15 | class GrVkPrimaryCommandBuffer; |
| 16 | class GrVkSecondaryCommandBuffer; |
| 17 | class GrVkGpu; |
| 18 | |
| 19 | class GrVkCommandPool : public GrVkResource { |
| 20 | public: |
| 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 Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 31 | GrVkPrimaryCommandBuffer* getPrimaryCommandBuffer() { return fPrimaryCommandBuffer.get(); } |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 32 | |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 33 | std::unique_ptr<GrVkSecondaryCommandBuffer> findOrCreateSecondaryCommandBuffer(GrVkGpu* gpu); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 34 | |
| 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 | |
| 50 | private: |
| 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 Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 63 | std::unique_ptr<GrVkPrimaryCommandBuffer> fPrimaryCommandBuffer; |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 64 | |
| 65 | // Array of available secondary command buffers that are not in flight |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 66 | SkSTArray<4, std::unique_ptr<GrVkSecondaryCommandBuffer>, true> fAvailableSecondaryBuffers; |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | #endif |