blob: c35808e033732c479f6930a052f7f1f1b0a1135e [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
egdaniel3658f382014-09-15 07:01:59 -07003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniel8dd688b2015-01-22 10:16:09 -08008#include "GrPipeline.h"
egdaniel3658f382014-09-15 07:01:59 -07009
egdanielc0648242014-09-22 13:17:02 -070010#include "GrDrawTargetCaps.h"
joshualitt4973d9d2014-11-08 09:24:25 -080011#include "GrGpu.h"
egdaniel8dd688b2015-01-22 10:16:09 -080012#include "GrPipelineBuilder.h"
egdanielb6cbc382014-11-13 11:00:34 -080013#include "GrProcOptInfo.h"
egdaniel95131432014-12-09 11:15:43 -080014#include "GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070015
egdaniel8dd688b2015-01-22 10:16:09 -080016GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder,
joshualitt71c92602015-01-14 08:12:47 -080017 const GrPrimitiveProcessor* primProc,
joshualittdafa4d02014-12-04 08:59:10 -080018 const GrDrawTargetCaps& caps,
bsalomon3e791242014-12-17 13:43:13 -080019 const GrScissorState& scissorState,
joshualittb77e4b62015-01-21 10:16:17 -080020 const GrDeviceCoordTexture* dstCopy) {
egdaniel8dd688b2015-01-22 10:16:09 -080021 const GrProcOptInfo& colorPOI = pipelineBuilder.colorProcInfo(primProc);
22 const GrProcOptInfo& coveragePOI = pipelineBuilder.coverageProcInfo(primProc);
egdaniel95131432014-12-09 11:15:43 -080023
24 // Create XferProcessor from DS's XPFactory
25 SkAutoTUnref<GrXferProcessor> xferProcessor(
egdaniel8dd688b2015-01-22 10:16:09 -080026 pipelineBuilder.getXPFactory()->createXferProcessor(colorPOI, coveragePOI));
egdaniel95131432014-12-09 11:15:43 -080027
joshualitt9b989322014-12-15 14:16:27 -080028 GrColor overrideColor = GrColor_ILLEGAL;
29 if (colorPOI.firstEffectiveStageIndex() != 0) {
30 overrideColor = colorPOI.inputColorToEffectiveStage();
31 }
32
egdaniel95131432014-12-09 11:15:43 -080033 GrXferProcessor::OptFlags optFlags;
34 if (xferProcessor) {
35 fXferProcessor.reset(xferProcessor.get());
36
37 optFlags = xferProcessor->getOptimizations(colorPOI,
38 coveragePOI,
egdaniel8dd688b2015-01-22 10:16:09 -080039 pipelineBuilder.getStencil().doesWrite(),
joshualitt9b989322014-12-15 14:16:27 -080040 &overrideColor,
egdanielc2304142014-12-11 13:15:13 -080041 caps);
egdaniel95131432014-12-09 11:15:43 -080042 }
bsalomonb03c4a32014-11-20 09:56:11 -080043
egdaniel8dd688b2015-01-22 10:16:09 -080044 // When path rendering the stencil settings are not always set on the GrPipelineBuilder
bsalomonb03c4a32014-11-20 09:56:11 -080045 // so we must check the draw type. In cases where we will skip drawing we simply return a
egdaniel8dd688b2015-01-22 10:16:09 -080046 // null GrPipeline.
bsalomon3e791242014-12-17 13:43:13 -080047 if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) {
bsalomonb03c4a32014-11-20 09:56:11 -080048 // Set the fields that don't default init and return. The lack of a render target will
49 // indicate that this can be skipped.
50 fFlags = 0;
egdaniel8dd688b2015-01-22 10:16:09 -080051 fDrawFace = GrPipelineBuilder::kInvalid_DrawFace;
bsalomonb03c4a32014-11-20 09:56:11 -080052 return;
53 }
54
egdaniel8dd688b2015-01-22 10:16:09 -080055 fRenderTarget.reset(pipelineBuilder.fRenderTarget.get());
bsalomonb03c4a32014-11-20 09:56:11 -080056 SkASSERT(fRenderTarget);
joshualitt54e0c122014-11-19 09:38:51 -080057 fScissorState = scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -080058 fStencilSettings = pipelineBuilder.getStencil();
59 fDrawFace = pipelineBuilder.getDrawFace();
60 // TODO move this out of GrPipeline
joshualitt9176e2c2014-11-20 07:28:52 -080061 if (dstCopy) {
62 fDstCopy = *dstCopy;
63 }
64
bsalomon04ddf892014-11-19 12:36:22 -080065 fFlags = 0;
egdaniel8dd688b2015-01-22 10:16:09 -080066 if (pipelineBuilder.isHWAntialias()) {
bsalomon04ddf892014-11-19 12:36:22 -080067 fFlags |= kHWAA_Flag;
68 }
egdaniel8dd688b2015-01-22 10:16:09 -080069 if (pipelineBuilder.isDither()) {
bsalomon04ddf892014-11-19 12:36:22 -080070 fFlags |= kDither_Flag;
71 }
72
egdaniel912b3d22014-11-17 07:45:53 -080073 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex();
egdaniel912b3d22014-11-17 07:45:53 -080074
75 // TODO: Once we can handle single or four channel input into coverage stages then we can use
egdaniel8dd688b2015-01-22 10:16:09 -080076 // GrPipelineBuilder's coverageProcInfo (like color above) to set this initial information.
egdaniel912b3d22014-11-17 07:45:53 -080077 int firstCoverageStageIdx = 0;
egdaniel912b3d22014-11-17 07:45:53 -080078
egdaniel95131432014-12-09 11:15:43 -080079 GrXferProcessor::BlendInfo blendInfo;
80 fXferProcessor->getBlendInfo(&blendInfo);
egdaniel95131432014-12-09 11:15:43 -080081
egdaniel8dd688b2015-01-22 10:16:09 -080082 this->adjustProgramFromOptimizations(pipelineBuilder, optFlags, colorPOI, coveragePOI,
egdaniel95131432014-12-09 11:15:43 -080083 &firstColorStageIdx, &firstCoverageStageIdx);
84
egdaniel71e236c2015-01-20 06:34:51 -080085 fDescInfo.fReadsDst = fXferProcessor->willReadDstColor();
86
joshualitt290c09b2014-12-19 13:45:20 -080087 bool usesLocalCoords = false;
88
egdaniel8dd688b2015-01-22 10:16:09 -080089 // Copy Stages from PipelineBuilder to Pipeline
90 for (int i = firstColorStageIdx; i < pipelineBuilder.numColorStages(); ++i) {
bsalomonae59b772014-11-19 08:23:49 -080091 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
92 GrPendingFragmentStage,
egdaniel8dd688b2015-01-22 10:16:09 -080093 (pipelineBuilder.fColorStages[i]));
joshualitt290c09b2014-12-19 13:45:20 -080094 usesLocalCoords = usesLocalCoords ||
egdaniel8dd688b2015-01-22 10:16:09 -080095 pipelineBuilder.fColorStages[i].processor()->usesLocalCoords();
bsalomonae59b772014-11-19 08:23:49 -080096 }
egdaniel95131432014-12-09 11:15:43 -080097
egdanield9aa2182014-10-09 13:47:05 -070098 fNumColorStages = fFragmentStages.count();
egdaniel8dd688b2015-01-22 10:16:09 -080099 for (int i = firstCoverageStageIdx; i < pipelineBuilder.numCoverageStages(); ++i) {
bsalomonae59b772014-11-19 08:23:49 -0800100 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
101 GrPendingFragmentStage,
egdaniel8dd688b2015-01-22 10:16:09 -0800102 (pipelineBuilder.fCoverageStages[i]));
joshualitt290c09b2014-12-19 13:45:20 -0800103 usesLocalCoords = usesLocalCoords ||
egdaniel8dd688b2015-01-22 10:16:09 -0800104 pipelineBuilder.fCoverageStages[i].processor()->usesLocalCoords();
egdaniel9cf45bf2014-10-08 06:49:10 -0700105 }
joshualitt79f8fae2014-10-28 17:59:26 -0700106
joshualitt87f48d92014-12-04 10:41:40 -0800107 // let the GP init the batch tracker
joshualitt873ad0e2015-01-20 09:08:51 -0800108 fInitBT.fColorIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag);
109 fInitBT.fOverrideColor = fInitBT.fColorIgnored ? GrColor_ILLEGAL : overrideColor;
110 fInitBT.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag);
111 fInitBT.fUsesLocalCoords = usesLocalCoords;
egdanielc0648242014-09-22 13:17:02 -0700112}
113
egdaniel8dd688b2015-01-22 10:16:09 -0800114void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder,
115 GrXferProcessor::OptFlags flags,
116 const GrProcOptInfo& colorPOI,
117 const GrProcOptInfo& coveragePOI,
118 int* firstColorStageIdx,
119 int* firstCoverageStageIdx) {
joshualittdafa4d02014-12-04 08:59:10 -0800120 fDescInfo.fReadsFragPosition = false;
egdaniela7dc0a82014-09-17 08:25:05 -0700121
joshualitt9b989322014-12-15 14:16:27 -0800122 if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) ||
123 (flags & GrXferProcessor::kOverrideColor_OptFlag)) {
egdaniel8dd688b2015-01-22 10:16:09 -0800124 *firstColorStageIdx = pipelineBuilder.numColorStages();
egdaniel95131432014-12-09 11:15:43 -0800125 } else {
egdaniel95131432014-12-09 11:15:43 -0800126 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition();
egdaniela7dc0a82014-09-17 08:25:05 -0700127 }
egdaniel95131432014-12-09 11:15:43 -0800128
joshualitt9b989322014-12-15 14:16:27 -0800129 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) {
egdaniel8dd688b2015-01-22 10:16:09 -0800130 *firstCoverageStageIdx = pipelineBuilder.numCoverageStages();
egdaniel95131432014-12-09 11:15:43 -0800131 } else {
egdaniel95131432014-12-09 11:15:43 -0800132 if (coveragePOI.readsFragPosition()) {
133 fDescInfo.fReadsFragPosition = true;
134 }
egdaniela7dc0a82014-09-17 08:25:05 -0700135 }
136}
137
egdaniel89af44a2014-09-26 06:15:04 -0700138////////////////////////////////////////////////////////////////////////////////
139
egdaniel8dd688b2015-01-22 10:16:09 -0800140bool GrPipeline::isEqual(const GrPipeline& that) const {
egdaniel89af44a2014-09-26 06:15:04 -0700141 if (this->getRenderTarget() != that.getRenderTarget() ||
joshualittdafa4d02014-12-04 08:59:10 -0800142 this->fFragmentStages.count() != that.fFragmentStages.count() ||
143 this->fNumColorStages != that.fNumColorStages ||
joshualitt54e0c122014-11-19 09:38:51 -0800144 this->fScissorState != that.fScissorState ||
bsalomon04ddf892014-11-19 12:36:22 -0800145 this->fFlags != that.fFlags ||
egdaniel89af44a2014-09-26 06:15:04 -0700146 this->fStencilSettings != that.fStencilSettings ||
joshualitt9176e2c2014-11-20 07:28:52 -0800147 this->fDrawFace != that.fDrawFace ||
148 this->fDstCopy.texture() != that.fDstCopy.texture()) {
egdaniel89af44a2014-09-26 06:15:04 -0700149 return false;
150 }
151
egdanielc2304142014-12-11 13:15:13 -0800152 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) {
153 return false;
154 }
155
bsalomonae59b772014-11-19 08:23:49 -0800156 // The program desc comparison should have already assured that the stage counts match.
157 SkASSERT(this->numFragmentStages() == that.numFragmentStages());
egdanield9aa2182014-10-09 13:47:05 -0700158 for (int i = 0; i < this->numFragmentStages(); i++) {
bsalomonae59b772014-11-19 08:23:49 -0800159
160 if (this->getFragmentStage(i) != that.getFragmentStage(i)) {
egdaniel89af44a2014-09-26 06:15:04 -0700161 return false;
162 }
163 }
egdaniel89af44a2014-09-26 06:15:04 -0700164 return true;
165}
166