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 | |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 10 | #include "GrDrawTargetCaps.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 11 | #include "GrGpu.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 12 | #include "GrPipelineBuilder.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 13 | #include "GrProcOptInfo.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 14 | #include "GrXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 15 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 16 | GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 17 | const GrPrimitiveProcessor* primProc, |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 18 | const GrDrawTargetCaps& caps, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 19 | const GrScissorState& scissorState, |
joshualitt | b77e4b6 | 2015-01-21 10:16:17 -0800 | [diff] [blame] | 20 | const GrDeviceCoordTexture* dstCopy) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 21 | const GrProcOptInfo& colorPOI = pipelineBuilder.colorProcInfo(primProc); |
| 22 | const GrProcOptInfo& coveragePOI = pipelineBuilder.coverageProcInfo(primProc); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 23 | |
| 24 | // Create XferProcessor from DS's XPFactory |
| 25 | SkAutoTUnref<GrXferProcessor> xferProcessor( |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 26 | pipelineBuilder.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); |
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 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 33 | GrXferProcessor::OptFlags optFlags; |
| 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 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 44 | // When path rendering the stencil settings are not always set on the GrPipelineBuilder |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 45 | // 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] | 46 | // null GrPipeline. |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 47 | if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) { |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 48 | // 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; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 51 | fDrawFace = GrPipelineBuilder::kInvalid_DrawFace; |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 52 | return; |
| 53 | } |
| 54 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 55 | fRenderTarget.reset(pipelineBuilder.fRenderTarget.get()); |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 56 | SkASSERT(fRenderTarget); |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 57 | fScissorState = scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 58 | fStencilSettings = pipelineBuilder.getStencil(); |
| 59 | fDrawFace = pipelineBuilder.getDrawFace(); |
| 60 | // TODO move this out of GrPipeline |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 61 | if (dstCopy) { |
| 62 | fDstCopy = *dstCopy; |
| 63 | } |
| 64 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 65 | fFlags = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 66 | if (pipelineBuilder.isHWAntialias()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 67 | fFlags |= kHWAA_Flag; |
| 68 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 69 | if (pipelineBuilder.isDither()) { |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 70 | fFlags |= kDither_Flag; |
| 71 | } |
| 72 | |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 73 | int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 74 | |
| 75 | // 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] | 76 | // GrPipelineBuilder's coverageProcInfo (like color above) to set this initial information. |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 77 | int firstCoverageStageIdx = 0; |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 78 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 79 | GrXferProcessor::BlendInfo blendInfo; |
| 80 | fXferProcessor->getBlendInfo(&blendInfo); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 81 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 82 | this->adjustProgramFromOptimizations(pipelineBuilder, optFlags, colorPOI, coveragePOI, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 83 | &firstColorStageIdx, &firstCoverageStageIdx); |
| 84 | |
egdaniel | 71e236c | 2015-01-20 06:34:51 -0800 | [diff] [blame] | 85 | fDescInfo.fReadsDst = fXferProcessor->willReadDstColor(); |
| 86 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 87 | bool usesLocalCoords = false; |
| 88 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 89 | // Copy Stages from PipelineBuilder to Pipeline |
| 90 | for (int i = firstColorStageIdx; i < pipelineBuilder.numColorStages(); ++i) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 91 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 92 | GrPendingFragmentStage, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 93 | (pipelineBuilder.fColorStages[i])); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 94 | usesLocalCoords = usesLocalCoords || |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 95 | pipelineBuilder.fColorStages[i].processor()->usesLocalCoords(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 96 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 97 | |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 98 | fNumColorStages = fFragmentStages.count(); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 99 | for (int i = firstCoverageStageIdx; i < pipelineBuilder.numCoverageStages(); ++i) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 100 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 101 | GrPendingFragmentStage, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 102 | (pipelineBuilder.fCoverageStages[i])); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 103 | usesLocalCoords = usesLocalCoords || |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 104 | pipelineBuilder.fCoverageStages[i].processor()->usesLocalCoords(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 105 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 106 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 107 | // let the GP init the batch tracker |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 108 | 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; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 112 | } |
| 113 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 114 | void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder, |
| 115 | GrXferProcessor::OptFlags flags, |
| 116 | const GrProcOptInfo& colorPOI, |
| 117 | const GrProcOptInfo& coveragePOI, |
| 118 | int* firstColorStageIdx, |
| 119 | int* firstCoverageStageIdx) { |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 120 | fDescInfo.fReadsFragPosition = false; |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 121 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 122 | if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || |
| 123 | (flags & GrXferProcessor::kOverrideColor_OptFlag)) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 124 | *firstColorStageIdx = pipelineBuilder.numColorStages(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 125 | } else { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 126 | fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 127 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 128 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 129 | if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 130 | *firstCoverageStageIdx = pipelineBuilder.numCoverageStages(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 131 | } else { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 132 | if (coveragePOI.readsFragPosition()) { |
| 133 | fDescInfo.fReadsFragPosition = true; |
| 134 | } |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 138 | //////////////////////////////////////////////////////////////////////////////// |
| 139 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 140 | bool GrPipeline::isEqual(const GrPipeline& that) const { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 141 | if (this->getRenderTarget() != that.getRenderTarget() || |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 142 | this->fFragmentStages.count() != that.fFragmentStages.count() || |
| 143 | this->fNumColorStages != that.fNumColorStages || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 144 | this->fScissorState != that.fScissorState || |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 145 | this->fFlags != that.fFlags || |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 146 | this->fStencilSettings != that.fStencilSettings || |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 147 | this->fDrawFace != that.fDrawFace || |
| 148 | this->fDstCopy.texture() != that.fDstCopy.texture()) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 152 | if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
| 153 | return false; |
| 154 | } |
| 155 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 156 | // The program desc comparison should have already assured that the stage counts match. |
| 157 | SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 158 | for (int i = 0; i < this->numFragmentStages(); i++) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 159 | |
| 160 | if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 161 | return false; |
| 162 | } |
| 163 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 164 | return true; |
| 165 | } |
| 166 | |