| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrVkCommandBuffer_DEFINED | 8 #ifndef GrVkCommandBuffer_DEFINED |
| 9 #define GrVkCommandBuffer_DEFINED | 9 #define GrVkCommandBuffer_DEFINED |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void draw(const GrVkGpu* gpu, | 107 void draw(const GrVkGpu* gpu, |
| 108 uint32_t vertexCount, | 108 uint32_t vertexCount, |
| 109 uint32_t instanceCount, | 109 uint32_t instanceCount, |
| 110 uint32_t firstVertex, | 110 uint32_t firstVertex, |
| 111 uint32_t firstInstance) const; | 111 uint32_t firstInstance) const; |
| 112 | 112 |
| 113 // Add ref-counted resource that will be tracked and released when this | 113 // Add ref-counted resource that will be tracked and released when this |
| 114 // command buffer finishes execution | 114 // command buffer finishes execution |
| 115 void addResource(const GrVkResource* resource) { | 115 void addResource(const GrVkResource* resource) { |
| 116 resource->ref(); | 116 resource->ref(); |
| 117 fTrackedResources.push_back(resource); | 117 fTrackedResources.append(1, &resource); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Add ref-counted resource that will be tracked and released when this comm
and buffer finishes | 120 // Add ref-counted resource that will be tracked and released when this comm
and buffer finishes |
| 121 // execution. When it is released, it will signal that the resource can be r
ecycled for reuse. | 121 // execution. When it is released, it will signal that the resource can be r
ecycled for reuse. |
| 122 void addRecycledResource(const GrVkRecycledResource* resource) { | 122 void addRecycledResource(const GrVkRecycledResource* resource) { |
| 123 resource->ref(); | 123 resource->ref(); |
| 124 fTrackedRecycledResources.push_back(resource); | 124 fTrackedRecycledResources.append(1, &resource); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void reset(GrVkGpu* gpu); | 127 void reset(GrVkGpu* gpu); |
| 128 | 128 |
| 129 protected: | 129 protected: |
| 130 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) | 130 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) |
| 131 : fTrackedResources(kInitialTrackedResourcesCount) | 131 : fIsActive(false) |
| 132 , fTrackedRecycledResources(kInitialTrackedResourcesCount) | |
| 133 , fIsActive(false) | |
| 134 , fActiveRenderPass(rp) | 132 , fActiveRenderPass(rp) |
| 135 , fCmdBuffer(cmdBuffer) | 133 , fCmdBuffer(cmdBuffer) |
| 136 , fBoundVertexBufferIsValid(false) | 134 , fBoundVertexBufferIsValid(false) |
| 137 , fBoundIndexBufferIsValid(false) { | 135 , fBoundIndexBufferIsValid(false) |
| 136 , fNumResets(0) { |
| 137 fTrackedResources.setReserve(kInitialTrackedResourcesCount); |
| 138 fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount); |
| 138 this->invalidateState(); | 139 this->invalidateState(); |
| 139 } | 140 } |
| 140 SkTArray<const GrVkResource*, true> fTrackedResources; | 141 |
| 141 SkTArray<const GrVkRecycledResource*, true> fTrackedRecycledResources; | 142 SkTDArray<const GrVkResource*> fTrackedResources; |
| 143 SkTDArray<const GrVkRecycledResource*> fTrackedRecycledResources; |
| 142 | 144 |
| 143 // Tracks whether we are in the middle of a command buffer begin/end cal
ls and thus can add | 145 // Tracks whether we are in the middle of a command buffer begin/end cal
ls and thus can add |
| 144 // new commands to the buffer; | 146 // new commands to the buffer; |
| 145 bool fIsActive; | 147 bool fIsActive; |
| 146 | 148 |
| 147 // Stores a pointer to the current active render pass (i.e. begin has be
en called but not | 149 // Stores a pointer to the current active render pass (i.e. begin has be
en called but not |
| 148 // end). A nullptr means there is no active render pass. The GrVKCommand
Buffer does not own | 150 // end). A nullptr means there is no active render pass. The GrVKCommand
Buffer does not own |
| 149 // the render pass. | 151 // the render pass. |
| 150 const GrVkRenderPass* fActiveRenderPass; | 152 const GrVkRenderPass* fActiveRenderPass; |
| 151 | 153 |
| 152 VkCommandBuffer fCmdBuffer; | 154 VkCommandBuffer fCmdBuffer; |
| 153 | 155 |
| 154 private: | 156 private: |
| 155 static const int kInitialTrackedResourcesCount = 32; | 157 static const int kInitialTrackedResourcesCount = 32; |
| 156 | 158 |
| 157 void freeGPUData(const GrVkGpu* gpu) const override; | 159 void freeGPUData(const GrVkGpu* gpu) const override; |
| 158 virtual void onFreeGPUData(const GrVkGpu* gpu) const = 0; | 160 virtual void onFreeGPUData(const GrVkGpu* gpu) const = 0; |
| 159 void abandonSubResources() const override; | 161 void abandonSubResources() const override; |
| 160 | 162 |
| 161 virtual void onReset(GrVkGpu* gpu) {} | 163 virtual void onReset(GrVkGpu* gpu) {} |
| 162 | 164 |
| 163 VkBuffer fBoundVertexBuffer; | 165 VkBuffer fBoundVertexBuffer; |
| 164 bool fBoundVertexBufferIsValid; | 166 bool fBoundVertexBufferIsValid; |
| 165 | 167 |
| 166 VkBuffer fBoundIndexBuffer; | 168 VkBuffer fBoundIndexBuffer; |
| 167 bool fBoundIndexBufferIsValid; | 169 bool fBoundIndexBufferIsValid; |
| 168 | 170 |
| 171 // When resetting the command buffer, we remove the tracked resources from t
heir arrays, and |
| 172 // we prefer to not free all the memory every time so usually we just rewind
. However, to avoid |
| 173 // all arrays growing to the max size, after so many resets we'll do a full
reset of the tracked |
| 174 // resource arrays. |
| 175 static const int kNumRewindResetsBeforeFullReset = 8; |
| 176 int fNumResets; |
| 177 |
| 169 // Cached values used for dynamic state updates | 178 // Cached values used for dynamic state updates |
| 170 VkViewport fCachedViewport; | 179 VkViewport fCachedViewport; |
| 171 VkRect2D fCachedScissor; | 180 VkRect2D fCachedScissor; |
| 172 float fCachedBlendConstant[4]; | 181 float fCachedBlendConstant[4]; |
| 173 }; | 182 }; |
| 174 | 183 |
| 175 class GrVkSecondaryCommandBuffer; | 184 class GrVkSecondaryCommandBuffer; |
| 176 | 185 |
| 177 class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer { | 186 class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer { |
| 178 public: | 187 public: |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 329 } |
| 321 | 330 |
| 322 void onFreeGPUData(const GrVkGpu* gpu) const override {} | 331 void onFreeGPUData(const GrVkGpu* gpu) const override {} |
| 323 | 332 |
| 324 friend class GrVkPrimaryCommandBuffer; | 333 friend class GrVkPrimaryCommandBuffer; |
| 325 | 334 |
| 326 typedef GrVkCommandBuffer INHERITED; | 335 typedef GrVkCommandBuffer INHERITED; |
| 327 }; | 336 }; |
| 328 | 337 |
| 329 #endif | 338 #endif |
| OLD | NEW |