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 "GrTypes.h" 15 #include "GrVkPipelineState.h" 16 17 class GrNonInstancedMesh; 18 class GrVkGpu; 19 class GrVkImage; 20 class GrVkRenderPass; 21 class GrVkRenderTarget; 22 class GrVkSecondaryCommandBuffer; 23 24 class GrVkGpuCommandBuffer : public GrGpuCommandBuffer { 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&, const GrNonInstancedMesh&); 50 51 sk_sp<GrVkPipelineState> prepareDrawState(const GrPipeline&, 52 const GrPrimitiveProcessor&, 53 GrPrimitiveType); 54 55 void onDraw(const GrPipeline& pipeline, 56 const GrPrimitiveProcessor& primProc, 57 const GrMesh* mesh, 58 int meshCount, 59 const SkRect& bounds) override; 60 61 void onClear(GrRenderTarget*, const GrFixedClip&, GrColor color) override; 62 63 void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) override; 64 65 void addAdditionalCommandBuffer(); 66 void addAdditionalRenderPass(); 67 68 struct InlineUploadInfo { InlineUploadInfoInlineUploadInfo69 InlineUploadInfo(GrOpFlushState* state, const GrDrawOp::DeferredUploadFn& upload) 70 : fFlushState(state), fUpload(upload) {} 71 72 GrOpFlushState* fFlushState; 73 GrDrawOp::DeferredUploadFn fUpload; 74 }; 75 76 struct CommandBufferInfo { 77 const GrVkRenderPass* fRenderPass; 78 SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers; 79 VkClearValue fColorClearValue; 80 SkRect fBounds; 81 bool fIsEmpty; 82 bool fStartsWithClear; 83 SkTArray<InlineUploadInfo> fPreDrawUploads; 84 currentCmdBufCommandBufferInfo85 GrVkSecondaryCommandBuffer* currentCmdBuf() { 86 return fCommandBuffers.back(); 87 } 88 }; 89 90 SkTArray<CommandBufferInfo> fCommandBufferInfos; 91 int fCurrentCmdInfo; 92 93 GrVkGpu* fGpu; 94 GrVkRenderTarget* fRenderTarget; 95 VkAttachmentLoadOp fVkColorLoadOp; 96 VkAttachmentStoreOp fVkColorStoreOp; 97 VkAttachmentLoadOp fVkStencilLoadOp; 98 VkAttachmentStoreOp fVkStencilStoreOp; 99 GrColor4f fClearColor; 100 GrVkPipelineState* fLastPipelineState; 101 102 typedef GrGpuCommandBuffer INHERITED; 103 }; 104 105 #endif 106