blob: e96c610754339366ecb759ebfb5e9fb7a85c2aca [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkDrawable.h"
12#include "src/gpu/GrPipeline.h"
13#include "src/gpu/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;
Greg Daniel64cc9aa2018-10-19 13:54:56 -040022class GrSemaphore;
egdaniel9cb63402016-06-23 08:37:05 -070023struct SkIRect;
Greg Daniel36a77ee2016-10-18 10:33:25 -040024struct SkRect;
egdaniel066df7c2016-06-08 14:02:27 -070025
Greg Daniel500d58b2017-08-24 15:59:33 -040026class GrGpuRTCommandBuffer;
27
28class GrGpuCommandBuffer {
29public:
30 virtual ~GrGpuCommandBuffer() {}
31
32 // Copy src into current surface owned by either a GrGpuTextureCommandBuffer or
Greg Daniel46cfbc62019-06-07 11:43:30 -040033 // GrGpuRenderTargetCommandBuffer. The srcRect and dstPoint must be in dst coords and have
34 // already been adjusted for any origin flips.
35 virtual void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) = 0;
Brian Salomonab32f652019-05-10 14:24:50 -040036 // Initiates a transfer from the surface owned by the command buffer to the GrGpuBuffer.
37 virtual void transferFrom(const SkIRect& srcRect, GrColorType bufferColorType,
38 GrGpuBuffer* transferBuffer, size_t offset) = 0;
Greg Daniel500d58b2017-08-24 15:59:33 -040039
40 virtual void insertEventMarker(const char*) = 0;
41
42 virtual GrGpuRTCommandBuffer* asRTCommandBuffer() { return nullptr; }
Greg Daniel500d58b2017-08-24 15:59:33 -040043};
44
45class GrGpuTextureCommandBuffer : public GrGpuCommandBuffer{
46public:
Robert Phillips5b5d84c2018-08-09 15:12:18 -040047 void set(GrTexture* texture, GrSurfaceOrigin origin) {
48 SkASSERT(!fTexture);
Greg Daniel500d58b2017-08-24 15:59:33 -040049
Robert Phillips5b5d84c2018-08-09 15:12:18 -040050 fTexture = texture;
51 }
Greg Daniel500d58b2017-08-24 15:59:33 -040052
53protected:
Greg Daniel46cfbc62019-06-07 11:43:30 -040054 GrGpuTextureCommandBuffer() : fTexture(nullptr) {}
Greg Daniel500d58b2017-08-24 15:59:33 -040055
Greg Daniel46cfbc62019-06-07 11:43:30 -040056 GrGpuTextureCommandBuffer(GrTexture* texture, GrSurfaceOrigin origin) : fTexture(texture) {}
Robert Phillips5b5d84c2018-08-09 15:12:18 -040057
Robert Phillips5b5d84c2018-08-09 15:12:18 -040058 GrTexture* fTexture;
Greg Daniel500d58b2017-08-24 15:59:33 -040059
60private:
61 typedef GrGpuCommandBuffer INHERITED;
62};
63
egdaniel9cb63402016-06-23 08:37:05 -070064/**
Greg Daniel500d58b2017-08-24 15:59:33 -040065 * The GrGpuRenderTargetCommandBuffer is a series of commands (draws, clears, and discards), which
66 * all target the same render target. It is possible that these commands execute immediately (GL),
67 * or get buffered up for later execution (Vulkan). GrOps will execute their draw commands into a
egdaniel9cb63402016-06-23 08:37:05 -070068 * GrGpuCommandBuffer.
69 */
Greg Daniel500d58b2017-08-24 15:59:33 -040070class GrGpuRTCommandBuffer : public GrGpuCommandBuffer {
egdaniel066df7c2016-06-08 14:02:27 -070071public:
egdaniel9cb63402016-06-23 08:37:05 -070072 struct LoadAndStoreInfo {
Brian Osman9a9baae2018-11-05 15:06:26 -050073 GrLoadOp fLoadOp;
74 GrStoreOp fStoreOp;
75 SkPMColor4f fClearColor;
egdaniel066df7c2016-06-08 14:02:27 -070076 };
77
Robert Phillips95214472017-08-08 18:00:03 -040078 // Load-time clears of the stencil buffer are always to 0 so we don't store
79 // an 'fStencilClearValue'
80 struct StencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040081 GrLoadOp fLoadOp;
82 GrStoreOp fStoreOp;
Robert Phillips95214472017-08-08 18:00:03 -040083 };
84
Greg Daniel500d58b2017-08-24 15:59:33 -040085 GrGpuRTCommandBuffer* asRTCommandBuffer() { return this; }
egdaniel066df7c2016-06-08 14:02:27 -070086
Robert Phillips95214472017-08-08 18:00:03 -040087 virtual void begin() = 0;
egdaniel066df7c2016-06-08 14:02:27 -070088 // Signals the end of recording to the command buffer and that it can now be submitted.
89 virtual void end() = 0;
90
egdaniel9cb63402016-06-23 08:37:05 -070091 // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each
92 // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and
93 // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g.
94 // number of vertex attributes is too large).
Brian Salomonff168d92018-06-23 15:17:27 -040095 bool draw(const GrPrimitiveProcessor&,
96 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -040097 const GrPipeline::FixedDynamicState*,
98 const GrPipeline::DynamicStateArrays*,
Chris Daltonbca46e22017-05-15 11:03:26 -060099 const GrMesh[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400100 int meshCount,
101 const SkRect& bounds);
egdaniel9cb63402016-06-23 08:37:05 -0700102
Greg Daniel77b53f62016-10-18 11:48:51 -0400103 // Performs an upload of vertex data in the middle of a set of a set of draws
Brian Salomon943ed792017-10-30 09:37:55 -0400104 virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
Greg Daniel77b53f62016-10-18 11:48:51 -0400105
egdaniel9cb63402016-06-23 08:37:05 -0700106 /**
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000107 * Clear the owned render target. Ignores the draw state and clip.
Greg Daniel77b53f62016-10-18 11:48:51 -0400108 */
Brian Osman9a9baae2018-11-05 15:06:26 -0500109 void clear(const GrFixedClip&, const SkPMColor4f&);
egdaniel9cb63402016-06-23 08:37:05 -0700110
Robert Phillips19e51dc2017-08-09 09:30:51 -0400111 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
Greg Daniel36a77ee2016-10-18 10:33:25 -0400112
egdaniel9cb63402016-06-23 08:37:05 -0700113 /**
Robert Phillips19e51dc2017-08-09 09:30:51 -0400114 * Discards the contents render target.
Greg Daniel77b53f62016-10-18 11:48:51 -0400115 */
egdaniel9cb63402016-06-23 08:37:05 -0700116 // 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 -0400117 virtual void discard() = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700118
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400119 /**
120 * Executes the SkDrawable object for the underlying backend.
121 */
122 virtual void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
123
Robert Phillips19e51dc2017-08-09 09:30:51 -0400124protected:
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400125 GrGpuRTCommandBuffer() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {}
126
Greg Daniel500d58b2017-08-24 15:59:33 -0400127 GrGpuRTCommandBuffer(GrRenderTarget* rt, GrSurfaceOrigin origin)
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400128 : fOrigin(origin)
Greg Daniel500d58b2017-08-24 15:59:33 -0400129 , fRenderTarget(rt) {
130 }
131
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400132 void set(GrRenderTarget* rt, GrSurfaceOrigin origin) {
133 SkASSERT(!fRenderTarget);
134
135 fRenderTarget = rt;
136 fOrigin = origin;
137 }
138
139 GrSurfaceOrigin fOrigin;
Robert Phillips19e51dc2017-08-09 09:30:51 -0400140 GrRenderTarget* fRenderTarget;
Robert Phillips65a88fa2017-08-08 08:36:22 -0400141
egdaniel9cb63402016-06-23 08:37:05 -0700142private:
143 virtual GrGpu* gpu() = 0;
Greg Daniel65a09272016-10-12 09:47:22 -0400144
egdaniel9cb63402016-06-23 08:37:05 -0700145 // overridden by backend-specific derived class to perform the draw call.
Brian Salomonff168d92018-06-23 15:17:27 -0400146 virtual void onDraw(const GrPrimitiveProcessor&,
147 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -0400148 const GrPipeline::FixedDynamicState*,
149 const GrPipeline::DynamicStateArrays*,
Chris Dalton46983b72017-06-06 12:27:16 -0600150 const GrMesh[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400151 int meshCount,
152 const SkRect& bounds) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700153
154 // overridden by backend-specific derived class to perform the clear.
Brian Osman9a9baae2018-11-05 15:06:26 -0500155 virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700156
Robert Phillips19e51dc2017-08-09 09:30:51 -0400157 virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
Greg Daniel500d58b2017-08-24 15:59:33 -0400158
159 typedef GrGpuCommandBuffer INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700160};
161
162#endif