/src/skia/src/gpu/ganesh/GrPipeline.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2015 Google Inc. |
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 | | #include "src/gpu/ganesh/GrPipeline.h" |
8 | | |
9 | | #include "include/gpu/GpuTypes.h" |
10 | | #include "include/private/base/SkAssert.h" |
11 | | #include "src/gpu/Blend.h" |
12 | | #include "src/gpu/KeyBuilder.h" |
13 | | #include "src/gpu/ganesh/GrAppliedClip.h" |
14 | | #include "src/gpu/ganesh/GrProcessorSet.h" |
15 | | #include "src/gpu/ganesh/GrScissorState.h" |
16 | | #include "src/gpu/ganesh/GrTexture.h" |
17 | | #include "src/gpu/ganesh/GrXferProcessor.h" |
18 | | #include "src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h" |
19 | | #include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h" |
20 | | |
21 | | #include <utility> |
22 | | |
23 | | GrPipeline::GrPipeline(const InitArgs& args, |
24 | | sk_sp<const GrXferProcessor> xferProcessor, |
25 | | const GrAppliedHardClip& hardClip) |
26 | | : fDstProxy(args.fDstProxyView) |
27 | | , fWindowRectsState(hardClip.windowRectsState()) |
28 | | , fXferProcessor(std::move(xferProcessor)) |
29 | 235k | , fWriteSwizzle(args.fWriteSwizzle) { |
30 | 235k | fFlags = (Flags)args.fInputFlags; |
31 | 235k | if (hardClip.hasStencilClip()) { |
32 | 11.6k | fFlags |= Flags::kHasStencilClip; |
33 | 11.6k | } |
34 | 235k | if (hardClip.scissorState().enabled()) { |
35 | 159k | fFlags |= Flags::kScissorTestEnabled; |
36 | 159k | } |
37 | | // If we have any special dst sample flags we better also have a dst proxy |
38 | 235k | SkASSERT(this->dstSampleFlags() == GrDstSampleFlags::kNone || this->dstProxyView()); |
39 | 235k | } |
40 | | |
41 | | GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors, |
42 | | GrAppliedClip&& appliedClip) |
43 | 235k | : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) { |
44 | 235k | SkASSERT(processors.isFinalized()); |
45 | | // Copy GrFragmentProcessors from GrProcessorSet to Pipeline |
46 | 235k | fNumColorProcessors = processors.hasColorFragmentProcessor() ? 1 : 0; |
47 | 235k | int numTotalProcessors = fNumColorProcessors + |
48 | 235k | (processors.hasCoverageFragmentProcessor() ? 1 : 0) + |
49 | 235k | (appliedClip.hasCoverageFragmentProcessor() ? 1 : 0); |
50 | 235k | fFragmentProcessors.reset(numTotalProcessors); |
51 | | |
52 | 235k | int currFPIdx = 0; |
53 | 235k | if (processors.hasColorFragmentProcessor()) { |
54 | 148k | fFragmentProcessors[currFPIdx++] = processors.detachColorFragmentProcessor(); |
55 | 148k | } |
56 | 235k | if (processors.hasCoverageFragmentProcessor()) { |
57 | 50.2k | fFragmentProcessors[currFPIdx++] = processors.detachCoverageFragmentProcessor(); |
58 | 50.2k | } |
59 | 235k | if (appliedClip.hasCoverageFragmentProcessor()) { |
60 | 13.4k | fFragmentProcessors[currFPIdx++] = appliedClip.detachCoverageFragmentProcessor(); |
61 | 13.4k | } |
62 | 235k | } GrPipeline::GrPipeline(GrPipeline::InitArgs const&, GrProcessorSet&&, GrAppliedClip&&) Line | Count | Source | 43 | 235k | : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) { | 44 | 235k | SkASSERT(processors.isFinalized()); | 45 | | // Copy GrFragmentProcessors from GrProcessorSet to Pipeline | 46 | 235k | fNumColorProcessors = processors.hasColorFragmentProcessor() ? 1 : 0; | 47 | 235k | int numTotalProcessors = fNumColorProcessors + | 48 | 235k | (processors.hasCoverageFragmentProcessor() ? 1 : 0) + | 49 | 235k | (appliedClip.hasCoverageFragmentProcessor() ? 1 : 0); | 50 | 235k | fFragmentProcessors.reset(numTotalProcessors); | 51 | | | 52 | 235k | int currFPIdx = 0; | 53 | 235k | if (processors.hasColorFragmentProcessor()) { | 54 | 148k | fFragmentProcessors[currFPIdx++] = processors.detachColorFragmentProcessor(); | 55 | 148k | } | 56 | 235k | if (processors.hasCoverageFragmentProcessor()) { | 57 | 50.2k | fFragmentProcessors[currFPIdx++] = processors.detachCoverageFragmentProcessor(); | 58 | 50.2k | } | 59 | 235k | if (appliedClip.hasCoverageFragmentProcessor()) { | 60 | 13.4k | fFragmentProcessors[currFPIdx++] = appliedClip.detachCoverageFragmentProcessor(); | 61 | 13.4k | } | 62 | 235k | } |
Unexecuted instantiation: GrPipeline::GrPipeline(GrPipeline::InitArgs const&, GrProcessorSet&&, GrAppliedClip&&) |
63 | | |
64 | 227k | GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const { |
65 | 227k | if (this->dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) { |
66 | 0 | return kTexture_GrXferBarrierType; |
67 | 0 | } |
68 | 227k | return this->getXferProcessor().xferBarrierType(caps); |
69 | 227k | } |
70 | | |
71 | | GrPipeline::GrPipeline(GrScissorTest scissorTest, |
72 | | sk_sp<const GrXferProcessor> xp, |
73 | | const skgpu::Swizzle& writeSwizzle, |
74 | | InputFlags inputFlags) |
75 | | : fWindowRectsState() |
76 | | , fFlags((Flags)inputFlags) |
77 | | , fXferProcessor(std::move(xp)) |
78 | 0 | , fWriteSwizzle(writeSwizzle) { |
79 | 0 | if (GrScissorTest::kEnabled == scissorTest) { |
80 | 0 | fFlags |= Flags::kScissorTestEnabled; |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | 0 | void GrPipeline::genKey(skgpu::KeyBuilder* b, const GrCaps& caps) const { |
85 | | // kSnapVerticesToPixelCenters is implemented in a shader. |
86 | 0 | InputFlags ignoredFlags = InputFlags::kSnapVerticesToPixelCenters; |
87 | 0 | b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags, "flags"); |
88 | |
|
89 | 0 | const skgpu::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo(); |
90 | |
|
91 | 0 | static constexpr uint32_t kBlendCoeffSize = 5; |
92 | 0 | static constexpr uint32_t kBlendEquationSize = 5; |
93 | 0 | static_assert(static_cast<int>(skgpu::BlendCoeff::kLast) < (1 << kBlendCoeffSize)); |
94 | 0 | static_assert(static_cast<int>(skgpu::BlendEquation::kLast) < (1 << kBlendEquationSize)); |
95 | |
|
96 | 0 | b->addBool(blendInfo.fWritesColor, "writesColor"); |
97 | 0 | b->addBits(kBlendCoeffSize, static_cast<int>(blendInfo.fSrcBlend), "srcBlend"); |
98 | 0 | b->addBits(kBlendCoeffSize, static_cast<int>(blendInfo.fDstBlend), "dstBlend"); |
99 | 0 | b->addBits(kBlendEquationSize, static_cast<int>(blendInfo.fEquation), "equation"); |
100 | 0 | b->addBool(this->usesDstInputAttachment(), "inputAttach"); |
101 | 0 | } |
102 | | |
103 | | void GrPipeline::visitTextureEffects( |
104 | 0 | const std::function<void(const GrTextureEffect&)>& func) const { |
105 | 0 | for (auto& fp : fFragmentProcessors) { |
106 | 0 | fp->visitTextureEffects(func); |
107 | 0 | } |
108 | 0 | } |
109 | | |
110 | 0 | void GrPipeline::visitProxies(const GrVisitProxyFunc& func) const { |
111 | | // This iteration includes any clip coverage FPs |
112 | 0 | for (auto& fp : fFragmentProcessors) { |
113 | 0 | fp->visitProxies(func); |
114 | 0 | } |
115 | 0 | if (this->usesDstTexture()) { |
116 | 0 | func(this->dstProxyView().proxy(), skgpu::Mipmapped::kNo); |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | | void GrPipeline::setDstTextureUniforms(const GrGLSLProgramDataManager& pdm, |
121 | 0 | GrGLSLBuiltinUniformHandles* fBuiltinUniformHandles) const { |
122 | 0 | GrTexture* dstTexture = this->peekDstTexture(); |
123 | |
|
124 | 0 | if (dstTexture) { |
125 | 0 | if (fBuiltinUniformHandles->fDstTextureCoordsUni.isValid()) { |
126 | 0 | float scaleX = 1.f; |
127 | 0 | float scaleY = 1.f; |
128 | 0 | if (dstTexture->textureType() == GrTextureType::kRectangle) { |
129 | | // When we have a rectangle texture, we use the scaleX component to store the height |
130 | | // in case we need to flip the coords when using a bottom left origin. |
131 | 0 | scaleX = dstTexture->height(); |
132 | 0 | } else { |
133 | 0 | scaleX /= dstTexture->width(); |
134 | 0 | scaleY /= dstTexture->height(); |
135 | 0 | } |
136 | 0 | pdm.set4f(fBuiltinUniformHandles->fDstTextureCoordsUni, |
137 | 0 | static_cast<float>(this->dstTextureOffset().fX), |
138 | 0 | static_cast<float>(this->dstTextureOffset().fY), |
139 | 0 | scaleX, |
140 | 0 | scaleY); |
141 | 0 | } |
142 | 0 | } else { |
143 | 0 | SkASSERT(!fBuiltinUniformHandles->fDstTextureCoordsUni.isValid()); |
144 | 0 | } |
145 | 0 | } Unexecuted instantiation: GrPipeline::setDstTextureUniforms(GrGLSLProgramDataManager const&, GrGLSLBuiltinUniformHandles*) const Unexecuted instantiation: GrPipeline::setDstTextureUniforms(GrGLSLProgramDataManager const&, GrGLSLBuiltinUniformHandles*) const |