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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrPipeline.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrAppliedClip.h" |
| 11 | #include "src/gpu/GrCaps.h" |
| 12 | #include "src/gpu/GrGpu.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrSurfaceDrawContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrXferProcessor.h" |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 15 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 16 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 17 | |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 18 | GrPipeline::GrPipeline(const InitArgs& args, |
| 19 | sk_sp<const GrXferProcessor> xferProcessor, |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 20 | const GrAppliedHardClip& hardClip) |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 21 | : fDstProxy(args.fDstProxyView) |
| 22 | , fWindowRectsState(hardClip.windowRectsState()) |
| 23 | , fXferProcessor(std::move(xferProcessor)) |
| 24 | , fWriteSwizzle(args.fWriteSwizzle) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 25 | fFlags = (Flags)args.fInputFlags; |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 26 | if (hardClip.hasStencilClip()) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 27 | fFlags |= Flags::kHasStencilClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 28 | } |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 29 | if (hardClip.scissorState().enabled()) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 30 | fFlags |= Flags::kScissorTestEnabled; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 31 | } |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 32 | // If we have any special dst sample flags we better also have a dst proxy |
| 33 | SkASSERT(this->dstSampleFlags() == GrDstSampleFlags::kNone || this->dstProxyView()); |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 34 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 35 | |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 36 | GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors, |
| 37 | GrAppliedClip&& appliedClip) |
| 38 | : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) { |
| 39 | SkASSERT(processors.isFinalized()); |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 40 | // Copy GrFragmentProcessors from GrProcessorSet to Pipeline |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 41 | fNumColorProcessors = processors.hasColorFragmentProcessor() ? 1 : 0; |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 42 | int numTotalProcessors = fNumColorProcessors + |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 43 | (processors.hasCoverageFragmentProcessor() ? 1 : 0) + |
John Stiles | 59e18dc | 2020-07-22 18:18:12 -0400 | [diff] [blame] | 44 | (appliedClip.hasCoverageFragmentProcessor() ? 1 : 0); |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 45 | fFragmentProcessors.reset(numTotalProcessors); |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 46 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 47 | int currFPIdx = 0; |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 48 | if (processors.hasColorFragmentProcessor()) { |
| 49 | fFragmentProcessors[currFPIdx++] = processors.detachColorFragmentProcessor(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 50 | } |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 51 | if (processors.hasCoverageFragmentProcessor()) { |
| 52 | fFragmentProcessors[currFPIdx++] = processors.detachCoverageFragmentProcessor(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 53 | } |
John Stiles | 59e18dc | 2020-07-22 18:18:12 -0400 | [diff] [blame] | 54 | if (appliedClip.hasCoverageFragmentProcessor()) { |
| 55 | fFragmentProcessors[currFPIdx++] = appliedClip.detachCoverageFragmentProcessor(); |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 56 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 59 | GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const { |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 60 | if (this->dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) { |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 61 | return kTexture_GrXferBarrierType; |
| 62 | } |
| 63 | return this->getXferProcessor().xferBarrierType(caps); |
| 64 | } |
| 65 | |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 66 | GrPipeline::GrPipeline(GrScissorTest scissorTest, |
| 67 | sk_sp<const GrXferProcessor> xp, |
| 68 | const GrSwizzle& writeSwizzle, |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 69 | InputFlags inputFlags) |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 70 | : fWindowRectsState() |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 71 | , fFlags((Flags)inputFlags) |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 72 | , fXferProcessor(std::move(xp)) |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 73 | , fWriteSwizzle(writeSwizzle) { |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 74 | if (GrScissorTest::kEnabled == scissorTest) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 75 | fFlags |= Flags::kScissorTestEnabled; |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 76 | } |
| 77 | } |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 78 | |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 79 | void 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 Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 83 | // Ganesh will omit kHWAntialias regardless of multisampleDisableSupport. |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 84 | ignoredFlags |= InputFlags::kHWAntialias; |
| 85 | } |
John Stiles | 4b18510 | 2021-06-04 16:27:00 -0400 | [diff] [blame] | 86 | b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags, "flags"); |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 87 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 88 | const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo(); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 89 | |
John Stiles | 4b18510 | 2021-06-04 16:27:00 -0400 | [diff] [blame] | 90 | 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 Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 94 | |
John Stiles | 4b18510 | 2021-06-04 16:27:00 -0400 | [diff] [blame] | 95 | 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 Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 99 | b->addBool(this->usesDstInputAttachment(), "inputAttach"); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 100 | } |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 101 | |
Brian Salomon | d90b3d3 | 2020-07-09 12:04:31 -0400 | [diff] [blame] | 102 | void GrPipeline::visitTextureEffects( |
| 103 | const std::function<void(const GrTextureEffect&)>& func) const { |
| 104 | for (auto& fp : fFragmentProcessors) { |
| 105 | fp->visitTextureEffects(func); |
| 106 | } |
| 107 | } |
| 108 | |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame^] | 109 | void GrPipeline::visitProxies(const GrVisitProxyFunc& func) const { |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 110 | // This iteration includes any clip coverage FPs |
Brian Salomon | d90b3d3 | 2020-07-09 12:04:31 -0400 | [diff] [blame] | 111 | for (auto& fp : fFragmentProcessors) { |
| 112 | fp->visitProxies(func); |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 113 | } |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 114 | if (this->usesDstTexture()) { |
John Stiles | bcfdc1d | 2021-06-04 17:19:43 -0400 | [diff] [blame] | 115 | func(this->dstProxyView().proxy(), GrMipmapped::kNo); |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 116 | } |
| 117 | } |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 118 | |
| 119 | void GrPipeline::setDstTextureUniforms(const GrGLSLProgramDataManager& pdm, |
| 120 | GrGLSLBuiltinUniformHandles* fBuiltinUniformHandles) const { |
John Stiles | 3e77d6e | 2021-06-04 15:30:50 -0400 | [diff] [blame] | 121 | GrTexture* dstTexture = this->peekDstTexture(); |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 122 | |
| 123 | if (dstTexture) { |
John Stiles | 1acbc1e | 2021-06-04 10:31:45 -0400 | [diff] [blame] | 124 | if (fBuiltinUniformHandles->fDstTextureCoordsUni.isValid()) { |
| 125 | pdm.set4f(fBuiltinUniformHandles->fDstTextureCoordsUni, |
John Stiles | bcfdc1d | 2021-06-04 17:19:43 -0400 | [diff] [blame] | 126 | static_cast<float>(this->dstTextureOffset().fX), |
| 127 | static_cast<float>(this->dstTextureOffset().fY), |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 128 | 1.f / dstTexture->width(), |
| 129 | 1.f / dstTexture->height()); |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 130 | } |
| 131 | } else { |
John Stiles | 1acbc1e | 2021-06-04 10:31:45 -0400 | [diff] [blame] | 132 | SkASSERT(!fBuiltinUniformHandles->fDstTextureCoordsUni.isValid()); |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 133 | } |
| 134 | } |