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, |
| 22 | const GrDeviceCoordTexture* dstCopy) { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 23 | // Create XferProcessor from DS's XPFactory |
| 24 | SkAutoTUnref<GrXferProcessor> xferProcessor( |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 25 | pipelineBuilder.getXPFactory()->createXferProcessor(colorPOI, coveragePOI, dstCopy, caps)); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 26 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 27 | GrColor overrideColor = GrColor_ILLEGAL; |
| 28 | if (colorPOI.firstEffectiveStageIndex() != 0) { |
| 29 | overrideColor = colorPOI.inputColorToEffectiveStage(); |
| 30 | } |
| 31 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 32 | GrXferProcessor::OptFlags optFlags; |
| 33 | if (xferProcessor) { |
| 34 | fXferProcessor.reset(xferProcessor.get()); |
| 35 | |
| 36 | optFlags = xferProcessor->getOptimizations(colorPOI, |
| 37 | coveragePOI, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 38 | pipelineBuilder.getStencil().doesWrite(), |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 39 | &overrideColor, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 40 | caps); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 41 | } |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 42 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 43 | // When path rendering the stencil settings are not always set on the GrPipelineBuilder |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 44 | // 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] | 45 | // null GrPipeline. |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 46 | if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) { |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 47 | // Set the fields that don't default init and return. The lack of a render target will |
| 48 | // indicate that this can be skipped. |
| 49 | fFlags = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 50 | fDrawFace = GrPipelineBuilder::kInvalid_DrawFace; |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 51 | return; |
| 52 | } |
| 53 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 54 | fRenderTarget.reset(pipelineBuilder.fRenderTarget.get()); |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 55 | SkASSERT(fRenderTarget); |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 56 | fScissorState = scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 57 | fStencilSettings = pipelineBuilder.getStencil(); |
| 58 | fDrawFace = pipelineBuilder.getDrawFace(); |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 59 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 60 | fFlags = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 61 | if (pipelineBuilder.isHWAntialias()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 62 | fFlags |= kHWAA_Flag; |
| 63 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 64 | if (pipelineBuilder.isDither()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 65 | fFlags |= kDither_Flag; |
| 66 | } |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 67 | if (pipelineBuilder.snapVerticesToPixelCenters()) { |
| 68 | fFlags |= kSnapVertices_Flag; |
| 69 | } |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 70 | |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 71 | int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 72 | |
| 73 | // 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] | 74 | // GrPipelineBuilder's coverageProcInfo (like color above) to set this initial information. |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 75 | int firstCoverageStageIdx = 0; |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 76 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 77 | this->adjustProgramFromOptimizations(pipelineBuilder, optFlags, colorPOI, coveragePOI, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 78 | &firstColorStageIdx, &firstCoverageStageIdx); |
| 79 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 80 | bool usesLocalCoords = false; |
| 81 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 82 | // Copy Stages from PipelineBuilder to Pipeline |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 83 | for (int i = firstColorStageIdx; i < pipelineBuilder.numColorFragmentStages(); ++i) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 84 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 85 | GrPendingFragmentStage, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 86 | (pipelineBuilder.fColorStages[i])); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 87 | usesLocalCoords = usesLocalCoords || |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 88 | pipelineBuilder.fColorStages[i].processor()->usesLocalCoords(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 89 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 90 | |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 91 | fNumColorStages = fFragmentStages.count(); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 92 | for (int i = firstCoverageStageIdx; i < pipelineBuilder.numCoverageFragmentStages(); ++i) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 93 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 94 | GrPendingFragmentStage, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 95 | (pipelineBuilder.fCoverageStages[i])); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 96 | usesLocalCoords = usesLocalCoords || |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 97 | pipelineBuilder.fCoverageStages[i].processor()->usesLocalCoords(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 98 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 99 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 100 | // let the GP init the batch tracker |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 101 | fInitBT.fColorIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag); |
| 102 | fInitBT.fOverrideColor = fInitBT.fColorIgnored ? GrColor_ILLEGAL : overrideColor; |
| 103 | fInitBT.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag); |
| 104 | fInitBT.fUsesLocalCoords = usesLocalCoords; |
egdaniel | f7c2d55 | 2015-02-13 12:11:00 -0800 | [diff] [blame] | 105 | fInitBT.fCanTweakAlphaForCoverage = |
| 106 | SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 107 | } |
| 108 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 109 | void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder, |
| 110 | GrXferProcessor::OptFlags flags, |
| 111 | const GrProcOptInfo& colorPOI, |
| 112 | const GrProcOptInfo& coveragePOI, |
| 113 | int* firstColorStageIdx, |
| 114 | int* firstCoverageStageIdx) { |
egdaniel | 060a52c | 2015-04-07 07:31:11 -0700 | [diff] [blame] | 115 | fReadsFragPosition = fXferProcessor->willReadFragmentPosition(); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 116 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 117 | if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || |
| 118 | (flags & GrXferProcessor::kOverrideColor_OptFlag)) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 119 | *firstColorStageIdx = pipelineBuilder.numColorFragmentStages(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 120 | } else { |
egdaniel | 060a52c | 2015-04-07 07:31:11 -0700 | [diff] [blame] | 121 | if (coveragePOI.readsFragPosition()) { |
| 122 | fReadsFragPosition = true; |
| 123 | } |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 124 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 125 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 126 | if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 127 | *firstCoverageStageIdx = pipelineBuilder.numCoverageFragmentStages(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 128 | } else { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 129 | if (coveragePOI.readsFragPosition()) { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 130 | fReadsFragPosition = true; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 131 | } |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 135 | //////////////////////////////////////////////////////////////////////////////// |
| 136 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 137 | bool GrPipeline::isEqual(const GrPipeline& that) const { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 138 | if (this->getRenderTarget() != that.getRenderTarget() || |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 139 | this->fFragmentStages.count() != that.fFragmentStages.count() || |
| 140 | this->fNumColorStages != that.fNumColorStages || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 141 | this->fScissorState != that.fScissorState || |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 142 | this->fFlags != that.fFlags || |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 143 | this->fStencilSettings != that.fStencilSettings || |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 144 | this->fDrawFace != that.fDrawFace) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 145 | return false; |
| 146 | } |
| 147 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 148 | if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
| 149 | return false; |
| 150 | } |
| 151 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 152 | // The program desc comparison should have already assured that the stage counts match. |
| 153 | SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 154 | for (int i = 0; i < this->numFragmentStages(); i++) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 155 | |
| 156 | if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 157 | return false; |
| 158 | } |
| 159 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 160 | return true; |
| 161 | } |
| 162 | |