blob: 60b89abd98ecefaa4c4803153d8905794dea7348 [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
2 * Copyright 2012 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
joshualittb0a8a372014-09-23 09:50:21 -07008#ifndef GrProcessor_DEFINED
9#define GrProcessor_DEFINED
tomhudson@google.com168e6342012-04-18 17:49:20 +000010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkMath.h"
12#include "include/core/SkString.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040013#include "src/gpu/GrColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrGpuBuffer.h"
15#include "src/gpu/GrProcessorUnitTest.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040016#include "src/gpu/GrSamplerState.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrShaderVar.h"
18#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040019#include "src/gpu/GrTextureProxy.h"
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000020
tomhudson@google.com168e6342012-04-18 17:49:20 +000021class GrContext;
Brian Osman32342f02017-03-04 08:12:46 -050022class GrResourceProvider;
bsalomon95740982014-09-04 13:12:37 -070023
joshualitteb2a6762014-12-04 11:35:33 -080024/**
25 * Used by processors to build their keys. It incorporates each per-processor key into a larger
26 * shader key.
27 */
28class GrProcessorKeyBuilder {
29public:
30 GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) {
31 SkASSERT(0 == fData->count() % sizeof(uint32_t));
32 }
33
34 void add32(uint32_t v) {
35 ++fCount;
36 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
37 }
38
39 /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next
40 add*() call. */
41 uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) {
42 SkASSERT(count > 0);
43 fCount += count;
44 return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count));
45 }
46
47 size_t size() const { return sizeof(uint32_t) * fCount; }
48
49private:
50 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
51 int fCount; // number of uint32_ts added to fData by the processor.
52};
53
bsalomon98b33eb2014-10-15 11:05:26 -070054/** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be
55 immutable: after being constructed, their fields may not change.
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000056
joshualittb0a8a372014-09-23 09:50:21 -070057 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
mdempsky38f1f6f2015-08-27 12:57:01 -070058 processor must reach 0 before the thread terminates and the pool is destroyed.
bsalomon98b33eb2014-10-15 11:05:26 -070059 */
Brian Salomond61c9d92017-04-10 10:54:25 -040060class GrProcessor {
tomhudson@google.com168e6342012-04-18 17:49:20 +000061public:
Ethan Nicholasabff9562017-10-09 10:54:08 -040062 enum ClassID {
Ethan Nicholasabff9562017-10-09 10:54:08 -040063 kBigKeyProcessor_ClassID,
64 kBlockInputFragmentProcessor_ClassID,
Brian Salomon62e4f3d2018-04-20 13:54:11 -040065 kButtCapStrokedCircleGeometryProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040066 kCircleGeometryProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040067 kCircularRRectEffect_ClassID,
Chris Dalton49d14e92018-07-27 12:38:35 -060068 kClockwiseTestProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040069 kColorTableEffect_ClassID,
70 kComposeOneFragmentProcessor_ClassID,
71 kComposeTwoFragmentProcessor_ClassID,
72 kCoverageSetOpXP_ClassID,
Chris Dalton09a7bb22018-08-31 19:53:15 +080073 kCubicStrokeProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040074 kCustomXP_ClassID,
75 kDashingCircleEffect_ClassID,
76 kDashingLineEffect_ClassID,
77 kDefaultGeoProc_ClassID,
78 kDIEllipseGeometryProcessor_ClassID,
79 kDisableColorXP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040080 kEllipseGeometryProcessor_ClassID,
81 kEllipticalRRectEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040082 kGP_ClassID,
Brian Osman387eaff2018-07-20 14:50:44 -040083 kVertexColorSpaceBenchGP_ClassID,
Ethan Nicholas8dca18a2017-11-15 15:33:33 -050084 kGrAARectEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040085 kGrAlphaThresholdFragmentProcessor_ClassID,
86 kGrBicubicEffect_ClassID,
87 kGrBitmapTextGeoProc_ClassID,
88 kGrBlurredEdgeFragmentProcessor_ClassID,
Chris Dalton383a2ef2018-01-08 17:21:41 -050089 kGrCCClipProcessor_ClassID,
Chris Dalton383a2ef2018-01-08 17:21:41 -050090 kGrCCPathProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040091 kGrCircleBlurFragmentProcessor_ClassID,
92 kGrCircleEffect_ClassID,
Michael Ludwig4f94ef62018-09-12 15:22:16 -040093 kGrClampedGradientEffect_ClassID,
Brian Salomond6f3f182019-05-31 09:24:40 -040094 kGrColorMatrixFragmentProcessor_ClassID,
Brian Osmanc4f93ca2017-10-17 17:15:52 -040095 kGrColorSpaceXformEffect_ClassID,
Ethan Nicholasff4fb332019-04-09 16:28:19 -040096 kGrComposeLerpEffect_ClassID,
97 kGrComposeLerpRedEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040098 kGrConfigConversionEffect_ClassID,
99 kGrConicEffect_ClassID,
100 kGrConstColorProcessor_ClassID,
101 kGrConvexPolyEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400102 kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID,
103 kGrDiffuseLightingEffect_ClassID,
104 kGrDisplacementMapEffect_ClassID,
105 kGrDistanceFieldA8TextGeoProc_ClassID,
106 kGrDistanceFieldLCDTextGeoProc_ClassID,
107 kGrDistanceFieldPathGeoProc_ClassID,
Brian Salomon7eabfe82019-12-02 14:20:20 -0500108 kGrDomainEffect_ClassID,
Michael Ludwig0495f7a2018-09-12 15:23:33 -0400109 kGrDualIntervalGradientColorizer_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400110 kGrEllipseEffect_ClassID,
Chris Dalton82eb9e72019-03-21 14:26:39 -0600111 kGrFillRRectOp_Processor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400112 kGrGaussianConvolutionFragmentProcessor_ClassID,
Chris Dalton2c5e0112019-03-29 13:14:18 -0500113 kGrGSCoverageProcessor_ClassID,
Florin Malita36031202019-10-23 11:44:22 -0400114 kGrHSLToRGBFilterEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400115 kGrImprovedPerlinNoiseEffect_ClassID,
Michael Ludwig4f94ef62018-09-12 15:22:16 -0400116 kGrLinearGradientLayout_ClassID,
Ethan Nicholas14efcbf2017-11-07 09:23:38 -0500117 kGrLumaColorFilterEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400118 kGrMagnifierEffect_ClassID,
119 kGrMatrixConvolutionEffect_ClassID,
120 kGrMeshTestProcessor_ClassID,
121 kGrMorphologyEffect_ClassID,
Florin Malita6041d312019-03-05 15:03:20 +0000122 kGrMixerEffect_ClassID,
Brian Salomonc0d79e52019-04-10 15:02:11 -0400123 kGrOverrideInputFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400124 kGrPathProcessor_ClassID,
125 kGrPerlinNoise2Effect_ClassID,
126 kGrPipelineDynamicStateTestProcessor_ClassID,
Ethan Nicholasbe0a0422017-11-17 13:44:05 -0500127 kGrPremulInputFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400128 kGrQuadEffect_ClassID,
Michael Ludwig4089df82018-09-12 15:22:37 -0400129 kGrRadialGradientLayout_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400130 kGrRectBlurEffect_ClassID,
Florin Malita36031202019-10-23 11:44:22 -0400131 kGrRGBToHSLFilterEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400132 kGrRRectBlurEffect_ClassID,
133 kGrRRectShadowGeoProc_ClassID,
134 kGrSimpleTextureEffect_ClassID,
Michael Ludwig4f94ef62018-09-12 15:22:16 -0400135 kGrSingleIntervalGradientColorizer_ClassID,
Ethan Nicholas00543112018-07-31 09:44:36 -0400136 kGrSkSLFP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400137 kGrSpecularLightingEffect_ClassID,
138 kGrSRGBEffect_ClassID,
Chris Daltonc3318f02019-07-19 14:20:53 -0600139 kGrSampleMaskProcessor_ClassID,
Brian Salomonf19f9ca2019-09-18 15:54:26 -0400140 kGrSaturateProcessor_ClassID,
Michael Ludwig24d438b2018-09-12 15:22:50 -0400141 kGrSweepGradientLayout_ClassID,
Michael Ludwiga7914d32018-09-14 09:47:21 -0400142 kGrTextureGradientColorizer_ClassID,
Michael Ludwig4f94ef62018-09-12 15:22:16 -0400143 kGrTiledGradientEffect_ClassID,
Michael Ludwig8f685082018-09-12 15:23:01 -0400144 kGrTwoPointConicalGradientLayout_ClassID,
Michael Ludwig72535fb2018-09-28 11:53:32 -0400145 kGrUnrolledBinaryGradientColorizer_ClassID,
Chris Dalton2c5e0112019-03-29 13:14:18 -0500146 kGrVSCoverageProcessor_ClassID,
Ethan Nicholas7461a4a2017-12-21 14:18:01 -0500147 kGrYUVtoRGBEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400148 kHighContrastFilterEffect_ClassID,
Brian Salomon2a943df2018-05-04 13:43:19 -0400149 kLatticeGP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400150 kPDLCDXferProcessor_ClassID,
151 kPorterDuffXferProcessor_ClassID,
152 kPremulFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400153 kQuadEdgeEffect_ClassID,
Michael Ludwig69858532018-11-28 15:34:34 -0500154 kQuadPerEdgeAAGeometryProcessor_ClassID,
Chris Daltond7291ba2019-03-07 14:17:03 -0700155 kSampleLocationsTestProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400156 kSeriesFragmentProcessor_ClassID,
157 kShaderPDXferProcessor_ClassID,
Chris Daltonc3318f02019-07-19 14:20:53 -0600158 kStencilResolveProcessor_ClassID,
Chris Dalton09212192018-11-13 15:07:24 -0500159 kFwidthSquircleTestProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400160 kSwizzleFragmentProcessor_ClassID,
161 kTestFP_ClassID,
Brian Salomone21af502019-11-22 16:56:36 -0500162 kTestRectOp_ClassID,
Robert Phillipsa8cdbd72018-07-17 12:30:40 -0400163 kFlatNormalsFP_ClassID,
164 kMappedNormalsFP_ClassID,
165 kLightingFP_ClassID,
Chris Dalton09a7bb22018-08-31 19:53:15 +0800166 kLinearStrokeProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400167 };
168
Brian Salomonab015ef2017-04-04 10:15:51 -0400169 virtual ~GrProcessor() = default;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000170
Brian Salomonb014cca2016-11-18 11:39:15 -0500171 /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader
172 code. */
joshualitteb2a6762014-12-04 11:35:33 -0800173 virtual const char* name() const = 0;
bsalomon@google.com289efe02012-05-21 20:57:59 +0000174
Brian Salomonb014cca2016-11-18 11:39:15 -0500175 /** Human-readable dump of all information */
Brian Osman9a390ac2018-11-12 09:47:48 -0500176#ifdef SK_DEBUG
robertphillipse004bfc2015-11-16 09:06:59 -0800177 virtual SkString dumpInfo() const {
178 SkString str;
179 str.appendf("Missing data");
180 return str;
181 }
Brian Osman9a390ac2018-11-12 09:47:48 -0500182#else
183 SkString dumpInfo() const { return SkString("<Processor information unavailable>"); }
184#endif
robertphillipse004bfc2015-11-16 09:06:59 -0800185
Chris Daltond7291ba2019-03-07 14:17:03 -0700186 /**
187 * Custom shader features provided by the framework. These require special handling when
188 * preparing shaders, so a processor must call setWillUseCustomFeature() from its constructor if
189 * it intends to use one.
190 */
191 enum class CustomFeatures {
192 kNone = 0,
193 kSampleLocations = 1 << 0,
194 };
195
196 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(CustomFeatures);
197
198 CustomFeatures requestedFeatures() const { return fRequestedFeatures; }
199
tomhudson@google.comdcba4c22012-07-24 21:36:16 +0000200 void* operator new(size_t size);
201 void operator delete(void* target);
202
bsalomon@google.comd42aca32013-04-23 15:37:27 +0000203 void* operator new(size_t size, void* placement) {
204 return ::operator new(size, placement);
205 }
206 void operator delete(void* target, void* placement) {
207 ::operator delete(target, placement);
208 }
209
Brian Salomonb014cca2016-11-18 11:39:15 -0500210 /** Helper for down-casting to a GrProcessor subclass */
joshualitt49586be2014-09-16 08:21:41 -0700211 template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
212
Ethan Nicholasabff9562017-10-09 10:54:08 -0400213 ClassID classID() const { return fClassID; }
joshualitteb2a6762014-12-04 11:35:33 -0800214
bsalomon@google.com50db75c2013-01-11 13:54:30 +0000215protected:
Chris Dalton535ba8d2018-02-20 09:51:59 -0700216 GrProcessor(ClassID classID) : fClassID(classID) {}
Brian Salomond61c9d92017-04-10 10:54:25 -0400217 GrProcessor(const GrProcessor&) = delete;
218 GrProcessor& operator=(const GrProcessor&) = delete;
219
Chris Daltond7291ba2019-03-07 14:17:03 -0700220 void setWillUseCustomFeature(CustomFeatures feature) { fRequestedFeatures |= feature; }
Chris Daltonc3318f02019-07-19 14:20:53 -0600221 void resetCustomFeatures() { fRequestedFeatures = CustomFeatures::kNone; }
Chris Daltond7291ba2019-03-07 14:17:03 -0700222
223 const ClassID fClassID;
224 CustomFeatures fRequestedFeatures = CustomFeatures::kNone;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000225};
226
Michael Ludwig61eba6c2019-11-01 11:21:58 -0400227GR_MAKE_BITFIELD_CLASS_OPS(GrProcessor::CustomFeatures)
Chris Daltond7291ba2019-03-07 14:17:03 -0700228
tomhudson@google.com168e6342012-04-18 17:49:20 +0000229#endif