| 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 |
| 11 #include "GrVkGpu.h" | 11 #include "GrVkGpu.h" |
| 12 #include "GrVkResource.h" | 12 #include "GrVkResource.h" |
| 13 #include "GrVkUtil.h" | 13 #include "GrVkUtil.h" |
| 14 #include "vk/GrVkDefines.h" | 14 #include "vk/GrVkDefines.h" |
| 15 | 15 |
| 16 class GrVkFramebuffer; | 16 class GrVkFramebuffer; |
| 17 class GrVkPipeline; | 17 class GrVkPipeline; |
| 18 class GrVkRenderPass; | 18 class GrVkRenderPass; |
| 19 class GrVkRenderTarget; | 19 class GrVkRenderTarget; |
| 20 class GrVkTransferBuffer; | 20 class GrVkTransferBuffer; |
| 21 | 21 |
| 22 class GrVkCommandBuffer : public GrVkResource { | 22 class GrVkCommandBuffer : public GrVkResource { |
| 23 public: | 23 public: |
| 24 ~GrVkCommandBuffer() override; | |
| 25 | |
| 26 void invalidateState(); | 24 void invalidateState(); |
| 27 | 25 |
| 28 //////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////// |
| 29 // CommandBuffer commands | 27 // CommandBuffer commands |
| 30 //////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////// |
| 31 enum BarrierType { | 29 enum BarrierType { |
| 32 kMemory_BarrierType, | 30 kMemory_BarrierType, |
| 33 kBufferMemory_BarrierType, | 31 kBufferMemory_BarrierType, |
| 34 kImageMemory_BarrierType | 32 kImageMemory_BarrierType |
| 35 }; | 33 }; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 resource->ref(); | 116 resource->ref(); |
| 119 fTrackedResources.push_back(resource); | 117 fTrackedResources.push_back(resource); |
| 120 } | 118 } |
| 121 | 119 |
| 122 protected: | 120 protected: |
| 123 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) | 121 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) |
| 124 : fTrackedResources(kInitialTrackedResourcesCount) | 122 : fTrackedResources(kInitialTrackedResourcesCount) |
| 125 , fIsActive(false) | 123 , fIsActive(false) |
| 126 , fActiveRenderPass(rp) | 124 , fActiveRenderPass(rp) |
| 127 , fCmdBuffer(cmdBuffer) | 125 , fCmdBuffer(cmdBuffer) |
| 128 , fSubmitFence(VK_NULL_HANDLE) | |
| 129 , fBoundVertexBufferIsValid(false) | 126 , fBoundVertexBufferIsValid(false) |
| 130 , fBoundIndexBufferIsValid(false) { | 127 , fBoundIndexBufferIsValid(false) { |
| 131 this->invalidateState(); | 128 this->invalidateState(); |
| 132 } | 129 } |
| 133 SkTArray<const GrVkResource*, true> fTrackedResources; | 130 SkTArray<const GrVkResource*, true> fTrackedResources; |
| 134 | 131 |
| 135 // Tracks whether we are in the middle of a command buffer begin/end cal
ls and thus can add | 132 // Tracks whether we are in the middle of a command buffer begin/end cal
ls and thus can add |
| 136 // new commands to the buffer; | 133 // new commands to the buffer; |
| 137 bool fIsActive; | 134 bool fIsActive; |
| 138 | 135 |
| 139 // Stores a pointer to the current active render pass (i.e. begin has be
en called but not | 136 // Stores a pointer to the current active render pass (i.e. begin has be
en called but not |
| 140 // end). A nullptr means there is no active render pass. The GrVKCommand
Buffer does not own | 137 // end). A nullptr means there is no active render pass. The GrVKCommand
Buffer does not own |
| 141 // the render pass. | 138 // the render pass. |
| 142 const GrVkRenderPass* fActiveRenderPass; | 139 const GrVkRenderPass* fActiveRenderPass; |
| 143 | 140 |
| 144 VkCommandBuffer fCmdBuffer; | 141 VkCommandBuffer fCmdBuffer; |
| 145 VkFence fSubmitFence; | |
| 146 | 142 |
| 147 private: | 143 private: |
| 148 static const int kInitialTrackedResourcesCount = 32; | 144 static const int kInitialTrackedResourcesCount = 32; |
| 149 | 145 |
| 150 void freeGPUData(const GrVkGpu* gpu) const override; | 146 void freeGPUData(const GrVkGpu* gpu) const override; |
| 147 virtual void onFreeGPUData(const GrVkGpu* gpu) const = 0; |
| 151 void abandonSubResources() const override; | 148 void abandonSubResources() const override; |
| 152 | 149 |
| 153 VkBuffer fBoundVertexBuffer; | 150 VkBuffer fBoundVertexBuffer; |
| 154 bool fBoundVertexBufferIsValid; | 151 bool fBoundVertexBufferIsValid; |
| 155 | 152 |
| 156 VkBuffer fBoundIndexBuffer; | 153 VkBuffer fBoundIndexBuffer; |
| 157 bool fBoundIndexBufferIsValid; | 154 bool fBoundIndexBufferIsValid; |
| 158 | 155 |
| 159 // Cached values used for dynamic state updates | 156 // Cached values used for dynamic state updates |
| 160 VkViewport fCachedViewport; | 157 VkViewport fCachedViewport; |
| 161 VkRect2D fCachedScissor; | 158 VkRect2D fCachedScissor; |
| 162 float fCachedBlendConstant[4]; | 159 float fCachedBlendConstant[4]; |
| 163 }; | 160 }; |
| 164 | 161 |
| 165 class GrVkSecondaryCommandBuffer; | 162 class GrVkSecondaryCommandBuffer; |
| 166 | 163 |
| 167 class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer { | 164 class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer { |
| 168 public: | 165 public: |
| 166 ~GrVkPrimaryCommandBuffer() override; |
| 167 |
| 169 static GrVkPrimaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cm
dPool); | 168 static GrVkPrimaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cm
dPool); |
| 170 | 169 |
| 171 void begin(const GrVkGpu* gpu); | 170 void begin(const GrVkGpu* gpu); |
| 172 void end(const GrVkGpu* gpu); | 171 void end(const GrVkGpu* gpu); |
| 173 | 172 |
| 174 // Begins render pass on this command buffer. The framebuffer from GrVkRende
rTarget will be used | 173 // Begins render pass on this command buffer. The framebuffer from GrVkRende
rTarget will be used |
| 175 // in the render pass. | 174 // in the render pass. |
| 176 void beginRenderPass(const GrVkGpu* gpu, | 175 void beginRenderPass(const GrVkGpu* gpu, |
| 177 const GrVkRenderPass* renderPass, | 176 const GrVkRenderPass* renderPass, |
| 178 const GrVkRenderTarget& target); | 177 const GrVkRenderTarget& target, |
| 178 const SkIRect& bounds, |
| 179 bool forSecondaryCB); |
| 179 void endRenderPass(const GrVkGpu* gpu); | 180 void endRenderPass(const GrVkGpu* gpu); |
| 180 | 181 |
| 181 // Submits the SecondaryCommandBuffer into this command buffer. It is requir
ed that we are | 182 // Submits the SecondaryCommandBuffer into this command buffer. It is requir
ed that we are |
| 182 // currently inside a render pass that is compatible with the one used to cr
eate the | 183 // currently inside a render pass that is compatible with the one used to cr
eate the |
| 183 // SecondaryCommandBuffer. | 184 // SecondaryCommandBuffer. |
| 184 void executeCommands(const GrVkGpu* gpu, | 185 void executeCommands(const GrVkGpu* gpu, |
| 185 const GrVkSecondaryCommandBuffer* secondaryBuffer); | 186 const GrVkSecondaryCommandBuffer* secondaryBuffer); |
| 186 | 187 |
| 187 // Commands that only work outside of a render pass | 188 // Commands that only work outside of a render pass |
| 188 void clearColorImage(const GrVkGpu* gpu, | 189 void clearColorImage(const GrVkGpu* gpu, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 GrVkTransferBuffer* srcBuffer, | 246 GrVkTransferBuffer* srcBuffer, |
| 246 GrVkImage* dstImage, | 247 GrVkImage* dstImage, |
| 247 VkImageLayout dstLayout, | 248 VkImageLayout dstLayout, |
| 248 uint32_t copyRegionCount, | 249 uint32_t copyRegionCount, |
| 249 const VkBufferImageCopy* copyRegions); | 250 const VkBufferImageCopy* copyRegions); |
| 250 | 251 |
| 251 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); | 252 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); |
| 252 bool finished(const GrVkGpu* gpu) const; | 253 bool finished(const GrVkGpu* gpu) const; |
| 253 | 254 |
| 254 private: | 255 private: |
| 255 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) : INHERITED(cmd
Buffer) {} | 256 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) |
| 257 : INHERITED(cmdBuffer) |
| 258 , fSubmitFence(VK_NULL_HANDLE) {} |
| 259 |
| 260 void onFreeGPUData(const GrVkGpu* gpu) const override; |
| 261 |
| 262 VkFence fSubmitFence; |
| 256 | 263 |
| 257 typedef GrVkCommandBuffer INHERITED; | 264 typedef GrVkCommandBuffer INHERITED; |
| 258 }; | 265 }; |
| 259 | 266 |
| 260 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { | 267 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { |
| 261 public: | 268 public: |
| 262 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool, | 269 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool, |
| 263 const GrVkRenderPass* compatibleRe
nderPass); | 270 const GrVkRenderPass* compatibleRe
nderPass); |
| 264 | 271 |
| 265 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer); | 272 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer); |
| 266 void end(const GrVkGpu* gpu); | 273 void end(const GrVkGpu* gpu); |
| 267 | 274 |
| 268 private: | 275 private: |
| 269 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, | 276 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, |
| 270 const GrVkRenderPass* compatibleRenderPa
ss) | 277 const GrVkRenderPass* compatibleRenderPa
ss) |
| 271 : INHERITED(cmdBuffer, compatibleRenderPass) { | 278 : INHERITED(cmdBuffer, compatibleRenderPass) { |
| 272 } | 279 } |
| 273 | 280 |
| 281 void onFreeGPUData(const GrVkGpu* gpu) const override {} |
| 282 |
| 274 friend class GrVkPrimaryCommandBuffer; | 283 friend class GrVkPrimaryCommandBuffer; |
| 275 | 284 |
| 276 typedef GrVkCommandBuffer INHERITED; | 285 typedef GrVkCommandBuffer INHERITED; |
| 277 }; | 286 }; |
| 278 | 287 |
| 279 #endif | 288 #endif |
| OLD | NEW |