blob: c6d8c1c4e5847b079cbaaf0d004b9c1f8d469ac9 [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
Greg Daniel2d41d0d2019-08-26 11:08:51 -04008#ifndef GrOpsRenderPass_DEFINED
9#define GrOpsRenderPass_DEFINED
egdaniel066df7c2016-06-08 14:02:27 -070010
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;
Robert Phillips901aff02019-10-08 12:32:56 -040021class GrProgramInfo;
egdaniel066df7c2016-06-08 14:02:27 -070022class GrRenderTarget;
Greg Daniel64cc9aa2018-10-19 13:54:56 -040023class GrSemaphore;
egdaniel9cb63402016-06-23 08:37:05 -070024struct SkIRect;
Greg Daniel36a77ee2016-10-18 10:33:25 -040025struct SkRect;
egdaniel066df7c2016-06-08 14:02:27 -070026
Greg Daniel2d41d0d2019-08-26 11:08:51 -040027/**
28 * The GrOpsRenderPass is a series of commands (draws, clears, and discards), which all target the
29 * same render target. It is possible that these commands execute immediately (GL), or get buffered
30 * up for later execution (Vulkan). GrOps execute into a GrOpsRenderPass.
31 */
32class GrOpsRenderPass {
Greg Daniel500d58b2017-08-24 15:59:33 -040033public:
Greg Daniel2d41d0d2019-08-26 11:08:51 -040034 virtual ~GrOpsRenderPass() {}
Greg Daniel500d58b2017-08-24 15:59:33 -040035
egdaniel9cb63402016-06-23 08:37:05 -070036 struct LoadAndStoreInfo {
Brian Osman9a9baae2018-11-05 15:06:26 -050037 GrLoadOp fLoadOp;
38 GrStoreOp fStoreOp;
39 SkPMColor4f fClearColor;
egdaniel066df7c2016-06-08 14:02:27 -070040 };
41
Robert Phillips95214472017-08-08 18:00:03 -040042 // Load-time clears of the stencil buffer are always to 0 so we don't store
43 // an 'fStencilClearValue'
44 struct StencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040045 GrLoadOp fLoadOp;
46 GrStoreOp fStoreOp;
Robert Phillips95214472017-08-08 18:00:03 -040047 };
48
Robert Phillips95214472017-08-08 18:00:03 -040049 virtual void begin() = 0;
Greg Daniel2d41d0d2019-08-26 11:08:51 -040050 // Signals the end of recording to the GrOpsRenderPass and that it can now be submitted.
egdaniel066df7c2016-06-08 14:02:27 -070051 virtual void end() = 0;
52
Chris Dalton4386ad12020-02-19 16:42:06 -070053 // Updates the internal pipeline state for drawing with the provided GrProgramInfo.
Chris Dalton2e7ed262020-02-21 15:17:59 -070054 // Enters an internal "bad" state if the pipeline could not be set.
Chris Dalton4386ad12020-02-19 16:42:06 -070055 void bindPipeline(const GrProgramInfo&, const SkRect& drawBounds);
56
Chris Dalton2e7ed262020-02-21 15:17:59 -070057 // The scissor rect is always dynamic state and therefore not stored on GrPipeline. If scissor
58 // test is enabled on the current pipeline, then the client must call setScissorRect() before
59 // drawing. The scissor rect may also be updated between draws without having to bind a new
60 // pipeline.
61 void setScissorRect(const SkIRect&);
62
Chris Daltondb20afc2020-03-05 12:13:53 -070063 // Binds textures for the primitive processor and any FP on the GrPipeline. Texture bindings are
64 // dynamic state and therefore not set during bindPipeline(). If the current program uses
65 // textures, then the client must call bindTextures() before drawing. The primitive processor
66 // textures may also be updated between draws by calling bindTextures() again with a different
67 // array for primProcTextures. (On subsequent calls, if the backend is capable of updating the
68 // primitive processor textures independently, then it will automatically skip re-binding
69 // FP textures from GrPipeline.)
Chris Daltonded43702020-03-02 11:45:27 -070070 //
71 // If the current program does not use textures, this is a no-op.
Chris Daltondb20afc2020-03-05 12:13:53 -070072 void bindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
73 const GrPipeline&);
Chris Dalton2e7ed262020-02-21 15:17:59 -070074
Chris Daltonded43702020-03-02 11:45:27 -070075 void bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
76 const GrBuffer* vertexBuffer, GrPrimitiveRestart = GrPrimitiveRestart::kNo);
77
Chris Dalton4386ad12020-02-19 16:42:06 -070078 // Draws the given array of meshes using the current pipeline state. The client must call
79 // bindPipeline() before using this method.
80 //
Chris Dalton2e7ed262020-02-21 15:17:59 -070081 // NOTE: This method will soon be deleted. While it continues to exist, it takes care of calling
82 // setScissor() and bindTextures() on the client's behalf.
Chris Dalton4386ad12020-02-19 16:42:06 -070083 void drawMeshes(const GrProgramInfo&, const GrMesh[], int meshCount);
egdaniel9cb63402016-06-23 08:37:05 -070084
Chris Daltonded43702020-03-02 11:45:27 -070085 // These methods issue draws using the current pipeline state. Before drawing, the caller must
86 // configure the pipeline and dynamic state:
87 //
88 // - Call bindPipeline()
89 // - If the scissor test is enabled, call setScissorRect()
90 // - If the current program uses textures, call bindTextures()
91 // - Call bindBuffers() (even if all buffers are null)
92 void draw(int vertexCount, int baseVertex);
93 void drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue,
Chris Dalton33db9fc2020-02-25 18:52:12 -070094 int baseVertex);
Chris Daltonded43702020-03-02 11:45:27 -070095 void drawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex);
96 void drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
97 int baseVertex);
Chris Dalton2e7ed262020-02-21 15:17:59 -070098
Greg Daniel77b53f62016-10-18 11:48:51 -040099 // Performs an upload of vertex data in the middle of a set of a set of draws
Brian Salomon943ed792017-10-30 09:37:55 -0400100 virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
Greg Daniel77b53f62016-10-18 11:48:51 -0400101
egdaniel9cb63402016-06-23 08:37:05 -0700102 /**
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000103 * Clear the owned render target. Ignores the draw state and clip.
Greg Daniel77b53f62016-10-18 11:48:51 -0400104 */
Brian Osman9a9baae2018-11-05 15:06:26 -0500105 void clear(const GrFixedClip&, const SkPMColor4f&);
egdaniel9cb63402016-06-23 08:37:05 -0700106
Robert Phillips19e51dc2017-08-09 09:30:51 -0400107 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
Greg Daniel36a77ee2016-10-18 10:33:25 -0400108
egdaniel9cb63402016-06-23 08:37:05 -0700109 /**
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400110 * Executes the SkDrawable object for the underlying backend.
111 */
Chris Dalton4386ad12020-02-19 16:42:06 -0700112 void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>);
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400113
Robert Phillips19e51dc2017-08-09 09:30:51 -0400114protected:
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400115 GrOpsRenderPass() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {}
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400116
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400117 GrOpsRenderPass(GrRenderTarget* rt, GrSurfaceOrigin origin)
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400118 : fOrigin(origin)
Greg Daniel500d58b2017-08-24 15:59:33 -0400119 , fRenderTarget(rt) {
120 }
121
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400122 void set(GrRenderTarget* rt, GrSurfaceOrigin origin) {
123 SkASSERT(!fRenderTarget);
124
125 fRenderTarget = rt;
126 fOrigin = origin;
127 }
128
129 GrSurfaceOrigin fOrigin;
Robert Phillips19e51dc2017-08-09 09:30:51 -0400130 GrRenderTarget* fRenderTarget;
Robert Phillips65a88fa2017-08-08 08:36:22 -0400131
egdaniel9cb63402016-06-23 08:37:05 -0700132private:
133 virtual GrGpu* gpu() = 0;
Greg Daniel65a09272016-10-12 09:47:22 -0400134
Chris Dalton33db9fc2020-02-25 18:52:12 -0700135 bool prepareToDraw();
136
Chris Dalton4386ad12020-02-19 16:42:06 -0700137 // overridden by backend-specific derived class to perform the rendering command.
138 virtual bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) = 0;
Chris Dalton2e7ed262020-02-21 15:17:59 -0700139 virtual void onSetScissorRect(const SkIRect&) = 0;
Chris Daltondb20afc2020-03-05 12:13:53 -0700140 virtual bool onBindTextures(const GrPrimitiveProcessor&,
141 const GrSurfaceProxy* const primProcTextures[],
142 const GrPipeline&) = 0;
Chris Daltonded43702020-03-02 11:45:27 -0700143 virtual void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
144 const GrBuffer* vertexBuffer, GrPrimitiveRestart) = 0;
145 virtual void onDraw(int vertexCount, int baseVertex) = 0;
146 virtual void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
147 uint16_t maxIndexValue, int baseVertex) = 0;
148 virtual void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
Chris Dalton33db9fc2020-02-25 18:52:12 -0700149 int baseVertex) = 0;
Chris Daltonded43702020-03-02 11:45:27 -0700150 virtual void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount,
151 int baseInstance, int baseVertex) = 0;
Brian Osman9a9baae2018-11-05 15:06:26 -0500152 virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
Robert Phillips19e51dc2017-08-09 09:30:51 -0400153 virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
Chris Dalton4386ad12020-02-19 16:42:06 -0700154 virtual void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
155
156 enum class DrawPipelineStatus {
157 kOk = 0,
158 kNotConfigured,
159 kFailedToBind
160 };
161
162 DrawPipelineStatus fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
Chris Dalton2e7ed262020-02-21 15:17:59 -0700163 GrXferBarrierType fXferBarrierType;
164
165#ifdef SK_DEBUG
166 enum class DynamicStateStatus {
167 kDisabled,
168 kUninitialized,
169 kConfigured
170 };
171
172 DynamicStateStatus fScissorStatus = DynamicStateStatus::kDisabled;
173 DynamicStateStatus fTextureBindingStatus = DynamicStateStatus::kDisabled;
Chris Daltonded43702020-03-02 11:45:27 -0700174 bool fHasIndexBuffer = false;
175 DynamicStateStatus fInstanceBufferStatus = DynamicStateStatus::kDisabled;
176 DynamicStateStatus fVertexBufferStatus = DynamicStateStatus::kDisabled;
Chris Dalton2e7ed262020-02-21 15:17:59 -0700177#endif
Greg Daniel500d58b2017-08-24 15:59:33 -0400178
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400179 typedef GrOpsRenderPass INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700180};
181
182#endif