| 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 uint32_t clearCount, |
| 178 const VkClearValue* clearValues, |
| 179 const GrVkRenderTarget& target, |
| 180 const SkIRect& bounds, |
| 181 bool forSecondaryCB); |
| 179 void endRenderPass(const GrVkGpu* gpu); | 182 void endRenderPass(const GrVkGpu* gpu); |
| 180 | 183 |
| 181 // Submits the SecondaryCommandBuffer into this command buffer. It is requir
ed that we are | 184 // 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 | 185 // currently inside a render pass that is compatible with the one used to cr
eate the |
| 183 // SecondaryCommandBuffer. | 186 // SecondaryCommandBuffer. |
| 184 void executeCommands(const GrVkGpu* gpu, | 187 void executeCommands(const GrVkGpu* gpu, |
| 185 const GrVkSecondaryCommandBuffer* secondaryBuffer); | 188 const GrVkSecondaryCommandBuffer* secondaryBuffer); |
| 186 | 189 |
| 187 // Commands that only work outside of a render pass | 190 // Commands that only work outside of a render pass |
| 188 void clearColorImage(const GrVkGpu* gpu, | 191 void clearColorImage(const GrVkGpu* gpu, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 GrVkTransferBuffer* srcBuffer, | 248 GrVkTransferBuffer* srcBuffer, |
| 246 GrVkImage* dstImage, | 249 GrVkImage* dstImage, |
| 247 VkImageLayout dstLayout, | 250 VkImageLayout dstLayout, |
| 248 uint32_t copyRegionCount, | 251 uint32_t copyRegionCount, |
| 249 const VkBufferImageCopy* copyRegions); | 252 const VkBufferImageCopy* copyRegions); |
| 250 | 253 |
| 251 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); | 254 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); |
| 252 bool finished(const GrVkGpu* gpu) const; | 255 bool finished(const GrVkGpu* gpu) const; |
| 253 | 256 |
| 254 private: | 257 private: |
| 255 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) : INHERITED(cmd
Buffer) {} | 258 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) |
| 259 : INHERITED(cmdBuffer) |
| 260 , fSubmitFence(VK_NULL_HANDLE) {} |
| 261 |
| 262 void onFreeGPUData(const GrVkGpu* gpu) const override; |
| 263 |
| 264 VkFence fSubmitFence; |
| 256 | 265 |
| 257 typedef GrVkCommandBuffer INHERITED; | 266 typedef GrVkCommandBuffer INHERITED; |
| 258 }; | 267 }; |
| 259 | 268 |
| 260 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { | 269 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { |
| 261 public: | 270 public: |
| 262 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool, | 271 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool, |
| 263 const GrVkRenderPass* compatibleRe
nderPass); | 272 const GrVkRenderPass* compatibleRe
nderPass); |
| 264 | 273 |
| 265 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer); | 274 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer); |
| 266 void end(const GrVkGpu* gpu); | 275 void end(const GrVkGpu* gpu); |
| 267 | 276 |
| 268 private: | 277 private: |
| 269 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, | 278 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, |
| 270 const GrVkRenderPass* compatibleRenderPa
ss) | 279 const GrVkRenderPass* compatibleRenderPa
ss) |
| 271 : INHERITED(cmdBuffer, compatibleRenderPass) { | 280 : INHERITED(cmdBuffer, compatibleRenderPass) { |
| 272 } | 281 } |
| 273 | 282 |
| 283 void onFreeGPUData(const GrVkGpu* gpu) const override {} |
| 284 |
| 274 friend class GrVkPrimaryCommandBuffer; | 285 friend class GrVkPrimaryCommandBuffer; |
| 275 | 286 |
| 276 typedef GrVkCommandBuffer INHERITED; | 287 typedef GrVkCommandBuffer INHERITED; |
| 277 }; | 288 }; |
| 278 | 289 |
| 279 #endif | 290 #endif |
| OLD | NEW |