egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 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 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 8 | #include "GrPipeline.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 9 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 11 | #include "GrBatch.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 12 | #include "GrGpu.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 13 | #include "GrPipelineBuilder.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 14 | #include "GrProcOptInfo.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 15 | #include "GrXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 16 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 17 | GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 18 | const GrProcOptInfo& colorPOI, |
| 19 | const GrProcOptInfo& coveragePOI, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 20 | const GrCaps& caps, |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 21 | const GrScissorState& scissorState, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 22 | const GrXferProcessor::DstTexture* dstTexture) { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 23 | // Create XferProcessor from DS's XPFactory |
| 24 | SkAutoTUnref<GrXferProcessor> xferProcessor( |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 25 | pipelineBuilder.getXPFactory()->createXferProcessor( |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 26 | colorPOI, coveragePOI, pipelineBuilder.hasMixedSamples(), dstTexture, caps)); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 27 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 28 | GrColor overrideColor = GrColor_ILLEGAL; |
| 29 | if (colorPOI.firstEffectiveStageIndex() != 0) { |
| 30 | overrideColor = colorPOI.inputColorToEffectiveStage(); |
| 31 | } |
| 32 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 33 | GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 34 | if (xferProcessor) { |
| 35 | fXferProcessor.reset(xferProcessor.get()); |
| 36 | |
| 37 | optFlags = xferProcessor->getOptimizations(colorPOI, |
| 38 | coveragePOI, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 39 | pipelineBuilder.getStencil().doesWrite(), |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 40 | &overrideColor, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 41 | caps); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 42 | } |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 43 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 44 | // No need to have an override color if it isn't even going to be used. |
| 45 | if (SkToBool(GrXferProcessor::kIgnoreColor_OptFlag & optFlags)) { |
| 46 | overrideColor = GrColor_ILLEGAL; |
| 47 | } |
| 48 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 49 | // When path rendering the stencil settings are not always set on the GrPipelineBuilder |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 50 | // so we must check the draw type. In cases where we will skip drawing we simply return a |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 51 | // null GrPipeline. |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 52 | if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) { |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 53 | // Set the fields that don't default init and return. The lack of a render target will |
| 54 | // indicate that this can be skipped. |
| 55 | fFlags = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 56 | fDrawFace = GrPipelineBuilder::kInvalid_DrawFace; |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 57 | return; |
| 58 | } |
| 59 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 60 | fRenderTarget.reset(pipelineBuilder.fRenderTarget.get()); |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 61 | SkASSERT(fRenderTarget); |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 62 | fScissorState = scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 63 | fStencilSettings = pipelineBuilder.getStencil(); |
| 64 | fDrawFace = pipelineBuilder.getDrawFace(); |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 65 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 66 | fFlags = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 67 | if (pipelineBuilder.isHWAntialias()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 68 | fFlags |= kHWAA_Flag; |
| 69 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 70 | if (pipelineBuilder.isDither()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 71 | fFlags |= kDither_Flag; |
| 72 | } |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 73 | if (pipelineBuilder.snapVerticesToPixelCenters()) { |
| 74 | fFlags |= kSnapVertices_Flag; |
| 75 | } |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 76 | |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 77 | int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 78 | |
| 79 | // TODO: Once we can handle single or four channel input into coverage stages then we can use |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 80 | // GrPipelineBuilder's coverageProcInfo (like color above) to set this initial information. |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 81 | int firstCoverageStageIdx = 0; |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 82 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 83 | this->adjustProgramFromOptimizations(pipelineBuilder, optFlags, colorPOI, coveragePOI, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 84 | &firstColorStageIdx, &firstCoverageStageIdx); |
| 85 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 86 | bool usesLocalCoords = false; |
| 87 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 88 | // Copy Stages from PipelineBuilder to Pipeline |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 89 | for (int i = firstColorStageIdx; i < pipelineBuilder.numColorFragmentStages(); ++i) { |
joshualitt | 6968428 | 2015-07-13 13:29:13 -0700 | [diff] [blame] | 90 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 91 | GrPendingFragmentStage, |
| 92 | (pipelineBuilder.fColorStages[i])); |
| 93 | usesLocalCoords = usesLocalCoords || |
| 94 | pipelineBuilder.fColorStages[i].processor()->usesLocalCoords(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 95 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 96 | |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 97 | fNumColorStages = fFragmentStages.count(); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 98 | for (int i = firstCoverageStageIdx; i < pipelineBuilder.numCoverageFragmentStages(); ++i) { |
joshualitt | 6968428 | 2015-07-13 13:29:13 -0700 | [diff] [blame] | 99 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 100 | GrPendingFragmentStage, |
| 101 | (pipelineBuilder.fCoverageStages[i])); |
| 102 | usesLocalCoords = usesLocalCoords || |
| 103 | pipelineBuilder.fCoverageStages[i].processor()->usesLocalCoords(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 104 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 105 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 106 | // Setup info we need to pass to GrPrimitiveProcessors that are used with this GrPipeline. |
| 107 | fInfoForPrimitiveProcessor.fFlags = 0; |
| 108 | if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { |
| 109 | fInfoForPrimitiveProcessor.fFlags |= GrPipelineInfo::kReadsColor_GrPipelineInfoFlag; |
| 110 | } |
| 111 | if (GrColor_ILLEGAL != overrideColor) { |
| 112 | fInfoForPrimitiveProcessor.fFlags |= GrPipelineInfo::kUseOverrideColor_GrPipelineInfoFlag; |
| 113 | fInfoForPrimitiveProcessor.fOverrideColor = overrideColor; |
| 114 | } |
| 115 | if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) { |
| 116 | fInfoForPrimitiveProcessor.fFlags |= GrPipelineInfo::kReadsCoverage_GrPipelineInfoFlag; |
| 117 | } |
| 118 | if (usesLocalCoords) { |
| 119 | fInfoForPrimitiveProcessor.fFlags |= GrPipelineInfo::kReadsLocalCoords_GrPipelineInfoFlag; |
| 120 | } |
| 121 | if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag)) { |
| 122 | fInfoForPrimitiveProcessor.fFlags |= |
| 123 | GrPipelineInfo::kCanTweakAlphaForCoverage_GrPipelineInfoFlag; |
| 124 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 125 | } |
| 126 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 127 | void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder, |
| 128 | GrXferProcessor::OptFlags flags, |
| 129 | const GrProcOptInfo& colorPOI, |
| 130 | const GrProcOptInfo& coveragePOI, |
| 131 | int* firstColorStageIdx, |
| 132 | int* firstCoverageStageIdx) { |
egdaniel | 060a52c | 2015-04-07 07:31:11 -0700 | [diff] [blame] | 133 | fReadsFragPosition = fXferProcessor->willReadFragmentPosition(); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 134 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 135 | if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || |
| 136 | (flags & GrXferProcessor::kOverrideColor_OptFlag)) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 137 | *firstColorStageIdx = pipelineBuilder.numColorFragmentStages(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 138 | } else { |
egdaniel | 060a52c | 2015-04-07 07:31:11 -0700 | [diff] [blame] | 139 | if (coveragePOI.readsFragPosition()) { |
| 140 | fReadsFragPosition = true; |
| 141 | } |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 142 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 143 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 144 | if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 145 | *firstCoverageStageIdx = pipelineBuilder.numCoverageFragmentStages(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 146 | } else { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 147 | if (coveragePOI.readsFragPosition()) { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 148 | fReadsFragPosition = true; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 149 | } |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 153 | //////////////////////////////////////////////////////////////////////////////// |
| 154 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 155 | bool GrPipeline::isEqual(const GrPipeline& that) const { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame^] | 156 | // If we point to the same pipeline, then we are necessarily equal |
| 157 | if (this == &that) { |
| 158 | return true; |
| 159 | } |
| 160 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 161 | if (this->getRenderTarget() != that.getRenderTarget() || |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 162 | this->fFragmentStages.count() != that.fFragmentStages.count() || |
| 163 | this->fNumColorStages != that.fNumColorStages || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 164 | this->fScissorState != that.fScissorState || |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 165 | this->fFlags != that.fFlags || |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 166 | this->fStencilSettings != that.fStencilSettings || |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 167 | this->fDrawFace != that.fDrawFace) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 168 | return false; |
| 169 | } |
| 170 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 171 | if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
| 172 | return false; |
| 173 | } |
| 174 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 175 | // The program desc comparison should have already assured that the stage counts match. |
| 176 | SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 177 | for (int i = 0; i < this->numFragmentStages(); i++) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 178 | |
| 179 | if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 180 | return false; |
| 181 | } |
| 182 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 183 | return true; |
| 184 | } |
| 185 | |