blob: dd511f70af490c553e13be7e3a2da0f126863a00 [file] [log] [blame]
egdaniel9cb63402016-06-23 08:37:05 -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#include "src/gpu/GrOpsRenderPass.h"
egdaniel9cb63402016-06-23 08:37:05 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkRect.h"
11#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrCaps.h"
13#include "src/gpu/GrContextPriv.h"
14#include "src/gpu/GrFixedClip.h"
15#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrMesh.h"
17#include "src/gpu/GrPrimitiveProcessor.h"
Robert Phillips901aff02019-10-08 12:32:56 -040018#include "src/gpu/GrProgramInfo.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040019#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrRenderTargetPriv.h"
Chris Dalton4ece96d2019-08-30 11:26:39 -060021#include "src/gpu/GrTexturePriv.h"
egdaniel9cb63402016-06-23 08:37:05 -070022
Greg Daniel2d41d0d2019-08-26 11:08:51 -040023void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
Robert Phillips4912d902018-04-27 12:09:35 -040024 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050025 // A clear at this level will always be a true clear, so make sure clears were not supposed to
26 // be redirected to draws instead
27 SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
28 SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Chris Dalton4386ad12020-02-19 16:42:06 -070029 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
Robert Phillips19e51dc2017-08-09 09:30:51 -040030 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070031}
32
Greg Daniel2d41d0d2019-08-26 11:08:51 -040033void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050034 // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
35 SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
Chris Dalton4386ad12020-02-19 16:42:06 -070036 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
Robert Phillips19e51dc2017-08-09 09:30:51 -040037 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070038}
39
Chris Dalton4386ad12020-02-19 16:42:06 -070040void GrOpsRenderPass::executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable) {
41 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
42 this->onExecuteDrawable(std::move(drawable));
43}
Robert Phillips901aff02019-10-08 12:32:56 -040044
Chris Dalton4386ad12020-02-19 16:42:06 -070045void GrOpsRenderPass::bindPipeline(const GrProgramInfo& programInfo, const SkRect& drawBounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060046#ifdef SK_DEBUG
Chris Dalton4386ad12020-02-19 16:42:06 -070047 if (programInfo.primProc().hasInstanceAttributes()) {
48 SkASSERT(this->gpu()->caps()->instanceAttribSupport());
49 }
50 if (programInfo.pipeline().usesConservativeRaster()) {
51 SkASSERT(this->gpu()->caps()->conservativeRasterSupport());
52 // Conservative raster, by default, only supports triangles. Implementations can
53 // optionally indicate that they also support points and lines, but we don't currently
54 // query or track that info.
55 SkASSERT(GrIsPrimTypeTris(programInfo.primitiveType()));
56 }
57 if (programInfo.pipeline().isWireframe()) {
58 SkASSERT(this->gpu()->caps()->wireframeSupport());
59 }
60 if (GrPrimitiveType::kPatches == programInfo.primitiveType()) {
61 SkASSERT(this->gpu()->caps()->shaderCaps()->tessellationSupport());
62 }
Robert Phillips2d8a95e2019-10-10 12:50:22 -040063 programInfo.checkAllInstantiated();
64 programInfo.checkMSAAAndMIPSAreResolved();
Robert Phillips12c46292019-04-23 07:36:17 -040065#endif
Robert Phillipsa91e0b72017-05-01 13:12:20 -040066
Robert Phillips901aff02019-10-08 12:32:56 -040067 if (programInfo.primProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
Chris Dalton4386ad12020-02-19 16:42:06 -070068 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
69 return;
egdaniel9cb63402016-06-23 08:37:05 -070070 }
Chris Dalton4386ad12020-02-19 16:42:06 -070071
72 if (!this->onBindPipeline(programInfo, drawBounds)) {
73 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
74 return;
75 }
Robert Phillips901aff02019-10-08 12:32:56 -040076
Chris Dalton8c4cafd2019-04-15 19:14:36 -060077#ifdef SK_DEBUG
Robert Phillips901aff02019-10-08 12:32:56 -040078 GrProcessor::CustomFeatures processorFeatures = programInfo.requestedFeatures();
Chris Dalton8c4cafd2019-04-15 19:14:36 -060079 if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
80 // Verify we always have the same sample pattern key, regardless of graphics state.
81 SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
82 == fRenderTarget->renderTargetPriv().getSamplePatternKey());
83 }
84#endif
Chris Dalton4386ad12020-02-19 16:42:06 -070085
86 fDrawPipelineStatus = DrawPipelineStatus::kOk;
87}
88
89void GrOpsRenderPass::drawMeshes(const GrProgramInfo& programInfo, const GrMesh meshes[],
90 int meshCount) {
91 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
92 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
93 this->gpu()->stats()->incNumFailedDraws();
94 return;
95 }
96
97#ifdef SK_DEBUG
98 if (int numDynamicStateArrays = programInfo.numDynamicStateArrays()) {
99 SkASSERT(meshCount == numDynamicStateArrays);
100 }
101 for (int i = 0; i < meshCount; ++i) {
102 SkASSERT(programInfo.primProc().hasVertexAttributes() ==
103 SkToBool(meshes[i].vertexBuffer()));
104 SkASSERT(programInfo.primProc().hasInstanceAttributes() ==
105 SkToBool(meshes[i].instanceBuffer()));
106 if (GrPrimitiveRestart::kYes == meshes[i].primitiveRestart()) {
107 SkASSERT(this->gpu()->caps()->usePrimitiveRestart());
108 }
109 }
110#endif
111
112 if (meshCount) {
113 this->onDrawMeshes(programInfo, meshes, meshCount);
114 }
egdaniel9cb63402016-06-23 08:37:05 -0700115}