blob: 0555c236cd7b7a3a1b6c0f2732febc99a47afe6a [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"
Brian Salomoneebe7352020-12-09 16:37:04 -050013#include "src/gpu/GrSurfaceDrawContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrXferProcessor.h"
John Stiles010d0882021-06-03 20:28:41 -040015#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
16#include "src/gpu/glsl/GrGLSLUniformHandler.h"
egdaniel3658f382014-09-15 07:01:59 -070017
Brian Salomon982f5462020-03-30 12:52:33 -040018GrPipeline::GrPipeline(const InitArgs& args,
19 sk_sp<const GrXferProcessor> xferProcessor,
Chris Daltonb832ce62020-01-06 19:49:37 -070020 const GrAppliedHardClip& hardClip)
Greg Daniel87fab9f2021-06-07 15:18:23 -040021 : fDstProxy(args.fDstProxyView)
22 , fWindowRectsState(hardClip.windowRectsState())
23 , fXferProcessor(std::move(xferProcessor))
24 , fWriteSwizzle(args.fWriteSwizzle) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060025 fFlags = (Flags)args.fInputFlags;
Chris Daltonb832ce62020-01-06 19:49:37 -070026 if (hardClip.hasStencilClip()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060027 fFlags |= Flags::kHasStencilClip;
Brian Salomon54d212e2017-03-21 14:22:38 -040028 }
Chris Daltonb832ce62020-01-06 19:49:37 -070029 if (hardClip.scissorState().enabled()) {
Chris Dalton2e7ed262020-02-21 15:17:59 -070030 fFlags |= Flags::kScissorTestEnabled;
Brian Salomon49348902018-06-26 09:12:38 -040031 }
Greg Daniel87fab9f2021-06-07 15:18:23 -040032 // If we have any special dst sample flags we better also have a dst proxy
33 SkASSERT(this->dstSampleFlags() == GrDstSampleFlags::kNone || this->dstProxyView());
Chris Daltonb832ce62020-01-06 19:49:37 -070034}
Brian Salomon31853842017-03-28 16:32:05 -040035
Chris Daltonb832ce62020-01-06 19:49:37 -070036GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors,
37 GrAppliedClip&& appliedClip)
38 : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) {
39 SkASSERT(processors.isFinalized());
Brian Salomone5b399e2017-07-19 13:50:54 -040040 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
John Stiles29d3e222020-07-21 17:28:12 -040041 fNumColorProcessors = processors.hasColorFragmentProcessor() ? 1 : 0;
Chris Dalton69824002017-10-31 00:37:52 -060042 int numTotalProcessors = fNumColorProcessors +
John Stiles29d3e222020-07-21 17:28:12 -040043 (processors.hasCoverageFragmentProcessor() ? 1 : 0) +
John Stiles59e18dc2020-07-22 18:18:12 -040044 (appliedClip.hasCoverageFragmentProcessor() ? 1 : 0);
Brian Salomonb5cb6832017-02-24 11:01:15 -050045 fFragmentProcessors.reset(numTotalProcessors);
Robert Phillips82774f82019-06-20 14:38:27 -040046
bsalomonac856c92015-08-27 06:30:17 -070047 int currFPIdx = 0;
John Stiles29d3e222020-07-21 17:28:12 -040048 if (processors.hasColorFragmentProcessor()) {
49 fFragmentProcessors[currFPIdx++] = processors.detachColorFragmentProcessor();
bsalomonae59b772014-11-19 08:23:49 -080050 }
John Stiles29d3e222020-07-21 17:28:12 -040051 if (processors.hasCoverageFragmentProcessor()) {
52 fFragmentProcessors[currFPIdx++] = processors.detachCoverageFragmentProcessor();
egdaniel9cf45bf2014-10-08 06:49:10 -070053 }
John Stiles59e18dc2020-07-22 18:18:12 -040054 if (appliedClip.hasCoverageFragmentProcessor()) {
55 fFragmentProcessors[currFPIdx++] = appliedClip.detachCoverageFragmentProcessor();
Robert Phillips82774f82019-06-20 14:38:27 -040056 }
egdanielc0648242014-09-22 13:17:02 -070057}
58
Greg Danield358cbe2020-09-11 09:33:54 -040059GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
Greg Daniel87fab9f2021-06-07 15:18:23 -040060 if (this->dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040061 return kTexture_GrXferBarrierType;
62 }
63 return this->getXferProcessor().xferBarrierType(caps);
64}
65
Brian Salomon982f5462020-03-30 12:52:33 -040066GrPipeline::GrPipeline(GrScissorTest scissorTest,
67 sk_sp<const GrXferProcessor> xp,
68 const GrSwizzle& writeSwizzle,
Chris Dalton1b6a43c2020-09-25 12:21:18 -060069 InputFlags inputFlags)
Robert Phillipsd0fe8752019-01-31 14:13:59 -050070 : fWindowRectsState()
Chris Daltonbaa1b352019-04-03 12:03:00 -060071 , fFlags((Flags)inputFlags)
Chris Daltonc3318f02019-07-19 14:20:53 -060072 , fXferProcessor(std::move(xp))
Brian Salomon982f5462020-03-30 12:52:33 -040073 , fWriteSwizzle(writeSwizzle) {
Chris Dalton916c4982018-08-15 00:53:25 -060074 if (GrScissorTest::kEnabled == scissorTest) {
Chris Dalton2e7ed262020-02-21 15:17:59 -070075 fFlags |= Flags::kScissorTestEnabled;
Chris Dalton46983b72017-06-06 12:27:16 -060076 }
77}
Jim Van Verth1223e7f2019-02-28 17:38:35 -050078
Chris Daltonb204e4c2019-11-07 12:43:13 -070079void GrPipeline::genKey(GrProcessorKeyBuilder* b, const GrCaps& caps) const {
80 // kSnapVerticesToPixelCenters is implemented in a shader.
81 InputFlags ignoredFlags = InputFlags::kSnapVerticesToPixelCenters;
82 if (!caps.multisampleDisableSupport()) {
John Stiles29d3e222020-07-21 17:28:12 -040083 // Ganesh will omit kHWAntialias regardless of multisampleDisableSupport.
Chris Daltonb204e4c2019-11-07 12:43:13 -070084 ignoredFlags |= InputFlags::kHWAntialias;
85 }
John Stiles4b185102021-06-04 16:27:00 -040086 b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags, "flags");
Chris Daltonb204e4c2019-11-07 12:43:13 -070087
Chris Daltonbbb3f642019-07-24 12:25:08 -040088 const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
Jim Van Verth1223e7f2019-02-28 17:38:35 -050089
John Stiles4b185102021-06-04 16:27:00 -040090 static constexpr uint32_t kBlendCoeffSize = 5;
91 static constexpr uint32_t kBlendEquationSize = 5;
92 static_assert(kLast_GrBlendCoeff < (1 << kBlendCoeffSize));
93 static_assert(kLast_GrBlendEquation < (1 << kBlendEquationSize));
Jim Van Verth1223e7f2019-02-28 17:38:35 -050094
John Stiles4b185102021-06-04 16:27:00 -040095 b->addBool(blendInfo.fWriteColor, "writeColor");
96 b->addBits(kBlendCoeffSize, blendInfo.fSrcBlend, "srcBlend");
97 b->addBits(kBlendCoeffSize, blendInfo.fDstBlend, "dstBlend");
98 b->addBits(kBlendEquationSize, blendInfo.fEquation, "equation");
Greg Daniel87fab9f2021-06-07 15:18:23 -040099 b->addBool(this->usesDstInputAttachment(), "inputAttach");
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500100}
Brian Salomonc241b582019-11-27 08:57:17 -0500101
Brian Salomond90b3d32020-07-09 12:04:31 -0400102void GrPipeline::visitTextureEffects(
103 const std::function<void(const GrTextureEffect&)>& func) const {
104 for (auto& fp : fFragmentProcessors) {
105 fp->visitTextureEffects(func);
106 }
107}
108
Robert Phillips294723d2021-06-17 09:23:58 -0400109void GrPipeline::visitProxies(const GrVisitProxyFunc& func) const {
Brian Salomonc241b582019-11-27 08:57:17 -0500110 // This iteration includes any clip coverage FPs
Brian Salomond90b3d32020-07-09 12:04:31 -0400111 for (auto& fp : fFragmentProcessors) {
112 fp->visitProxies(func);
Brian Salomonc241b582019-11-27 08:57:17 -0500113 }
Greg Danield358cbe2020-09-11 09:33:54 -0400114 if (this->usesDstTexture()) {
John Stilesbcfdc1d2021-06-04 17:19:43 -0400115 func(this->dstProxyView().proxy(), GrMipmapped::kNo);
Brian Salomonc241b582019-11-27 08:57:17 -0500116 }
117}
John Stiles010d0882021-06-03 20:28:41 -0400118
119void GrPipeline::setDstTextureUniforms(const GrGLSLProgramDataManager& pdm,
120 GrGLSLBuiltinUniformHandles* fBuiltinUniformHandles) const {
John Stiles3e77d6e2021-06-04 15:30:50 -0400121 GrTexture* dstTexture = this->peekDstTexture();
John Stiles010d0882021-06-03 20:28:41 -0400122
123 if (dstTexture) {
John Stiles1acbc1e2021-06-04 10:31:45 -0400124 if (fBuiltinUniformHandles->fDstTextureCoordsUni.isValid()) {
125 pdm.set4f(fBuiltinUniformHandles->fDstTextureCoordsUni,
John Stilesbcfdc1d2021-06-04 17:19:43 -0400126 static_cast<float>(this->dstTextureOffset().fX),
127 static_cast<float>(this->dstTextureOffset().fY),
John Stiles010d0882021-06-03 20:28:41 -0400128 1.f / dstTexture->width(),
129 1.f / dstTexture->height());
John Stiles010d0882021-06-03 20:28:41 -0400130 }
131 } else {
John Stiles1acbc1e2021-06-04 10:31:45 -0400132 SkASSERT(!fBuiltinUniformHandles->fDstTextureCoordsUni.isValid());
John Stiles010d0882021-06-03 20:28:41 -0400133 }
134}