blob: 3e18d5b6164ec83c3081a25eab2bc3657f8a5d6d [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
Chris Daltonb832ce62020-01-06 19:49:37 -070018GrPipeline::GrPipeline(const InitArgs& args, sk_sp<const GrXferProcessor> xferProcessor,
19 const GrAppliedHardClip& hardClip)
Greg Daniel2c3398d2019-06-19 11:58:01 -040020 : fOutputSwizzle(args.fOutputSwizzle) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060021 fFlags = (Flags)args.fInputFlags;
Chris Daltonb832ce62020-01-06 19:49:37 -070022 if (hardClip.hasStencilClip()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060023 fFlags |= Flags::kHasStencilClip;
Brian Salomon54d212e2017-03-21 14:22:38 -040024 }
Chris Daltonb832ce62020-01-06 19:49:37 -070025 if (hardClip.scissorState().enabled()) {
Chris Dalton2e7ed262020-02-21 15:17:59 -070026 fFlags |= Flags::kScissorTestEnabled;
Brian Salomon49348902018-06-26 09:12:38 -040027 }
28
Chris Daltonb832ce62020-01-06 19:49:37 -070029 fWindowRectsState = hardClip.windowRectsState();
Chris Dalton4328e922020-01-29 13:16:14 -070030 this->setUserStencil(args.fUserStencil);
Brian Salomon54d212e2017-03-21 14:22:38 -040031
Chris Daltonb832ce62020-01-06 19:49:37 -070032 fXferProcessor = std::move(xferProcessor);
Brian Salomon189098e72017-01-19 09:55:19 -050033
Greg Daniel524e28b2019-11-01 11:48:53 -040034 if (args.fDstProxyView.proxy()) {
Greg Daniel524e28b2019-11-01 11:48:53 -040035 fDstProxyView = args.fDstProxyView.proxyView();
36 fDstTextureOffset = args.fDstProxyView.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040037 }
Chris Daltonb832ce62020-01-06 19:49:37 -070038}
Brian Salomon31853842017-03-28 16:32:05 -040039
Chris Daltonb832ce62020-01-06 19:49:37 -070040GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors,
41 GrAppliedClip&& appliedClip)
42 : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) {
43 SkASSERT(processors.isFinalized());
Brian Salomone5b399e2017-07-19 13:50:54 -040044 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomon91326c32017-08-09 16:02:19 -040045 fNumColorProcessors = processors.numColorFragmentProcessors();
Chris Dalton69824002017-10-31 00:37:52 -060046 int numTotalProcessors = fNumColorProcessors +
47 processors.numCoverageFragmentProcessors() +
48 appliedClip.numClipCoverageFragmentProcessors();
Brian Salomonb5cb6832017-02-24 11:01:15 -050049 fFragmentProcessors.reset(numTotalProcessors);
Robert Phillips82774f82019-06-20 14:38:27 -040050
bsalomonac856c92015-08-27 06:30:17 -070051 int currFPIdx = 0;
Brian Salomon91326c32017-08-09 16:02:19 -040052 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040053 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
bsalomonae59b772014-11-19 08:23:49 -080054 }
Brian Salomon91326c32017-08-09 16:02:19 -040055 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040056 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
egdaniel9cf45bf2014-10-08 06:49:10 -070057 }
Chris Dalton69824002017-10-31 00:37:52 -060058 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
59 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
Robert Phillips82774f82019-06-20 14:38:27 -040060 }
egdanielc0648242014-09-22 13:17:02 -070061}
62
Robert Phillipsd0fe8752019-01-31 14:13:59 -050063GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
Greg Daniel524e28b2019-11-01 11:48:53 -040064 auto proxy = fDstProxyView.proxy();
65 if (proxy && proxy->peekTexture() == texture) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040066 return kTexture_GrXferBarrierType;
67 }
68 return this->getXferProcessor().xferBarrierType(caps);
69}
70
Chris Daltonc3318f02019-07-19 14:20:53 -060071GrPipeline::GrPipeline(GrScissorTest scissorTest, sk_sp<const GrXferProcessor> xp,
Greg Daniel2c3398d2019-06-19 11:58:01 -040072 const GrSwizzle& outputSwizzle, InputFlags inputFlags,
Chris Daltond7291ba2019-03-07 14:17:03 -070073 const GrUserStencilSettings* userStencil)
Robert Phillipsd0fe8752019-01-31 14:13:59 -050074 : fWindowRectsState()
Chris Daltonbaa1b352019-04-03 12:03:00 -060075 , fFlags((Flags)inputFlags)
Chris Daltonc3318f02019-07-19 14:20:53 -060076 , fXferProcessor(std::move(xp))
Greg Daniel2c3398d2019-06-19 11:58:01 -040077 , fOutputSwizzle(outputSwizzle) {
Chris Dalton916c4982018-08-15 00:53:25 -060078 if (GrScissorTest::kEnabled == scissorTest) {
Chris Dalton2e7ed262020-02-21 15:17:59 -070079 fFlags |= Flags::kScissorTestEnabled;
Chris Dalton46983b72017-06-06 12:27:16 -060080 }
Chris Dalton4328e922020-01-29 13:16:14 -070081 this->setUserStencil(userStencil);
Chris Dalton46983b72017-06-06 12:27:16 -060082}
Jim Van Verth1223e7f2019-02-28 17:38:35 -050083
Chris Daltonb204e4c2019-11-07 12:43:13 -070084void GrPipeline::genKey(GrProcessorKeyBuilder* b, const GrCaps& caps) const {
85 // kSnapVerticesToPixelCenters is implemented in a shader.
86 InputFlags ignoredFlags = InputFlags::kSnapVerticesToPixelCenters;
87 if (!caps.multisampleDisableSupport()) {
88 // Ganesh will omit kHWAntialias regardless multisampleDisableSupport.
89 ignoredFlags |= InputFlags::kHWAntialias;
90 }
91 b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags);
92
Chris Daltonbbb3f642019-07-24 12:25:08 -040093 const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
Jim Van Verth1223e7f2019-02-28 17:38:35 -050094
95 static const uint32_t kBlendWriteShift = 1;
96 static const uint32_t kBlendCoeffShift = 5;
Brian Salomon4dea72a2019-12-18 10:43:10 -050097 static_assert(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
98 static_assert(kFirstAdvancedGrBlendEquation - 1 < 4);
Jim Van Verth1223e7f2019-02-28 17:38:35 -050099
Chris Daltonb204e4c2019-11-07 12:43:13 -0700100 uint32_t blendKey = blendInfo.fWriteColor;
101 blendKey |= (blendInfo.fSrcBlend << kBlendWriteShift);
102 blendKey |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
103 blendKey |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500104
Chris Daltonb204e4c2019-11-07 12:43:13 -0700105 b->add32(blendKey);
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500106}
Brian Salomonc241b582019-11-27 08:57:17 -0500107
108void GrPipeline::visitProxies(const GrOp::VisitProxyFunc& func) const {
109 // This iteration includes any clip coverage FPs
110 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(*this)) {
111 bool mipped = (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter());
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000112 func(sampler.view().proxy(), GrMipMapped(mipped));
Brian Salomonc241b582019-11-27 08:57:17 -0500113 }
114 if (fDstProxyView.asTextureProxy()) {
115 func(fDstProxyView.asTextureProxy(), GrMipMapped::kNo);
116 }
117}