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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.push_back(resource); |
118 } | 118 } |
119 | 119 |
| 120 void reset(GrVkGpu* gpu); |
| 121 |
120 protected: | 122 protected: |
121 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) | 123 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) |
122 : fTrackedResources(kInitialTrackedResourcesCount) | 124 : fTrackedResources(kInitialTrackedResourcesCount) |
123 , fIsActive(false) | 125 , fIsActive(false) |
124 , fActiveRenderPass(rp) | 126 , fActiveRenderPass(rp) |
125 , fCmdBuffer(cmdBuffer) | 127 , fCmdBuffer(cmdBuffer) |
126 , fBoundVertexBufferIsValid(false) | 128 , fBoundVertexBufferIsValid(false) |
127 , fBoundIndexBufferIsValid(false) { | 129 , fBoundIndexBufferIsValid(false) { |
128 this->invalidateState(); | 130 this->invalidateState(); |
129 } | 131 } |
(...skipping 10 matching lines...) Expand all Loading... |
140 | 142 |
141 VkCommandBuffer fCmdBuffer; | 143 VkCommandBuffer fCmdBuffer; |
142 | 144 |
143 private: | 145 private: |
144 static const int kInitialTrackedResourcesCount = 32; | 146 static const int kInitialTrackedResourcesCount = 32; |
145 | 147 |
146 void freeGPUData(const GrVkGpu* gpu) const override; | 148 void freeGPUData(const GrVkGpu* gpu) const override; |
147 virtual void onFreeGPUData(const GrVkGpu* gpu) const = 0; | 149 virtual void onFreeGPUData(const GrVkGpu* gpu) const = 0; |
148 void abandonSubResources() const override; | 150 void abandonSubResources() const override; |
149 | 151 |
| 152 virtual void onReset(GrVkGpu* gpu) {} |
| 153 |
150 VkBuffer fBoundVertexBuffer; | 154 VkBuffer fBoundVertexBuffer; |
151 bool fBoundVertexBufferIsValid; | 155 bool fBoundVertexBufferIsValid; |
152 | 156 |
153 VkBuffer fBoundIndexBuffer; | 157 VkBuffer fBoundIndexBuffer; |
154 bool fBoundIndexBufferIsValid; | 158 bool fBoundIndexBufferIsValid; |
155 | 159 |
156 // Cached values used for dynamic state updates | 160 // Cached values used for dynamic state updates |
157 VkViewport fCachedViewport; | 161 VkViewport fCachedViewport; |
158 VkRect2D fCachedScissor; | 162 VkRect2D fCachedScissor; |
159 float fCachedBlendConstant[4]; | 163 float fCachedBlendConstant[4]; |
(...skipping 18 matching lines...) Expand all Loading... |
178 const VkClearValue* clearValues, | 182 const VkClearValue* clearValues, |
179 const GrVkRenderTarget& target, | 183 const GrVkRenderTarget& target, |
180 const SkIRect& bounds, | 184 const SkIRect& bounds, |
181 bool forSecondaryCB); | 185 bool forSecondaryCB); |
182 void endRenderPass(const GrVkGpu* gpu); | 186 void endRenderPass(const GrVkGpu* gpu); |
183 | 187 |
184 // Submits the SecondaryCommandBuffer into this command buffer. It is requir
ed that we are | 188 // Submits the SecondaryCommandBuffer into this command buffer. It is requir
ed that we are |
185 // currently inside a render pass that is compatible with the one used to cr
eate the | 189 // currently inside a render pass that is compatible with the one used to cr
eate the |
186 // SecondaryCommandBuffer. | 190 // SecondaryCommandBuffer. |
187 void executeCommands(const GrVkGpu* gpu, | 191 void executeCommands(const GrVkGpu* gpu, |
188 const GrVkSecondaryCommandBuffer* secondaryBuffer); | 192 GrVkSecondaryCommandBuffer* secondaryBuffer); |
189 | 193 |
190 // Commands that only work outside of a render pass | 194 // Commands that only work outside of a render pass |
191 void clearColorImage(const GrVkGpu* gpu, | 195 void clearColorImage(const GrVkGpu* gpu, |
192 GrVkImage* image, | 196 GrVkImage* image, |
193 const VkClearColorValue* color, | 197 const VkClearColorValue* color, |
194 uint32_t subRangeCount, | 198 uint32_t subRangeCount, |
195 const VkImageSubresourceRange* subRanges); | 199 const VkImageSubresourceRange* subRanges); |
196 | 200 |
197 void clearDepthStencilImage(const GrVkGpu* gpu, | 201 void clearDepthStencilImage(const GrVkGpu* gpu, |
198 GrVkImage* image, | 202 GrVkImage* image, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 257 |
254 void updateBuffer(GrVkGpu* gpu, | 258 void updateBuffer(GrVkGpu* gpu, |
255 GrVkBuffer* dstBuffer, | 259 GrVkBuffer* dstBuffer, |
256 VkDeviceSize dstOffset, | 260 VkDeviceSize dstOffset, |
257 VkDeviceSize dataSize, | 261 VkDeviceSize dataSize, |
258 const void* data); | 262 const void* data); |
259 | 263 |
260 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); | 264 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); |
261 bool finished(const GrVkGpu* gpu) const; | 265 bool finished(const GrVkGpu* gpu) const; |
262 | 266 |
| 267 #ifdef SK_TRACE_VK_RESOURCES |
| 268 void dumpInfo() const override { |
| 269 SkDebugf("GrVkPrimaryCommandBuffer: %d (%d refs)\n", fCmdBuffer, this->g
etRefCnt()); |
| 270 } |
| 271 #endif |
| 272 |
263 private: | 273 private: |
264 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) | 274 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) |
265 : INHERITED(cmdBuffer) | 275 : INHERITED(cmdBuffer) |
266 , fSubmitFence(VK_NULL_HANDLE) {} | 276 , fSubmitFence(VK_NULL_HANDLE) {} |
267 | 277 |
268 void onFreeGPUData(const GrVkGpu* gpu) const override; | 278 void onFreeGPUData(const GrVkGpu* gpu) const override; |
269 | 279 |
270 VkFence fSubmitFence; | 280 void onReset(GrVkGpu* gpu) override; |
| 281 |
| 282 SkTArray<GrVkSecondaryCommandBuffer*, true> fSecondaryCommandBuffers; |
| 283 VkFence fSubmitFence; |
271 | 284 |
272 typedef GrVkCommandBuffer INHERITED; | 285 typedef GrVkCommandBuffer INHERITED; |
273 }; | 286 }; |
274 | 287 |
275 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { | 288 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { |
276 public: | 289 public: |
277 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool, | 290 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool); |
278 const GrVkRenderPass* compatibleRe
nderPass); | |
279 | 291 |
280 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer); | 292 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer, |
| 293 const GrVkRenderPass* compatibleRenderPass); |
281 void end(const GrVkGpu* gpu); | 294 void end(const GrVkGpu* gpu); |
282 | 295 |
| 296 #ifdef SK_TRACE_VK_RESOURCES |
| 297 void dumpInfo() const override { |
| 298 SkDebugf("GrVkSecondaryCommandBuffer: %d (%d refs)\n", fCmdBuffer, this-
>getRefCnt()); |
| 299 } |
| 300 #endif |
| 301 |
283 private: | 302 private: |
284 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, | 303 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer) |
285 const GrVkRenderPass* compatibleRenderPa
ss) | 304 : INHERITED(cmdBuffer) { |
286 : INHERITED(cmdBuffer, compatibleRenderPass) { | |
287 } | 305 } |
288 | 306 |
289 void onFreeGPUData(const GrVkGpu* gpu) const override {} | 307 void onFreeGPUData(const GrVkGpu* gpu) const override {} |
290 | 308 |
291 friend class GrVkPrimaryCommandBuffer; | 309 friend class GrVkPrimaryCommandBuffer; |
292 | 310 |
293 typedef GrVkCommandBuffer INHERITED; | 311 typedef GrVkCommandBuffer INHERITED; |
294 }; | 312 }; |
295 | 313 |
296 #endif | 314 #endif |
OLD | NEW |