32 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
34 fScissorStatus = DynamicStateStatus::kDisabled;
35 fTextureBindingStatus = DynamicStateStatus::kDisabled;
36 fHasIndexBuffer =
false;
37 fInstanceBufferStatus = DynamicStateStatus::kDisabled;
38 fVertexBufferStatus = DynamicStateStatus::kDisabled;
45 this->resetActiveBuffers();
52 SkASSERT(!this->
gpu()->caps()->performColorClearsAsDraws());
53 SkASSERT(!scissor.
enabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
54 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
60 SkASSERT(!this->
gpu()->caps()->performStencilClearsAsDraws());
61 SkASSERT(!scissor.
enabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
62 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
67 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
77 SkASSERT(this->
gpu()->caps()->drawInstancedSupport());
80 SkASSERT(this->
gpu()->caps()->conservativeRasterSupport());
85 if (this->
gpu()->caps()->twoSidedStencilRefsAndMasksMustMatch() &&
94 programInfo.checkAllInstantiated();
95 programInfo.checkMSAAAndMIPSAreResolved();
98 this->resetActiveBuffers();
101 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
106 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
112 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
118 fTextureBindingStatus = (hasTextures) ?
119 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
120 fHasIndexBuffer =
false;
122 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
124 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
127 fDrawPipelineStatus = DrawPipelineStatus::kOk;
132 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
133 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
136 SkASSERT(DynamicStateStatus::kDisabled != fScissorStatus);
138 SkDEBUGCODE(fScissorStatus = DynamicStateStatus::kConfigured);
164 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
165 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
172 if (!this->
onBindTextures(geomProc, geomProcTextures, pipeline)) {
173 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
177 SkDEBUGCODE(fTextureBindingStatus = DynamicStateStatus::kConfigured);
184 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
185 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
191 fHasIndexBuffer =
true;
194 SkASSERT((DynamicStateStatus::kDisabled == fInstanceBufferStatus) !=
SkToBool(instanceBuffer));
195 if (instanceBuffer) {
196 fInstanceBufferStatus = DynamicStateStatus::kConfigured;
199 SkASSERT((DynamicStateStatus::kDisabled == fVertexBufferStatus) !=
SkToBool(vertexBuffer));
201 fVertexBufferStatus = DynamicStateStatus::kConfigured;
205 SkASSERT(this->
gpu()->caps()->usePrimitiveRestart());
209 this->
onBindBuffers(std::move(indexBuffer), std::move(instanceBuffer), std::move(vertexBuffer),
213bool GrOpsRenderPass::prepareToDraw() {
214 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
215 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
219 SkASSERT(DynamicStateStatus::kUninitialized != fScissorStatus);
220 SkASSERT(DynamicStateStatus::kUninitialized != fTextureBindingStatus);
229 if (!this->prepareToDraw()) {
233 SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus);
234 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
235 this->
onDraw(vertexCount, baseVertex);
239 uint16_t maxIndexValue,
int baseVertex) {
240 if (!this->prepareToDraw()) {
244 SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus);
245 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
246 this->
onDrawIndexed(indexCount, baseIndex, minIndexValue, maxIndexValue, baseVertex);
251 SkASSERT(this->
gpu()->caps()->drawInstancedSupport());
252 if (!this->prepareToDraw()) {
256 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
257 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
258 this->
onDrawInstanced(instanceCount, baseInstance, vertexCount, baseVertex);
262 int baseInstance,
int baseVertex) {
263 SkASSERT(this->
gpu()->caps()->drawInstancedSupport());
264 if (!this->prepareToDraw()) {
268 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
269 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
275 SkASSERT(this->
gpu()->caps()->drawInstancedSupport());
278 if (!this->prepareToDraw()) {
282 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
283 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
284 if (!this->
gpu()->caps()->nativeDrawIndirectSupport()) {
287 auto* cpuIndirectBuffer =
static_cast<const GrCpuBuffer*
>(drawIndirectBuffer);
289 cpuIndirectBuffer->data() + bufferOffset);
290 for (
int i = 0;
i < drawCount; ++
i) {
291 auto [vertexCount, instanceCount, baseVertex, baseInstance] = cmds[
i];
292 this->
onDrawInstanced(instanceCount, baseInstance, vertexCount, baseVertex);
296 this->
onDrawIndirect(drawIndirectBuffer, bufferOffset, drawCount);
301 SkASSERT(this->
gpu()->caps()->drawInstancedSupport());
304 if (!this->prepareToDraw()) {
308 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
309 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
310 if (!this->
gpu()->caps()->nativeDrawIndirectSupport() ||
311 this->
gpu()->caps()->nativeDrawIndexedIndirectIsBroken()) {
314 auto* cpuIndirectBuffer =
static_cast<const GrCpuBuffer*
>(drawIndirectBuffer);
316 cpuIndirectBuffer->data() + bufferOffset);
317 for (
int i = 0;
i < drawCount; ++
i) {
318 auto [indexCount, instanceCount, baseIndex, baseVertex, baseInstance] = cmds[
i];
328 int maxPatternRepetitionsInIndexBuffer,
329 int patternVertexCount,
int baseVertex) {
330 int baseRepetition = 0;
331 while (baseRepetition < patternRepeatCount) {
332 int repeatCount =
std::min(patternRepeatCount - baseRepetition,
333 maxPatternRepetitionsInIndexBuffer);
334 int drawIndexCount = repeatCount * patternIndexCount;
336 int minIndexValue = 0;
337 int maxIndexValue = patternVertexCount * repeatCount - 1;
338 this->
drawIndexed(drawIndexCount, 0, minIndexValue, maxIndexValue,
339 patternVertexCount * baseRepetition + baseVertex);
340 baseRepetition += repeatCount;
@ kNone_GrXferBarrierType
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr bool SkToBool(const T &x)
virtual bool isCpuBuffer() const =0
int numVertexAttributes() const
const TextureSampler & textureSampler(int index) const
int numTextureSamplers() const
bool hasInstanceAttributes() const
bool hasVertexAttributes() const
const GrCaps * caps() const
virtual void xferBarrier(GrRenderTarget *, GrXferBarrierType)=0
void bindTextures(const GrGeometryProcessor &, const GrSurfaceProxy *const geomProcTextures[], const GrPipeline &)
virtual void onSetScissorRect(const SkIRect &)=0
virtual void onExecuteDrawable(std::unique_ptr< SkDrawable::GpuDrawHandler >)
void bindPipeline(const GrProgramInfo &, const SkRect &drawBounds)
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)
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 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 setScissorRect(const SkIRect &)
virtual void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex)=0
void drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue, int baseVertex)
virtual void onDrawIndirect(const GrBuffer *, size_t offset, int drawCount)
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)
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
bool hasStencilClip() const
void visitProxies(const GrVisitProxyFunc &) const
bool isScissorTestEnabled() const
bool usesConservativeRaster() const
GrXferBarrierType xferBarrierType(const GrCaps &) const
GrSurfaceOrigin origin() const
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
const GrUserStencilSettings * userStencilSettings() const
bool isStencilEnabled() const
const GrBackendFormat & backendFormat() const
GrTexture * peekTexture() const
skgpu::Mipmapped mipmapped() const
bool mipmapsAreDirty() const
static float min(float r, float g, float b)
bool isTwoSided(bool hasStencilClip) const