1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrVkGpuCommandBuffer_DEFINED 9 #define GrVkGpuCommandBuffer_DEFINED 10 11 #include "GrGpuCommandBuffer.h" 12 13 #include "GrColor.h" 14 #include "GrMesh.h" 15 #include "GrTypes.h" 16 #include "GrVkPipelineState.h" 17 18 class GrVkGpu; 19 class GrVkImage; 20 class GrVkRenderPass; 21 class GrVkRenderTarget; 22 class GrVkSecondaryCommandBuffer; 23 24 class GrVkGpuCommandBuffer : public GrGpuCommandBuffer, private GrMesh::SendToGpuImpl { 25 public: 26 GrVkGpuCommandBuffer(GrVkGpu* gpu, 27 const LoadAndStoreInfo& colorInfo, 28 const LoadAndStoreInfo& stencilInfo); 29 30 ~GrVkGpuCommandBuffer() override; 31 32 void end() override; 33 34 void discard(GrRenderTarget*) override; 35 36 void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload, 37 GrRenderTarget*) override; 38 39 private: 40 // Performs lazy initialization on the first operation seen by the command buffer. 41 void init(GrVkRenderTarget* rt); 42 43 GrGpu* gpu() override; 44 GrRenderTarget* renderTarget() override; 45 46 void onSubmit() override; 47 48 // Bind vertex and index buffers 49 void bindGeometry(const GrPrimitiveProcessor&, 50 const GrBuffer* indexBuffer, 51 const GrBuffer* vertexBuffer, 52 const GrBuffer* instanceBuffer); 53 54 sk_sp<GrVkPipelineState> prepareDrawState(const GrPipeline&, 55 const GrPrimitiveProcessor&, 56 GrPrimitiveType, 57 bool hasDynamicState); 58 59 void onDraw(const GrPipeline& pipeline, 60 const GrPrimitiveProcessor& primProc, 61 const GrMesh mesh[], 62 const GrPipeline::DynamicState[], 63 int meshCount, 64 const SkRect& bounds) override; 65 66 // GrMesh::SendToGpuImpl methods. These issue the actual Vulkan draw commands. 67 // Marked final as a hint to the compiler to not use virtual dispatch. sendMeshToGpu(const GrPrimitiveProcessor & primProc,GrPrimitiveType primType,const GrBuffer * vertexBuffer,int vertexCount,int baseVertex)68 void sendMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primType, 69 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex) final { 70 this->sendInstancedMeshToGpu(primProc, primType, vertexBuffer, vertexCount, baseVertex, 71 nullptr, 1, 0); 72 } 73 sendIndexedMeshToGpu(const GrPrimitiveProcessor & primProc,GrPrimitiveType primType,const GrBuffer * indexBuffer,int indexCount,int baseIndex,uint16_t,uint16_t,const GrBuffer * vertexBuffer,int baseVertex)74 void sendIndexedMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primType, 75 const GrBuffer* indexBuffer, int indexCount, int baseIndex, 76 uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/, 77 const GrBuffer* vertexBuffer, int baseVertex) final { 78 this->sendIndexedInstancedMeshToGpu(primProc, primType, indexBuffer, indexCount, baseIndex, 79 vertexBuffer, baseVertex, nullptr, 1, 0); 80 } 81 82 void sendInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, 83 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex, 84 const GrBuffer* instanceBuffer, int instanceCount, 85 int baseInstance) final; 86 87 void sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, 88 const GrBuffer* indexBuffer, int indexCount, int baseIndex, 89 const GrBuffer* vertexBuffer, int baseVertex, 90 const GrBuffer* instanceBuffer, int instanceCount, 91 int baseInstance) final; 92 93 void onClear(GrRenderTarget*, const GrFixedClip&, GrColor color) override; 94 95 void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) override; 96 97 void addAdditionalCommandBuffer(); 98 void addAdditionalRenderPass(); 99 100 struct InlineUploadInfo { InlineUploadInfoInlineUploadInfo101 InlineUploadInfo(GrOpFlushState* state, const GrDrawOp::DeferredUploadFn& upload) 102 : fFlushState(state), fUpload(upload) {} 103 104 GrOpFlushState* fFlushState; 105 GrDrawOp::DeferredUploadFn fUpload; 106 }; 107 108 struct CommandBufferInfo { 109 const GrVkRenderPass* fRenderPass; 110 SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers; 111 VkClearValue fColorClearValue; 112 SkRect fBounds; 113 bool fIsEmpty; 114 bool fStartsWithClear; 115 SkTArray<InlineUploadInfo> fPreDrawUploads; 116 currentCmdBufCommandBufferInfo117 GrVkSecondaryCommandBuffer* currentCmdBuf() { 118 return fCommandBuffers.back(); 119 } 120 }; 121 122 SkTArray<CommandBufferInfo> fCommandBufferInfos; 123 int fCurrentCmdInfo; 124 125 GrVkGpu* fGpu; 126 GrVkRenderTarget* fRenderTarget; 127 VkAttachmentLoadOp fVkColorLoadOp; 128 VkAttachmentStoreOp fVkColorStoreOp; 129 VkAttachmentLoadOp fVkStencilLoadOp; 130 VkAttachmentStoreOp fVkStencilStoreOp; 131 GrColor4f fClearColor; 132 GrVkPipelineState* fLastPipelineState; 133 134 typedef GrGpuCommandBuffer INHERITED; 135 }; 136 137 #endif 138