| 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 GrVkPipeline; | 17 class GrVkPipeline; |
| 17 class GrVkRenderPass; | 18 class GrVkRenderPass; |
| 18 class GrVkRenderTarget; | 19 class GrVkRenderTarget; |
| 19 class GrVkTransferBuffer; | 20 class GrVkTransferBuffer; |
| 20 | 21 |
| 21 class GrVkCommandBuffer : public GrVkResource { | 22 class GrVkCommandBuffer : public GrVkResource { |
| 22 public: | 23 public: |
| 23 static GrVkCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cmdPool); | |
| 24 ~GrVkCommandBuffer() override; | 24 ~GrVkCommandBuffer() override; |
| 25 | 25 |
| 26 void begin(const GrVkGpu* gpu); | |
| 27 void end(const GrVkGpu* gpu); | |
| 28 | |
| 29 void invalidateState(); | 26 void invalidateState(); |
| 30 | 27 |
| 31 // Begins render pass on this command buffer. The framebuffer from GrVkRende
rTarget will be used | |
| 32 // in the render pass. | |
| 33 void beginRenderPass(const GrVkGpu* gpu, | |
| 34 const GrVkRenderPass* renderPass, | |
| 35 const GrVkRenderTarget& target); | |
| 36 void endRenderPass(const GrVkGpu* gpu); | |
| 37 | |
| 38 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); | |
| 39 bool finished(const GrVkGpu* gpu) const; | |
| 40 | |
| 41 //////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////// |
| 42 // CommandBuffer commands | 29 // CommandBuffer commands |
| 43 //////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////// |
| 44 enum BarrierType { | 31 enum BarrierType { |
| 45 kMemory_BarrierType, | 32 kMemory_BarrierType, |
| 46 kBufferMemory_BarrierType, | 33 kBufferMemory_BarrierType, |
| 47 kImageMemory_BarrierType | 34 kImageMemory_BarrierType |
| 48 }; | 35 }; |
| 49 | 36 |
| 50 void pipelineBarrier(const GrVkGpu* gpu, | 37 void pipelineBarrier(const GrVkGpu* gpu, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 uint32_t viewportCount, | 85 uint32_t viewportCount, |
| 99 const VkViewport* viewports); | 86 const VkViewport* viewports); |
| 100 | 87 |
| 101 void setScissor(const GrVkGpu* gpu, | 88 void setScissor(const GrVkGpu* gpu, |
| 102 uint32_t firstScissor, | 89 uint32_t firstScissor, |
| 103 uint32_t scissorCount, | 90 uint32_t scissorCount, |
| 104 const VkRect2D* scissors); | 91 const VkRect2D* scissors); |
| 105 | 92 |
| 106 void setBlendConstants(const GrVkGpu* gpu, const float blendConstants[4]); | 93 void setBlendConstants(const GrVkGpu* gpu, const float blendConstants[4]); |
| 107 | 94 |
| 95 // Commands that only work inside of a render pass |
| 96 void clearAttachments(const GrVkGpu* gpu, |
| 97 int numAttachments, |
| 98 const VkClearAttachment* attachments, |
| 99 int numRects, |
| 100 const VkClearRect* clearRects) const; |
| 101 |
| 102 void drawIndexed(const GrVkGpu* gpu, |
| 103 uint32_t indexCount, |
| 104 uint32_t instanceCount, |
| 105 uint32_t firstIndex, |
| 106 int32_t vertexOffset, |
| 107 uint32_t firstInstance) const; |
| 108 |
| 109 void draw(const GrVkGpu* gpu, |
| 110 uint32_t vertexCount, |
| 111 uint32_t instanceCount, |
| 112 uint32_t firstVertex, |
| 113 uint32_t firstInstance) const; |
| 114 |
| 115 // Add ref-counted resource that will be tracked and released when this |
| 116 // command buffer finishes execution |
| 117 void addResource(const GrVkResource* resource) { |
| 118 resource->ref(); |
| 119 fTrackedResources.push_back(resource); |
| 120 } |
| 121 |
| 122 protected: |
| 123 GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp =
VK_NULL_HANDLE) |
| 124 : fTrackedResources(kInitialTrackedResourcesCount) |
| 125 , fIsActive(false) |
| 126 , fActiveRenderPass(rp) |
| 127 , fCmdBuffer(cmdBuffer) |
| 128 , fSubmitFence(VK_NULL_HANDLE) |
| 129 , fBoundVertexBufferIsValid(false) |
| 130 , fBoundIndexBufferIsValid(false) { |
| 131 this->invalidateState(); |
| 132 } |
| 133 SkTArray<const GrVkResource*, true> fTrackedResources; |
| 134 |
| 135 // 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; |
| 137 bool fIsActive; |
| 138 |
| 139 // 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 |
| 141 // the render pass. |
| 142 const GrVkRenderPass* fActiveRenderPass; |
| 143 |
| 144 VkCommandBuffer fCmdBuffer; |
| 145 VkFence fSubmitFence; |
| 146 |
| 147 private: |
| 148 static const int kInitialTrackedResourcesCount = 32; |
| 149 |
| 150 void freeGPUData(const GrVkGpu* gpu) const override; |
| 151 void abandonSubResources() const override; |
| 152 |
| 153 VkBuffer fBoundVertexBuffer; |
| 154 bool fBoundVertexBufferIsValid; |
| 155 |
| 156 VkBuffer fBoundIndexBuffer; |
| 157 bool fBoundIndexBufferIsValid; |
| 158 |
| 159 // Cached values used for dynamic state updates |
| 160 VkViewport fCachedViewport; |
| 161 VkRect2D fCachedScissor; |
| 162 float fCachedBlendConstant[4]; |
| 163 }; |
| 164 |
| 165 class GrVkSecondaryCommandBuffer; |
| 166 |
| 167 class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer { |
| 168 public: |
| 169 static GrVkPrimaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cm
dPool); |
| 170 |
| 171 void begin(const GrVkGpu* gpu); |
| 172 void end(const GrVkGpu* gpu); |
| 173 |
| 174 // Begins render pass on this command buffer. The framebuffer from GrVkRende
rTarget will be used |
| 175 // in the render pass. |
| 176 void beginRenderPass(const GrVkGpu* gpu, |
| 177 const GrVkRenderPass* renderPass, |
| 178 const GrVkRenderTarget& target); |
| 179 void endRenderPass(const GrVkGpu* gpu); |
| 180 |
| 181 // 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 // SecondaryCommandBuffer. |
| 184 void executeCommands(const GrVkGpu* gpu, |
| 185 const GrVkSecondaryCommandBuffer* secondaryBuffer); |
| 186 |
| 108 // Commands that only work outside of a render pass | 187 // Commands that only work outside of a render pass |
| 109 void clearColorImage(const GrVkGpu* gpu, | 188 void clearColorImage(const GrVkGpu* gpu, |
| 110 GrVkImage* image, | 189 GrVkImage* image, |
| 111 const VkClearColorValue* color, | 190 const VkClearColorValue* color, |
| 112 uint32_t subRangeCount, | 191 uint32_t subRangeCount, |
| 113 const VkImageSubresourceRange* subRanges); | 192 const VkImageSubresourceRange* subRanges); |
| 114 | 193 |
| 115 void clearDepthStencilImage(const GrVkGpu* gpu, | 194 void clearDepthStencilImage(const GrVkGpu* gpu, |
| 116 GrVkImage* image, | 195 GrVkImage* image, |
| 117 const VkClearDepthStencilValue* color, | 196 const VkClearDepthStencilValue* color, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 uint32_t copyRegionCount, | 241 uint32_t copyRegionCount, |
| 163 const VkBufferImageCopy* copyRegions); | 242 const VkBufferImageCopy* copyRegions); |
| 164 | 243 |
| 165 void copyBufferToImage(const GrVkGpu* gpu, | 244 void copyBufferToImage(const GrVkGpu* gpu, |
| 166 GrVkTransferBuffer* srcBuffer, | 245 GrVkTransferBuffer* srcBuffer, |
| 167 GrVkImage* dstImage, | 246 GrVkImage* dstImage, |
| 168 VkImageLayout dstLayout, | 247 VkImageLayout dstLayout, |
| 169 uint32_t copyRegionCount, | 248 uint32_t copyRegionCount, |
| 170 const VkBufferImageCopy* copyRegions); | 249 const VkBufferImageCopy* copyRegions); |
| 171 | 250 |
| 172 // Commands that only work inside of a render pass | 251 void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue syn
c); |
| 173 void clearAttachments(const GrVkGpu* gpu, | 252 bool finished(const GrVkGpu* gpu) const; |
| 174 int numAttachments, | |
| 175 const VkClearAttachment* attachments, | |
| 176 int numRects, | |
| 177 const VkClearRect* clearRects) const; | |
| 178 | 253 |
| 179 void drawIndexed(const GrVkGpu* gpu, | 254 private: |
| 180 uint32_t indexCount, | 255 explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) : INHERITED(cmd
Buffer) {} |
| 181 uint32_t instanceCount, | |
| 182 uint32_t firstIndex, | |
| 183 int32_t vertexOffset, | |
| 184 uint32_t firstInstance) const; | |
| 185 | 256 |
| 186 void draw(const GrVkGpu* gpu, | 257 typedef GrVkCommandBuffer INHERITED; |
| 187 uint32_t vertexCount, | 258 }; |
| 188 uint32_t instanceCount, | |
| 189 uint32_t firstVertex, | |
| 190 uint32_t firstInstance) const; | |
| 191 | 259 |
| 192 // Add ref-counted resource that will be tracked and released when this | 260 class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { |
| 193 // command buffer finishes execution | 261 public: |
| 194 void addResource(const GrVkResource* resource) { | 262 static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool
cmdPool, |
| 195 resource->ref(); | 263 const GrVkRenderPass* compatibleRe
nderPass); |
| 196 fTrackedResources.push_back(resource); | 264 |
| 265 void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer); |
| 266 void end(const GrVkGpu* gpu); |
| 267 |
| 268 private: |
| 269 explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, |
| 270 const GrVkRenderPass* compatibleRenderPa
ss) |
| 271 : INHERITED(cmdBuffer, compatibleRenderPass) { |
| 197 } | 272 } |
| 198 | 273 |
| 199 private: | 274 friend class GrVkPrimaryCommandBuffer; |
| 200 static const int kInitialTrackedResourcesCount = 32; | |
| 201 | 275 |
| 202 explicit GrVkCommandBuffer(VkCommandBuffer cmdBuffer) | 276 typedef GrVkCommandBuffer INHERITED; |
| 203 : fTrackedResources(kInitialTrackedResourcesCount) | |
| 204 , fCmdBuffer(cmdBuffer) | |
| 205 , fSubmitFence(VK_NULL_HANDLE) | |
| 206 , fBoundVertexBufferIsValid(false) | |
| 207 , fBoundIndexBufferIsValid(false) | |
| 208 , fIsActive(false) | |
| 209 , fActiveRenderPass(nullptr) { | |
| 210 this->invalidateState(); | |
| 211 } | |
| 212 | |
| 213 void freeGPUData(const GrVkGpu* gpu) const override; | |
| 214 void abandonSubResources() const override; | |
| 215 | |
| 216 SkTArray<const GrVkResource*, true> fTrackedResources; | |
| 217 | |
| 218 VkCommandBuffer fCmdBuffer; | |
| 219 VkFence fSubmitFence; | |
| 220 | |
| 221 VkBuffer fBoundVertexBuffer; | |
| 222 bool fBoundVertexBufferIsValid; | |
| 223 | |
| 224 VkBuffer fBoundIndexBuffer; | |
| 225 bool fBoundIndexBufferIsValid; | |
| 226 | |
| 227 // Tracks whether we are in the middle of a command buffer begin/end calls a
nd thus can add new | |
| 228 // commands to the buffer; | |
| 229 bool fIsActive; | |
| 230 | |
| 231 // Stores a pointer to the current active render pass (i.e. begin has been c
alled but not end). | |
| 232 // A nullptr means there is no active render pass. The GrVKCommandBuffer doe
s not own the render | |
| 233 // pass. | |
| 234 const GrVkRenderPass* fActiveRenderPass; | |
| 235 | |
| 236 // Cached values used for dynamic state updates | |
| 237 VkViewport fCachedViewport; | |
| 238 VkRect2D fCachedScissor; | |
| 239 float fCachedBlendConstant[4]; | |
| 240 }; | 277 }; |
| 241 | 278 |
| 242 | |
| 243 #endif | 279 #endif |
| OLD | NEW |