Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrOpsRenderPass.h
Go to the documentation of this file.
1/*
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 GrOpsRenderPass_DEFINED
9#define GrOpsRenderPass_DEFINED
10
13#include "include/gpu/GrTypes.h"
19
20#include <array>
21#include <cstddef>
22#include <cstdint>
23#include <memory>
24
26class GrGpu;
27class GrOpFlushState;
28class GrPipeline;
29class GrProgramInfo;
30class GrRenderTarget;
31class GrScissorState;
32class GrSurfaceProxy;
33struct SkIRect;
34struct SkRect;
35
36/**
37 * The GrOpsRenderPass is a series of commands (draws, clears, and discards), which all target the
38 * same render target. It is possible that these commands execute immediately (GL), or get buffered
39 * up for later execution (Vulkan). GrOps execute into a GrOpsRenderPass.
40 */
42public:
43 virtual ~GrOpsRenderPass() {}
44
50
51 // Load-time clears of the stencil buffer are always to 0 so we don't store
52 // an 'fStencilClearValue'
57
58 void begin();
59 // Signals the end of recording to the GrOpsRenderPass and that it can now be submitted.
60 void end();
61
62 // Updates the internal pipeline state for drawing with the provided GrProgramInfo. Enters an
63 // internal "bad" state if the pipeline could not be set.
64 void bindPipeline(const GrProgramInfo&, const SkRect& drawBounds);
65
66 // The scissor rect is always dynamic state and therefore not stored on GrPipeline. If scissor
67 // test is enabled on the current pipeline, then the client must call setScissorRect() before
68 // drawing. The scissor rect may also be updated between draws without having to bind a new
69 // pipeline.
70 void setScissorRect(const SkIRect&);
71
72 // Binds textures for the primitive processor and any FP on the GrPipeline. Texture bindings are
73 // dynamic state and therefore not set during bindPipeline(). If the current program uses
74 // textures, then the client must call bindTextures() before drawing. The primitive processor
75 // textures may also be updated between draws by calling bindTextures() again with a different
76 // array for primProcTextures. (On subsequent calls, if the backend is capable of updating the
77 // primitive processor textures independently, then it will automatically skip re-binding
78 // FP textures from GrPipeline.)
79 //
80 // If the current program does not use textures, this is a no-op.
82 const GrSurfaceProxy* const geomProcTextures[],
83 const GrPipeline&);
84
85 void bindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
87
88 // The next several draw*() methods issue draws using the current pipeline state. Before
89 // drawing, the caller must configure the pipeline and dynamic state:
90 //
91 // - Call bindPipeline()
92 // - If the scissor test is enabled, call setScissorRect()
93 // - If the current program uses textures, call bindTextures()
94 // - Call bindBuffers() (even if all buffers are null)
95 void draw(int vertexCount, int baseVertex);
96 void drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue,
97 int baseVertex);
98
99 // Requires caps.drawInstancedSupport().
100 void drawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex);
101
102 // Requires caps.drawInstancedSupport().
103 void drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
104 int baseVertex);
105
106 // Executes multiple draws from an array of GrDrawIndirectCommand in the provided buffer.
107 //
108 // Requires caps.drawInstancedSupport().
109 //
110 // If caps.nativeDrawIndirectSupport() is unavailable, then 'drawIndirectBuffer' must be a
111 // GrCpuBuffer in order to polyfill. Performance may suffer in this scenario.
112 void drawIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset, int drawCount);
113
114 // Executes multiple draws from an array of GrDrawIndexedIndirectCommand in the provided buffer.
115 //
116 // Requires caps.drawInstancedSupport().
117 //
118 // If caps.nativeDrawIndirectSupport() is unavailable, then 'drawIndirectBuffer' must be a
119 // GrCpuBuffer in order to polyfill. Performance may suffer in this scenario.
120 void drawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset,
121 int drawCount);
122
123 // This is a helper method for drawing a repeating pattern of vertices. The bound index buffer
124 // is understood to contain 'maxPatternRepetitionsInIndexBuffer' repetitions of the pattern.
125 // If more repetitions are required, then we loop.
126 void drawIndexPattern(int patternIndexCount, int patternRepeatCount,
127 int maxPatternRepetitionsInIndexBuffer, int patternVertexCount,
128 int baseVertex);
129
130 // Performs an upload of vertex data in the middle of a set of a set of draws
132
133 /**
134 * Clear the owned render target. Clears the full target if 'scissor' is disabled, otherwise it
135 * is restricted to 'scissor'. Must check caps.performPartialClearsAsDraws() before using an
136 * enabled scissor test; must check caps.performColorClearsAsDraws() before using this at all.
137 */
138 void clear(const GrScissorState& scissor, std::array<float, 4> color);
139
140 /**
141 * Same as clear() but modifies the stencil; check caps.performStencilClearsAsDraws() and
142 * caps.performPartialClearsAsDraws().
143 */
144 void clearStencilClip(const GrScissorState& scissor, bool insideStencilMask);
145
146 /**
147 * Executes the SkDrawable object for the underlying backend.
148 */
149 void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>);
150
151protected:
153
155 : fOrigin(origin)
156 , fRenderTarget(rt) {
157 }
158
161
162 fRenderTarget = rt;
163 fOrigin = origin;
164 }
165
168
169 // Backends may defer binding of certain buffers if their draw API requires a buffer, or if
170 // their bind methods don't support base values.
174
175private:
176 virtual GrGpu* gpu() = 0;
177
178 void resetActiveBuffers() {
182 }
183
184 bool prepareToDraw();
185
186 // overridden by backend-specific derived class to perform the rendering command.
187 virtual void onBegin() {}
188 virtual void onEnd() {}
189 virtual bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) = 0;
190 virtual void onSetScissorRect(const SkIRect&) = 0;
192 const GrSurfaceProxy* const geomProcTextures[],
193 const GrPipeline&) = 0;
194 virtual void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
195 sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) = 0;
196 virtual void onDraw(int vertexCount, int baseVertex) = 0;
197 virtual void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
198 uint16_t maxIndexValue, int baseVertex) = 0;
199 virtual void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
200 int baseVertex) = 0;
201 virtual void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount,
202 int baseInstance, int baseVertex) = 0;
203 virtual void onDrawIndirect(const GrBuffer*, size_t offset, int drawCount) {
204 SK_ABORT("Not implemented."); // Only called if caps.nativeDrawIndirectSupport().
205 }
206 virtual void onDrawIndexedIndirect(const GrBuffer*, size_t offset, int drawCount) {
207 SK_ABORT("Not implemented."); // Only called if caps.nativeDrawIndirectSupport().
208 }
209 virtual void onClear(const GrScissorState&, std::array<float, 4> color) = 0;
210 virtual void onClearStencilClip(const GrScissorState&, bool insideStencilMask) = 0;
211 virtual void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
212
213 enum class DrawPipelineStatus {
214 kOk = 0,
215 kNotConfigured,
216 kFailedToBind
217 };
218
219 DrawPipelineStatus fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
220 GrXferBarrierType fXferBarrierType;
221
222#ifdef SK_DEBUG
223 enum class DynamicStateStatus {
224 kDisabled,
226 kConfigured
227 };
228
229 DynamicStateStatus fScissorStatus;
230 DynamicStateStatus fTextureBindingStatus;
231 bool fHasIndexBuffer;
232 DynamicStateStatus fInstanceBufferStatus;
233 DynamicStateStatus fVertexBufferStatus;
234#endif
235
236 using INHERITED = GrOpsRenderPass;
237};
238
239#endif
std::function< void(GrDeferredTextureUploadWritePixelsFn &)> GrDeferredTextureUploadFn
GrPrimitiveRestart
Definition GrTypesPriv.h:55
GrStoreOp
GrLoadOp
GrSurfaceOrigin
Definition GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
GrXferBarrierType
SkColor4f color
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
Definition GrGpu.h:62
virtual void onBegin()
void bindTextures(const GrGeometryProcessor &, const GrSurfaceProxy *const geomProcTextures[], const GrPipeline &)
virtual void inlineUpload(GrOpFlushState *, GrDeferredTextureUploadFn &)=0
virtual void onSetScissorRect(const SkIRect &)=0
virtual void onEnd()
virtual void onExecuteDrawable(std::unique_ptr< SkDrawable::GpuDrawHandler >)
void bindPipeline(const GrProgramInfo &, const SkRect &drawBounds)
sk_sp< const GrBuffer > fActiveIndexBuffer
void draw(int vertexCount, int baseVertex)
virtual bool onBindTextures(const GrGeometryProcessor &, const GrSurfaceProxy *const geomProcTextures[], const GrPipeline &)=0
void clear(const GrScissorState &scissor, std::array< float, 4 > color)
sk_sp< const GrBuffer > fActiveInstanceBuffer
void drawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex)
void drawIndexPattern(int patternIndexCount, int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer, int patternVertexCount, int baseVertex)
virtual void onClearStencilClip(const GrScissorState &, bool insideStencilMask)=0
virtual void onDrawIndexedIndirect(const GrBuffer *, size_t offset, int drawCount)
virtual GrGpu * gpu()=0
sk_sp< const GrBuffer > fActiveVertexBuffer
virtual void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue, int baseVertex)=0
virtual void onBindBuffers(sk_sp< const GrBuffer > indexBuffer, sk_sp< const GrBuffer > instanceBuffer, sk_sp< const GrBuffer > vertexBuffer, GrPrimitiveRestart)=0
virtual void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance, int baseVertex)=0
void executeDrawable(std::unique_ptr< SkDrawable::GpuDrawHandler >)
void bindBuffers(sk_sp< const GrBuffer > indexBuffer, sk_sp< const GrBuffer > instanceBuffer, sk_sp< const GrBuffer > vertexBuffer, GrPrimitiveRestart=GrPrimitiveRestart::kNo)
void set(GrRenderTarget *rt, GrSurfaceOrigin origin)
void setScissorRect(const SkIRect &)
virtual void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex)=0
GrOpsRenderPass(GrRenderTarget *rt, GrSurfaceOrigin origin)
void drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue, int baseVertex)
virtual void onDrawIndirect(const GrBuffer *, size_t offset, int drawCount)
virtual ~GrOpsRenderPass()
void drawIndexedIndirect(const GrBuffer *drawIndirectBuffer, size_t bufferOffset, int drawCount)
virtual bool onBindPipeline(const GrProgramInfo &, const SkRect &drawBounds)=0
virtual void onClear(const GrScissorState &, std::array< float, 4 > color)=0
void drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance, int baseVertex)
GrSurfaceOrigin fOrigin
void drawIndirect(const GrBuffer *drawIndirectBuffer, size_t bufferOffset, int drawCount)
void clearStencilClip(const GrScissorState &scissor, bool insideStencilMask)
virtual void onDraw(int vertexCount, int baseVertex)=0
GrRenderTarget * fRenderTarget
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
Point offset
std::array< float, 4 > fClearColor