blob: 2aa457bad022265b9c56d4ab8802ae280413276a [file] [log] [blame]
egdaniel066df7c2016-06-08 14:02:27 -07001/*
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"
Chris Dalton114a3c02017-05-26 15:17:19 -060014#include "GrMesh.h"
egdaniel9cb63402016-06-23 08:37:05 -070015#include "GrTypes.h"
16#include "GrVkPipelineState.h"
egdaniel066df7c2016-06-08 14:02:27 -070017
18class GrVkGpu;
egdaniel9cb63402016-06-23 08:37:05 -070019class GrVkImage;
egdaniel066df7c2016-06-08 14:02:27 -070020class GrVkRenderPass;
21class GrVkRenderTarget;
22class GrVkSecondaryCommandBuffer;
23
Greg Daniel500d58b2017-08-24 15:59:33 -040024class GrVkGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
egdaniel066df7c2016-06-08 14:02:27 -070025public:
Greg Daniel500d58b2017-08-24 15:59:33 -040026 GrVkGpuTextureCommandBuffer(GrVkGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin)
27 : INHERITED(texture, origin)
28 , fGpu(gpu) {
29 }
egdaniel066df7c2016-06-08 14:02:27 -070030
Greg Daniel500d58b2017-08-24 15:59:33 -040031 ~GrVkGpuTextureCommandBuffer() override;
32
Robert Phillipsb0e93a22017-08-29 08:26:54 -040033 void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
34 const SkIPoint& dstPoint) override;
Greg Daniel500d58b2017-08-24 15:59:33 -040035
36 void insertEventMarker(const char*) override;
37
38private:
39 void submit() override;
40
41 struct CopyInfo {
Robert Phillipsb0e93a22017-08-29 08:26:54 -040042 CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
43 const SkIPoint& dstPoint)
44 : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {}
Greg Daniel500d58b2017-08-24 15:59:33 -040045
Robert Phillipsb0e93a22017-08-29 08:26:54 -040046 GrSurface* fSrc;
47 GrSurfaceOrigin fSrcOrigin;
48 SkIRect fSrcRect;
49 SkIPoint fDstPoint;
Greg Daniel500d58b2017-08-24 15:59:33 -040050 };
51
52 GrVkGpu* fGpu;
53 SkTArray<CopyInfo> fCopies;
54
55 typedef GrGpuTextureCommandBuffer INHERITED;
56};
57
58class GrVkGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl {
59public:
60 GrVkGpuRTCommandBuffer(GrVkGpu*, GrRenderTarget*, GrSurfaceOrigin,
61 const LoadAndStoreInfo&,
62 const StencilLoadAndStoreInfo&);
63
64 ~GrVkGpuRTCommandBuffer() override;
egdaniel066df7c2016-06-08 14:02:27 -070065
Robert Phillips74c627f2017-08-09 10:28:00 -040066 void begin() override { }
egdaniel066df7c2016-06-08 14:02:27 -070067 void end() override;
68
Robert Phillips19e51dc2017-08-09 09:30:51 -040069 void discard() override;
70 void insertEventMarker(const char*) override;
egdaniel066df7c2016-06-08 14:02:27 -070071
Brian Salomon943ed792017-10-30 09:37:55 -040072 void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
Greg Daniel77b53f62016-10-18 11:48:51 -040073
Robert Phillipsb0e93a22017-08-29 08:26:54 -040074 void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
75 const SkIPoint& dstPoint) override;
Greg Daniel500d58b2017-08-24 15:59:33 -040076
77 void submit() override;
78
egdaniel066df7c2016-06-08 14:02:27 -070079private:
Robert Phillips19e51dc2017-08-09 09:30:51 -040080 void init();
Brian Salomonc293a292016-11-30 13:38:32 -050081
egdaniel9cb63402016-06-23 08:37:05 -070082 GrGpu* gpu() override;
83
egdaniel9cb63402016-06-23 08:37:05 -070084 // Bind vertex and index buffers
Chris Daltonff926502017-05-03 14:36:54 -040085 void bindGeometry(const GrPrimitiveProcessor&,
86 const GrBuffer* indexBuffer,
Chris Dalton1d616352017-05-31 12:51:23 -060087 const GrBuffer* vertexBuffer,
88 const GrBuffer* instanceBuffer);
egdaniel9cb63402016-06-23 08:37:05 -070089
Greg Daniel09eeefb2017-10-16 15:15:02 -040090 GrVkPipelineState* prepareDrawState(const GrPipeline&,
91 const GrPrimitiveProcessor&,
92 GrPrimitiveType,
93 bool hasDynamicState);
egdaniel9cb63402016-06-23 08:37:05 -070094
95 void onDraw(const GrPipeline& pipeline,
96 const GrPrimitiveProcessor& primProc,
Chris Dalton46983b72017-06-06 12:27:16 -060097 const GrMesh mesh[],
98 const GrPipeline::DynamicState[],
Greg Daniel36a77ee2016-10-18 10:33:25 -040099 int meshCount,
100 const SkRect& bounds) override;
egdaniel9cb63402016-06-23 08:37:05 -0700101
Chris Dalton114a3c02017-05-26 15:17:19 -0600102 // GrMesh::SendToGpuImpl methods. These issue the actual Vulkan draw commands.
103 // Marked final as a hint to the compiler to not use virtual dispatch.
Chris Dalton1d616352017-05-31 12:51:23 -0600104 void sendMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primType,
105 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex) final {
106 this->sendInstancedMeshToGpu(primProc, primType, vertexBuffer, vertexCount, baseVertex,
107 nullptr, 1, 0);
108 }
Chris Dalton114a3c02017-05-26 15:17:19 -0600109
Chris Dalton1d616352017-05-31 12:51:23 -0600110 void sendIndexedMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primType,
Chris Dalton114a3c02017-05-26 15:17:19 -0600111 const GrBuffer* indexBuffer, int indexCount, int baseIndex,
Chris Dalton1d616352017-05-31 12:51:23 -0600112 uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/,
113 const GrBuffer* vertexBuffer, int baseVertex) final {
114 this->sendIndexedInstancedMeshToGpu(primProc, primType, indexBuffer, indexCount, baseIndex,
115 vertexBuffer, baseVertex, nullptr, 1, 0);
116 }
117
118 void sendInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType,
119 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex,
120 const GrBuffer* instanceBuffer, int instanceCount,
121 int baseInstance) final;
122
123 void sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType,
124 const GrBuffer* indexBuffer, int indexCount, int baseIndex,
125 const GrBuffer* vertexBuffer, int baseVertex,
126 const GrBuffer* instanceBuffer, int instanceCount,
127 int baseInstance) final;
Chris Dalton114a3c02017-05-26 15:17:19 -0600128
Robert Phillips19e51dc2017-08-09 09:30:51 -0400129 void onClear(const GrFixedClip&, GrColor color) override;
egdaniel9cb63402016-06-23 08:37:05 -0700130
Robert Phillips19e51dc2017-08-09 09:30:51 -0400131 void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override;
egdaniel9cb63402016-06-23 08:37:05 -0700132
Greg Daniel77b53f62016-10-18 11:48:51 -0400133 void addAdditionalCommandBuffer();
Greg Daniel22bc8652017-03-22 15:45:43 -0400134 void addAdditionalRenderPass();
Greg Daniel77b53f62016-10-18 11:48:51 -0400135
136 struct InlineUploadInfo {
Brian Salomon943ed792017-10-30 09:37:55 -0400137 InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload)
138 : fFlushState(state), fUpload(upload) {}
Greg Daniel77b53f62016-10-18 11:48:51 -0400139
Brian Salomon742e31d2016-12-07 17:06:19 -0500140 GrOpFlushState* fFlushState;
Brian Salomon943ed792017-10-30 09:37:55 -0400141 GrDeferredTextureUploadFn fUpload;
Greg Daniel77b53f62016-10-18 11:48:51 -0400142 };
143
Greg Daniel500d58b2017-08-24 15:59:33 -0400144 struct CopyInfo {
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400145 CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
146 const SkIPoint& dstPoint)
147 : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {}
Greg Daniel500d58b2017-08-24 15:59:33 -0400148
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400149 GrSurface* fSrc;
150 GrSurfaceOrigin fSrcOrigin;
151 SkIRect fSrcRect;
152 SkIPoint fDstPoint;
Greg Daniel500d58b2017-08-24 15:59:33 -0400153 };
154
Greg Daniel36a77ee2016-10-18 10:33:25 -0400155 struct CommandBufferInfo {
Greg Daniel22bc8652017-03-22 15:45:43 -0400156 const GrVkRenderPass* fRenderPass;
157 SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers;
158 VkClearValue fColorClearValue;
159 SkRect fBounds;
160 bool fIsEmpty;
161 bool fStartsWithClear;
Greg Daniel500d58b2017-08-24 15:59:33 -0400162 // The PreDrawUploads and PreCopies are sent to the GPU before submitting the secondary
163 // command buffer.
Greg Daniel22bc8652017-03-22 15:45:43 -0400164 SkTArray<InlineUploadInfo> fPreDrawUploads;
Greg Daniel500d58b2017-08-24 15:59:33 -0400165 SkTArray<CopyInfo> fPreCopies;
Greg Daniel22bc8652017-03-22 15:45:43 -0400166
167 GrVkSecondaryCommandBuffer* currentCmdBuf() {
168 return fCommandBuffers.back();
169 }
Greg Daniel36a77ee2016-10-18 10:33:25 -0400170 };
171
172 SkTArray<CommandBufferInfo> fCommandBufferInfos;
Greg Daniel22bc8652017-03-22 15:45:43 -0400173 int fCurrentCmdInfo;
Greg Daniel36a77ee2016-10-18 10:33:25 -0400174
egdaniel066df7c2016-06-08 14:02:27 -0700175 GrVkGpu* fGpu;
Brian Salomonc293a292016-11-30 13:38:32 -0500176 VkAttachmentLoadOp fVkColorLoadOp;
177 VkAttachmentStoreOp fVkColorStoreOp;
178 VkAttachmentLoadOp fVkStencilLoadOp;
179 VkAttachmentStoreOp fVkStencilStoreOp;
180 GrColor4f fClearColor;
Greg Daniel22bc8652017-03-22 15:45:43 -0400181 GrVkPipelineState* fLastPipelineState;
egdaniel9cb63402016-06-23 08:37:05 -0700182
Greg Daniel500d58b2017-08-24 15:59:33 -0400183 typedef GrGpuRTCommandBuffer INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700184};
185
186#endif