blob: 6963d23ebe8358ae2a468de3b1a4c0f20b229669 [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; }
39
40 // Sends the command buffer off to the GPU object to execute the commands built up in the
41 // buffer. The gpu object is allowed to defer execution of the commands until it is flushed.
42 virtual void submit() = 0;
43
44protected:
45 GrGpuCommandBuffer(GrSurfaceOrigin origin) : fOrigin(origin) {}
46
47 GrSurfaceOrigin fOrigin;
48};
49
50class GrGpuTextureCommandBuffer : public GrGpuCommandBuffer{
51public:
52 virtual ~GrGpuTextureCommandBuffer() {}
53
54 virtual void submit() = 0;
55
56protected:
57 GrGpuTextureCommandBuffer(GrTexture* texture, GrSurfaceOrigin origin)
58 : INHERITED(origin)
59 , fTexture(texture) {}
60
61 GrTexture* fTexture;
62
63private:
64 typedef GrGpuCommandBuffer INHERITED;
65};
66
egdaniel9cb63402016-06-23 08:37:05 -070067/**
Greg Daniel500d58b2017-08-24 15:59:33 -040068 * The GrGpuRenderTargetCommandBuffer is a series of commands (draws, clears, and discards), which
69 * all target the same render target. It is possible that these commands execute immediately (GL),
70 * or get buffered up for later execution (Vulkan). GrOps will execute their draw commands into a
egdaniel9cb63402016-06-23 08:37:05 -070071 * GrGpuCommandBuffer.
72 */
Greg Daniel500d58b2017-08-24 15:59:33 -040073class GrGpuRTCommandBuffer : public GrGpuCommandBuffer {
egdaniel066df7c2016-06-08 14:02:27 -070074public:
egdaniel9cb63402016-06-23 08:37:05 -070075 struct LoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040076 GrLoadOp fLoadOp;
77 GrStoreOp fStoreOp;
78 GrColor fClearColor;
egdaniel066df7c2016-06-08 14:02:27 -070079 };
80
Robert Phillips95214472017-08-08 18:00:03 -040081 // Load-time clears of the stencil buffer are always to 0 so we don't store
82 // an 'fStencilClearValue'
83 struct StencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040084 GrLoadOp fLoadOp;
85 GrStoreOp fStoreOp;
Robert Phillips95214472017-08-08 18:00:03 -040086 };
87
Greg Daniel500d58b2017-08-24 15:59:33 -040088 virtual ~GrGpuRTCommandBuffer() {}
89
90 GrGpuRTCommandBuffer* asRTCommandBuffer() { return this; }
egdaniel066df7c2016-06-08 14:02:27 -070091
Robert Phillips95214472017-08-08 18:00:03 -040092 virtual void begin() = 0;
egdaniel066df7c2016-06-08 14:02:27 -070093 // Signals the end of recording to the command buffer and that it can now be submitted.
94 virtual void end() = 0;
95
egdaniel9cb63402016-06-23 08:37:05 -070096 // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each
97 // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and
98 // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g.
99 // number of vertex attributes is too large).
100 bool draw(const GrPipeline&,
101 const GrPrimitiveProcessor&,
Chris Daltonbca46e22017-05-15 11:03:26 -0600102 const GrMesh[],
Chris Dalton46983b72017-06-06 12:27:16 -0600103 const GrPipeline::DynamicState[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400104 int meshCount,
105 const SkRect& bounds);
egdaniel9cb63402016-06-23 08:37:05 -0700106
Greg Daniel77b53f62016-10-18 11:48:51 -0400107 // Performs an upload of vertex data in the middle of a set of a set of draws
Brian Salomon943ed792017-10-30 09:37:55 -0400108 virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
Greg Daniel77b53f62016-10-18 11:48:51 -0400109
egdaniel9cb63402016-06-23 08:37:05 -0700110 /**
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000111 * Clear the owned render target. Ignores the draw state and clip.
Greg Daniel77b53f62016-10-18 11:48:51 -0400112 */
Robert Phillips19e51dc2017-08-09 09:30:51 -0400113 void clear(const GrFixedClip&, GrColor);
egdaniel9cb63402016-06-23 08:37:05 -0700114
Robert Phillips19e51dc2017-08-09 09:30:51 -0400115 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
Greg Daniel36a77ee2016-10-18 10:33:25 -0400116
egdaniel9cb63402016-06-23 08:37:05 -0700117 /**
Robert Phillips19e51dc2017-08-09 09:30:51 -0400118 * Discards the contents render target.
Greg Daniel77b53f62016-10-18 11:48:51 -0400119 */
egdaniel9cb63402016-06-23 08:37:05 -0700120 // 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 -0400121 virtual void discard() = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700122
Robert Phillips19e51dc2017-08-09 09:30:51 -0400123protected:
Greg Daniel500d58b2017-08-24 15:59:33 -0400124 GrGpuRTCommandBuffer(GrRenderTarget* rt, GrSurfaceOrigin origin)
125 : INHERITED(origin)
126 , fRenderTarget(rt) {
127 }
128
Robert Phillips19e51dc2017-08-09 09:30:51 -0400129 GrRenderTarget* fRenderTarget;
Robert Phillips65a88fa2017-08-08 08:36:22 -0400130
egdaniel9cb63402016-06-23 08:37:05 -0700131private:
132 virtual GrGpu* gpu() = 0;
Greg Daniel65a09272016-10-12 09:47:22 -0400133
egdaniel9cb63402016-06-23 08:37:05 -0700134 // overridden by backend-specific derived class to perform the draw call.
135 virtual void onDraw(const GrPipeline&,
136 const GrPrimitiveProcessor&,
Chris Dalton46983b72017-06-06 12:27:16 -0600137 const GrMesh[],
138 const GrPipeline::DynamicState[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400139 int meshCount,
140 const SkRect& bounds) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700141
142 // overridden by backend-specific derived class to perform the clear.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400143 virtual void onClear(const GrFixedClip&, GrColor) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700144
Robert Phillips19e51dc2017-08-09 09:30:51 -0400145 virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
Greg Daniel500d58b2017-08-24 15:59:33 -0400146
147 typedef GrGpuCommandBuffer INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700148};
149
150#endif