blob: c1b44b4f530be161403db33dda9d15a6261e6145 [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 GrGpuCommandBuffer_DEFINED
9#define GrGpuCommandBuffer_DEFINED
10
11#include "GrColor.h"
Chris Dalton46983b72017-06-06 12:27:16 -060012#include "GrPipeline.h"
Brian Salomon89527432016-12-16 09:52:16 -050013#include "ops/GrDrawOp.h"
egdaniel066df7c2016-06-08 14:02:27 -070014
Brian Salomon742e31d2016-12-07 17:06:19 -050015class GrOpFlushState;
csmartdalton29df7602016-08-31 11:55:52 -070016class GrFixedClip;
egdaniel9cb63402016-06-23 08:37:05 -070017class GrGpu;
Chris Daltonbca46e22017-05-15 11:03:26 -060018class GrMesh;
egdaniel9cb63402016-06-23 08:37:05 -070019class GrPipeline;
20class GrPrimitiveProcessor;
egdaniel066df7c2016-06-08 14:02:27 -070021class GrRenderTarget;
egdaniel9cb63402016-06-23 08:37:05 -070022struct SkIRect;
Greg Daniel36a77ee2016-10-18 10:33:25 -040023struct SkRect;
egdaniel066df7c2016-06-08 14:02:27 -070024
Greg Daniel500d58b2017-08-24 15:59:33 -040025class GrGpuRTCommandBuffer;
26
27class GrGpuCommandBuffer {
28public:
29 virtual ~GrGpuCommandBuffer() {}
30
31 // Copy src into current surface owned by either a GrGpuTextureCommandBuffer or
32 // GrGpuRenderTargetCommandBuffer.
Robert Phillipsb0e93a22017-08-29 08:26:54 -040033 virtual void copy(GrSurface* src, GrSurfaceOrigin srcOrigin,
34 const SkIRect& srcRect, const SkIPoint& dstPoint) = 0;
Greg Daniel500d58b2017-08-24 15:59:33 -040035
36 virtual void insertEventMarker(const char*) = 0;
37
38 virtual GrGpuRTCommandBuffer* asRTCommandBuffer() { return nullptr; }
Greg Daniel500d58b2017-08-24 15:59:33 -040039};
40
41class GrGpuTextureCommandBuffer : public GrGpuCommandBuffer{
42public:
Robert Phillips5b5d84c2018-08-09 15:12:18 -040043 void set(GrTexture* texture, GrSurfaceOrigin origin) {
44 SkASSERT(!fTexture);
Greg Daniel500d58b2017-08-24 15:59:33 -040045
Robert Phillips5b5d84c2018-08-09 15:12:18 -040046 fOrigin = origin;
47 fTexture = texture;
48 }
Greg Daniel500d58b2017-08-24 15:59:33 -040049
50protected:
Robert Phillips5b5d84c2018-08-09 15:12:18 -040051 GrGpuTextureCommandBuffer() : fOrigin(kTopLeft_GrSurfaceOrigin), fTexture(nullptr) {}
Greg Daniel500d58b2017-08-24 15:59:33 -040052
Robert Phillips5b5d84c2018-08-09 15:12:18 -040053 GrGpuTextureCommandBuffer(GrTexture* texture, GrSurfaceOrigin origin)
54 : fOrigin(origin)
55 , fTexture(texture) {
56 }
57
58 GrSurfaceOrigin fOrigin;
59 GrTexture* fTexture;
Greg Daniel500d58b2017-08-24 15:59:33 -040060
61private:
62 typedef GrGpuCommandBuffer INHERITED;
63};
64
egdaniel9cb63402016-06-23 08:37:05 -070065/**
Greg Daniel500d58b2017-08-24 15:59:33 -040066 * The GrGpuRenderTargetCommandBuffer is a series of commands (draws, clears, and discards), which
67 * all target the same render target. It is possible that these commands execute immediately (GL),
68 * or get buffered up for later execution (Vulkan). GrOps will execute their draw commands into a
egdaniel9cb63402016-06-23 08:37:05 -070069 * GrGpuCommandBuffer.
70 */
Greg Daniel500d58b2017-08-24 15:59:33 -040071class GrGpuRTCommandBuffer : public GrGpuCommandBuffer {
egdaniel066df7c2016-06-08 14:02:27 -070072public:
egdaniel9cb63402016-06-23 08:37:05 -070073 struct LoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040074 GrLoadOp fLoadOp;
75 GrStoreOp fStoreOp;
76 GrColor fClearColor;
egdaniel066df7c2016-06-08 14:02:27 -070077 };
78
Robert Phillips95214472017-08-08 18:00:03 -040079 // Load-time clears of the stencil buffer are always to 0 so we don't store
80 // an 'fStencilClearValue'
81 struct StencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040082 GrLoadOp fLoadOp;
83 GrStoreOp fStoreOp;
Robert Phillips95214472017-08-08 18:00:03 -040084 };
85
Greg Daniel500d58b2017-08-24 15:59:33 -040086 GrGpuRTCommandBuffer* asRTCommandBuffer() { return this; }
egdaniel066df7c2016-06-08 14:02:27 -070087
Robert Phillips95214472017-08-08 18:00:03 -040088 virtual void begin() = 0;
egdaniel066df7c2016-06-08 14:02:27 -070089 // Signals the end of recording to the command buffer and that it can now be submitted.
90 virtual void end() = 0;
91
egdaniel9cb63402016-06-23 08:37:05 -070092 // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each
93 // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and
94 // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g.
95 // number of vertex attributes is too large).
Brian Salomonff168d92018-06-23 15:17:27 -040096 bool draw(const GrPrimitiveProcessor&,
97 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -040098 const GrPipeline::FixedDynamicState*,
99 const GrPipeline::DynamicStateArrays*,
Chris Daltonbca46e22017-05-15 11:03:26 -0600100 const GrMesh[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400101 int meshCount,
102 const SkRect& bounds);
egdaniel9cb63402016-06-23 08:37:05 -0700103
Greg Daniel77b53f62016-10-18 11:48:51 -0400104 // Performs an upload of vertex data in the middle of a set of a set of draws
Brian Salomon943ed792017-10-30 09:37:55 -0400105 virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
Greg Daniel77b53f62016-10-18 11:48:51 -0400106
egdaniel9cb63402016-06-23 08:37:05 -0700107 /**
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000108 * Clear the owned render target. Ignores the draw state and clip.
Greg Daniel77b53f62016-10-18 11:48:51 -0400109 */
Robert Phillips19e51dc2017-08-09 09:30:51 -0400110 void clear(const GrFixedClip&, GrColor);
egdaniel9cb63402016-06-23 08:37:05 -0700111
Robert Phillips19e51dc2017-08-09 09:30:51 -0400112 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
Greg Daniel36a77ee2016-10-18 10:33:25 -0400113
egdaniel9cb63402016-06-23 08:37:05 -0700114 /**
Robert Phillips19e51dc2017-08-09 09:30:51 -0400115 * Discards the contents render target.
Greg Daniel77b53f62016-10-18 11:48:51 -0400116 */
egdaniel9cb63402016-06-23 08:37:05 -0700117 // TODO: This should be removed in the future to favor using the load and store ops for discard
Robert Phillips19e51dc2017-08-09 09:30:51 -0400118 virtual void discard() = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700119
Robert Phillips19e51dc2017-08-09 09:30:51 -0400120protected:
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400121 GrGpuRTCommandBuffer() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {}
122
Greg Daniel500d58b2017-08-24 15:59:33 -0400123 GrGpuRTCommandBuffer(GrRenderTarget* rt, GrSurfaceOrigin origin)
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400124 : fOrigin(origin)
Greg Daniel500d58b2017-08-24 15:59:33 -0400125 , fRenderTarget(rt) {
126 }
127
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400128 void set(GrRenderTarget* rt, GrSurfaceOrigin origin) {
129 SkASSERT(!fRenderTarget);
130
131 fRenderTarget = rt;
132 fOrigin = origin;
133 }
134
135 GrSurfaceOrigin fOrigin;
Robert Phillips19e51dc2017-08-09 09:30:51 -0400136 GrRenderTarget* fRenderTarget;
Robert Phillips65a88fa2017-08-08 08:36:22 -0400137
egdaniel9cb63402016-06-23 08:37:05 -0700138private:
139 virtual GrGpu* gpu() = 0;
Greg Daniel65a09272016-10-12 09:47:22 -0400140
egdaniel9cb63402016-06-23 08:37:05 -0700141 // overridden by backend-specific derived class to perform the draw call.
Brian Salomonff168d92018-06-23 15:17:27 -0400142 virtual void onDraw(const GrPrimitiveProcessor&,
143 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -0400144 const GrPipeline::FixedDynamicState*,
145 const GrPipeline::DynamicStateArrays*,
Chris Dalton46983b72017-06-06 12:27:16 -0600146 const GrMesh[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400147 int meshCount,
148 const SkRect& bounds) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700149
150 // overridden by backend-specific derived class to perform the clear.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400151 virtual void onClear(const GrFixedClip&, GrColor) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700152
Robert Phillips19e51dc2017-08-09 09:30:51 -0400153 virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
Greg Daniel500d58b2017-08-24 15:59:33 -0400154
155 typedef GrGpuCommandBuffer INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700156};
157
158#endif