blob: 9a44ce4167e36c80018bcb81d024b2eb8efd9384 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrPipeline.h"
egdaniel3658f382014-09-15 07:01:59 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrCaps.h"
12#include "src/gpu/GrGpu.h"
13#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070015
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070017
Brian Salomon49348902018-06-26 09:12:38 -040018GrPipeline::GrPipeline(const InitArgs& args,
19 GrProcessorSet&& processors,
Greg Daniel2c3398d2019-06-19 11:58:01 -040020 GrAppliedClip&& appliedClip)
21 : fOutputSwizzle(args.fOutputSwizzle) {
Brian Salomon91326c32017-08-09 16:02:19 -040022 SkASSERT(processors.isFinalized());
Brian Salomon92aee3d2016-12-21 09:20:25 -050023
Chris Daltonbaa1b352019-04-03 12:03:00 -060024 fFlags = (Flags)args.fInputFlags;
Brian Salomonbfd18cd2017-08-09 16:27:09 -040025 if (appliedClip.hasStencilClip()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060026 fFlags |= Flags::kHasStencilClip;
Brian Salomon54d212e2017-03-21 14:22:38 -040027 }
Brian Salomond818ebf2018-07-02 14:08:49 +000028 if (appliedClip.scissorState().enabled()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060029 fFlags |= Flags::kScissorEnabled;
Brian Salomon49348902018-06-26 09:12:38 -040030 }
31
Brian Salomonbfd18cd2017-08-09 16:27:09 -040032 fWindowRectsState = appliedClip.windowRectsState();
Chris Daltonbaa1b352019-04-03 12:03:00 -060033 if (!args.fUserStencil->isDisabled(fFlags & Flags::kHasStencilClip)) {
34 fFlags |= Flags::kStencilEnabled;
Brian Salomon54d212e2017-03-21 14:22:38 -040035 }
36
37 fUserStencilSettings = args.fUserStencil;
38
Brian Salomon91326c32017-08-09 16:02:19 -040039 fXferProcessor = processors.refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050040
Greg Daniel524e28b2019-11-01 11:48:53 -040041 if (args.fDstProxyView.proxy()) {
Greg Daniel524e28b2019-11-01 11:48:53 -040042 fDstProxyView = args.fDstProxyView.proxyView();
43 fDstTextureOffset = args.fDstProxyView.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040044 }
Brian Salomon31853842017-03-28 16:32:05 -040045
Brian Salomone5b399e2017-07-19 13:50:54 -040046 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomon91326c32017-08-09 16:02:19 -040047 fNumColorProcessors = processors.numColorFragmentProcessors();
Chris Dalton69824002017-10-31 00:37:52 -060048 int numTotalProcessors = fNumColorProcessors +
49 processors.numCoverageFragmentProcessors() +
50 appliedClip.numClipCoverageFragmentProcessors();
Brian Salomonb5cb6832017-02-24 11:01:15 -050051 fFragmentProcessors.reset(numTotalProcessors);
Robert Phillips82774f82019-06-20 14:38:27 -040052
bsalomonac856c92015-08-27 06:30:17 -070053 int currFPIdx = 0;
Brian Salomon91326c32017-08-09 16:02:19 -040054 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040055 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
bsalomonae59b772014-11-19 08:23:49 -080056 }
Brian Salomon91326c32017-08-09 16:02:19 -040057 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040058 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
egdaniel9cf45bf2014-10-08 06:49:10 -070059 }
Chris Dalton69824002017-10-31 00:37:52 -060060 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
61 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
Robert Phillips82774f82019-06-20 14:38:27 -040062 }
egdanielc0648242014-09-22 13:17:02 -070063}
64
Robert Phillipsd0fe8752019-01-31 14:13:59 -050065GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
Greg Daniel524e28b2019-11-01 11:48:53 -040066 auto proxy = fDstProxyView.proxy();
67 if (proxy && proxy->peekTexture() == texture) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040068 return kTexture_GrXferBarrierType;
69 }
70 return this->getXferProcessor().xferBarrierType(caps);
71}
72
Chris Daltonc3318f02019-07-19 14:20:53 -060073GrPipeline::GrPipeline(GrScissorTest scissorTest, sk_sp<const GrXferProcessor> xp,
Greg Daniel2c3398d2019-06-19 11:58:01 -040074 const GrSwizzle& outputSwizzle, InputFlags inputFlags,
Chris Daltond7291ba2019-03-07 14:17:03 -070075 const GrUserStencilSettings* userStencil)
Robert Phillipsd0fe8752019-01-31 14:13:59 -050076 : fWindowRectsState()
Chris Daltond7291ba2019-03-07 14:17:03 -070077 , fUserStencilSettings(userStencil)
Chris Daltonbaa1b352019-04-03 12:03:00 -060078 , fFlags((Flags)inputFlags)
Chris Daltonc3318f02019-07-19 14:20:53 -060079 , fXferProcessor(std::move(xp))
Robert Phillips2890fbf2017-07-26 15:48:41 -040080 , fFragmentProcessors()
Greg Daniel2c3398d2019-06-19 11:58:01 -040081 , fNumColorProcessors(0)
82 , fOutputSwizzle(outputSwizzle) {
Chris Dalton916c4982018-08-15 00:53:25 -060083 if (GrScissorTest::kEnabled == scissorTest) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060084 fFlags |= Flags::kScissorEnabled;
Chris Dalton46983b72017-06-06 12:27:16 -060085 }
Chris Daltond7291ba2019-03-07 14:17:03 -070086 if (!userStencil->isDisabled(false)) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060087 fFlags |= Flags::kStencilEnabled;
Chris Daltond7291ba2019-03-07 14:17:03 -070088 }
Chris Dalton46983b72017-06-06 12:27:16 -060089}
Jim Van Verth1223e7f2019-02-28 17:38:35 -050090
Chris Daltonb204e4c2019-11-07 12:43:13 -070091void GrPipeline::genKey(GrProcessorKeyBuilder* b, const GrCaps& caps) const {
92 // kSnapVerticesToPixelCenters is implemented in a shader.
93 InputFlags ignoredFlags = InputFlags::kSnapVerticesToPixelCenters;
94 if (!caps.multisampleDisableSupport()) {
95 // Ganesh will omit kHWAntialias regardless multisampleDisableSupport.
96 ignoredFlags |= InputFlags::kHWAntialias;
97 }
98 b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags);
99
Chris Daltonbbb3f642019-07-24 12:25:08 -0400100 const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500101
102 static const uint32_t kBlendWriteShift = 1;
103 static const uint32_t kBlendCoeffShift = 5;
Brian Salomonb0047b52019-12-05 19:52:25 +0000104 GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
105 GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4);
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500106
Chris Daltonb204e4c2019-11-07 12:43:13 -0700107 uint32_t blendKey = blendInfo.fWriteColor;
108 blendKey |= (blendInfo.fSrcBlend << kBlendWriteShift);
109 blendKey |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
110 blendKey |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500111
Chris Daltonb204e4c2019-11-07 12:43:13 -0700112 b->add32(blendKey);
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500113}
Brian Salomonc241b582019-11-27 08:57:17 -0500114
115void GrPipeline::visitProxies(const GrOp::VisitProxyFunc& func) const {
116 // This iteration includes any clip coverage FPs
117 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(*this)) {
118 bool mipped = (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter());
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000119 func(sampler.view().proxy(), GrMipMapped(mipped));
Brian Salomonc241b582019-11-27 08:57:17 -0500120 }
121 if (fDstProxyView.asTextureProxy()) {
122 func(fDstProxyView.asTextureProxy(), GrMipMapped::kNo);
123 }
124}