tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 8 | #ifndef GrProcessor_DEFINED |
| 9 | #define GrProcessor_DEFINED |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMath.h" |
| 12 | #include "include/core/SkString.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrGpuBuffer.h" |
| 15 | #include "src/gpu/GrProcessorUnitTest.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrSamplerState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrShaderVar.h" |
| 18 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrTextureProxy.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 20 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 21 | class GrContext; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 22 | class GrResourceProvider; |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 23 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Used by processors to build their keys. It incorporates each per-processor key into a larger |
| 26 | * shader key. |
| 27 | */ |
| 28 | class GrProcessorKeyBuilder { |
| 29 | public: |
| 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 | |
| 49 | private: |
| 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 | |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 54 | /** 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.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 56 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an |
mdempsky | 38f1f6f | 2015-08-27 12:57:01 -0700 | [diff] [blame] | 58 | processor must reach 0 before the thread terminates and the pool is destroyed. |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 59 | */ |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 60 | class GrProcessor { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 61 | public: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 62 | enum ClassID { |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 63 | kBigKeyProcessor_ClassID, |
| 64 | kBlockInputFragmentProcessor_ClassID, |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 65 | kButtCapStrokedCircleGeometryProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 66 | kCircleGeometryProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 67 | kCircularRRectEffect_ClassID, |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 68 | kClockwiseTestProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 69 | kColorTableEffect_ClassID, |
| 70 | kComposeOneFragmentProcessor_ClassID, |
| 71 | kComposeTwoFragmentProcessor_ClassID, |
| 72 | kCoverageSetOpXP_ClassID, |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 73 | kCubicStrokeProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 74 | kCustomXP_ClassID, |
| 75 | kDashingCircleEffect_ClassID, |
| 76 | kDashingLineEffect_ClassID, |
| 77 | kDefaultGeoProc_ClassID, |
| 78 | kDIEllipseGeometryProcessor_ClassID, |
| 79 | kDisableColorXP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 80 | kEllipseGeometryProcessor_ClassID, |
| 81 | kEllipticalRRectEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 82 | kGP_ClassID, |
Brian Osman | 387eaff | 2018-07-20 14:50:44 -0400 | [diff] [blame] | 83 | kVertexColorSpaceBenchGP_ClassID, |
Ethan Nicholas | 8dca18a | 2017-11-15 15:33:33 -0500 | [diff] [blame] | 84 | kGrAARectEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 85 | kGrAlphaThresholdFragmentProcessor_ClassID, |
| 86 | kGrBicubicEffect_ClassID, |
| 87 | kGrBitmapTextGeoProc_ClassID, |
| 88 | kGrBlurredEdgeFragmentProcessor_ClassID, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 89 | kGrCCClipProcessor_ClassID, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 90 | kGrCCPathProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 91 | kGrCircleBlurFragmentProcessor_ClassID, |
| 92 | kGrCircleEffect_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 93 | kGrClampedGradientEffect_ClassID, |
Brian Salomon | d6f3f18 | 2019-05-31 09:24:40 -0400 | [diff] [blame] | 94 | kGrColorMatrixFragmentProcessor_ClassID, |
Brian Osman | c4f93ca | 2017-10-17 17:15:52 -0400 | [diff] [blame] | 95 | kGrColorSpaceXformEffect_ClassID, |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 96 | kGrComposeLerpEffect_ClassID, |
| 97 | kGrComposeLerpRedEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 98 | kGrConfigConversionEffect_ClassID, |
| 99 | kGrConicEffect_ClassID, |
| 100 | kGrConstColorProcessor_ClassID, |
| 101 | kGrConvexPolyEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 102 | kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID, |
| 103 | kGrDiffuseLightingEffect_ClassID, |
| 104 | kGrDisplacementMapEffect_ClassID, |
| 105 | kGrDistanceFieldA8TextGeoProc_ClassID, |
| 106 | kGrDistanceFieldLCDTextGeoProc_ClassID, |
| 107 | kGrDistanceFieldPathGeoProc_ClassID, |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame^] | 108 | kGrDomainEffect_ClassID, |
Michael Ludwig | 0495f7a | 2018-09-12 15:23:33 -0400 | [diff] [blame] | 109 | kGrDualIntervalGradientColorizer_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 110 | kGrEllipseEffect_ClassID, |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 111 | kGrFillRRectOp_Processor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 112 | kGrGaussianConvolutionFragmentProcessor_ClassID, |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 113 | kGrGSCoverageProcessor_ClassID, |
Florin Malita | 3603120 | 2019-10-23 11:44:22 -0400 | [diff] [blame] | 114 | kGrHSLToRGBFilterEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 115 | kGrImprovedPerlinNoiseEffect_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 116 | kGrLinearGradientLayout_ClassID, |
Ethan Nicholas | 14efcbf | 2017-11-07 09:23:38 -0500 | [diff] [blame] | 117 | kGrLumaColorFilterEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 118 | kGrMagnifierEffect_ClassID, |
| 119 | kGrMatrixConvolutionEffect_ClassID, |
| 120 | kGrMeshTestProcessor_ClassID, |
| 121 | kGrMorphologyEffect_ClassID, |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 122 | kGrMixerEffect_ClassID, |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 123 | kGrOverrideInputFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 124 | kGrPathProcessor_ClassID, |
| 125 | kGrPerlinNoise2Effect_ClassID, |
| 126 | kGrPipelineDynamicStateTestProcessor_ClassID, |
Ethan Nicholas | be0a042 | 2017-11-17 13:44:05 -0500 | [diff] [blame] | 127 | kGrPremulInputFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 128 | kGrQuadEffect_ClassID, |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 129 | kGrRadialGradientLayout_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 130 | kGrRectBlurEffect_ClassID, |
Florin Malita | 3603120 | 2019-10-23 11:44:22 -0400 | [diff] [blame] | 131 | kGrRGBToHSLFilterEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 132 | kGrRRectBlurEffect_ClassID, |
| 133 | kGrRRectShadowGeoProc_ClassID, |
| 134 | kGrSimpleTextureEffect_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 135 | kGrSingleIntervalGradientColorizer_ClassID, |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 136 | kGrSkSLFP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 137 | kGrSpecularLightingEffect_ClassID, |
| 138 | kGrSRGBEffect_ClassID, |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 139 | kGrSampleMaskProcessor_ClassID, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 140 | kGrSaturateProcessor_ClassID, |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 141 | kGrSweepGradientLayout_ClassID, |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 142 | kGrTextureGradientColorizer_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 143 | kGrTiledGradientEffect_ClassID, |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 144 | kGrTwoPointConicalGradientLayout_ClassID, |
Michael Ludwig | 72535fb | 2018-09-28 11:53:32 -0400 | [diff] [blame] | 145 | kGrUnrolledBinaryGradientColorizer_ClassID, |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 146 | kGrVSCoverageProcessor_ClassID, |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 147 | kGrYUVtoRGBEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 148 | kHighContrastFilterEffect_ClassID, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 149 | kLatticeGP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 150 | kPDLCDXferProcessor_ClassID, |
| 151 | kPorterDuffXferProcessor_ClassID, |
| 152 | kPremulFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 153 | kQuadEdgeEffect_ClassID, |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 154 | kQuadPerEdgeAAGeometryProcessor_ClassID, |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 155 | kSampleLocationsTestProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 156 | kSeriesFragmentProcessor_ClassID, |
| 157 | kShaderPDXferProcessor_ClassID, |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 158 | kStencilResolveProcessor_ClassID, |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 159 | kFwidthSquircleTestProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 160 | kSwizzleFragmentProcessor_ClassID, |
| 161 | kTestFP_ClassID, |
Brian Salomon | e21af50 | 2019-11-22 16:56:36 -0500 | [diff] [blame] | 162 | kTestRectOp_ClassID, |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 163 | kFlatNormalsFP_ClassID, |
| 164 | kMappedNormalsFP_ClassID, |
| 165 | kLightingFP_ClassID, |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 166 | kLinearStrokeProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 169 | virtual ~GrProcessor() = default; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 170 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 171 | /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader |
| 172 | code. */ |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 173 | virtual const char* name() const = 0; |
bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 174 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 175 | /** Human-readable dump of all information */ |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 176 | #ifdef SK_DEBUG |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 177 | virtual SkString dumpInfo() const { |
| 178 | SkString str; |
| 179 | str.appendf("Missing data"); |
| 180 | return str; |
| 181 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 182 | #else |
| 183 | SkString dumpInfo() const { return SkString("<Processor information unavailable>"); } |
| 184 | #endif |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 185 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 186 | /** |
| 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.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 200 | void* operator new(size_t size); |
| 201 | void operator delete(void* target); |
| 202 | |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 203 | 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 Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 210 | /** Helper for down-casting to a GrProcessor subclass */ |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 211 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| 212 | |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 213 | ClassID classID() const { return fClassID; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 214 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 215 | protected: |
Chris Dalton | 535ba8d | 2018-02-20 09:51:59 -0700 | [diff] [blame] | 216 | GrProcessor(ClassID classID) : fClassID(classID) {} |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 217 | GrProcessor(const GrProcessor&) = delete; |
| 218 | GrProcessor& operator=(const GrProcessor&) = delete; |
| 219 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 220 | void setWillUseCustomFeature(CustomFeatures feature) { fRequestedFeatures |= feature; } |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 221 | void resetCustomFeatures() { fRequestedFeatures = CustomFeatures::kNone; } |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 222 | |
| 223 | const ClassID fClassID; |
| 224 | CustomFeatures fRequestedFeatures = CustomFeatures::kNone; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
Michael Ludwig | 61eba6c | 2019-11-01 11:21:58 -0400 | [diff] [blame] | 227 | GR_MAKE_BITFIELD_CLASS_OPS(GrProcessor::CustomFeatures) |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 228 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 229 | #endif |