Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLSLFragmentShaderBuilder.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 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
8#ifndef GrGLSLFragmentShaderBuilder_DEFINED
9#define GrGLSLFragmentShaderBuilder_DEFINED
10
11#include "include/gpu/GrTypes.h"
13
14#include <cstdint>
15
17
18namespace skgpu { enum class BlendEquation : uint8_t; }
19
20/*
21 * This class is used by fragment processors to build their fragment code.
22 */
24public:
25 /** Appease the compiler; the derived class initializes GrGLSLShaderBuilder. */
27 // Suppress unused warning error
28 (void) fPadding;
29 }
30
31 enum class ScopeFlags {
32 // Every fragment will always execute this code, and will do it exactly once.
33 kTopLevel = 0,
34 // Either all fragments in a given primitive, or none, will execute this code.
36 // Any given fragment may or may not execute this code.
37 kInsidePerPixelBranch = (1 << 1),
38 // This code will be executed more than once.
39 kInsideLoop = (1 << 2)
40 };
41
42 virtual void forceHighPrecision() = 0;
43
44 /** Returns the variable name that holds the color of the destination pixel. This may be nullptr
45 * if no effect advertised that it will read the destination. */
46 virtual const char* dstColor() = 0;
47
48private:
49 // WARNING: LIke GrRenderTargetProxy, changes to this can cause issues in ASAN. This is caused
50 // by GrGLSLProgramBuilder's SkTBlockLists requiring 16 byte alignment, but since
51 // GrGLSLFragmentShaderBuilder has a virtual diamond hierarchy, ASAN requires all this pointers
52 // to start aligned, even though clang is already correctly offsetting the individual fields
53 // that require the larger alignment. In the current world, this extra padding is sufficient to
54 // correctly initialize GrGLSLXPFragmentBuilder second.
55 char fPadding[4] = {};
56};
57
59
60/*
61 * This class is used by Xfer processors to build their fragment code.
62 */
64public:
65 /** Appease the compiler; the derived class initializes GrGLSLShaderBuilder. */
67
68 virtual bool hasSecondaryOutput() const = 0;
69
70 /** Returns the variable name that holds the color of the destination pixel. This may be nullptr
71 * if no effect advertised that it will read the destination. */
72 virtual const char* dstColor() = 0;
73
74 /** Adds any necessary layout qualifiers in order to legalize the supplied blend equation with
75 this shader. It is only legal to call this method with an advanced blend equation, and only
76 if these equations are supported. */
78};
79
80/*
81 * This class implements the various fragment builder interfaces.
82 */
84public:
86
87 // Shared FP/XP interface.
88 const char* dstColor() override;
89
90 // GrGLSLFPFragmentBuilder interface.
91 void forceHighPrecision() override { fForceHighPrecision = true; }
92
93 // GrGLSLXPFragmentBuilder interface.
94 bool hasSecondaryOutput() const override { return fHasSecondaryOutput; }
96
97private:
98 // Private public interface, used by GrGLProgramBuilder to build a fragment shader
99 void enableSecondaryOutput();
100 const char* getPrimaryColorOutputName() const;
101 const char* getSecondaryColorOutputName() const;
102 bool primaryColorOutputIsInOut() const;
103
104#ifdef SK_DEBUG
105 // As GLSLProcessors emit code, there are some conditions we need to verify. We use the below
106 // state to track this. The reset call is called per processor emitted.
107 bool fHasReadDstColorThisStage_DebugOnly = false;
108
109 void debugOnly_resetPerStageVerification() {
110 fHasReadDstColorThisStage_DebugOnly = false;
111 }
112#endif
113
114 static const char* DeclaredColorOutputName() { return "sk_FragColor"; }
115 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryColorOut"; }
116
117 GrSurfaceOrigin getSurfaceOrigin() const;
118
119 void onFinalize() override;
120
121 inline static constexpr const char kDstColorName[] = "_dstColor";
122
123 bool fPrimaryColorIsInOut = false;
124 bool fSetupFragPosition = false;
125 bool fHasSecondaryOutput = false;
126 bool fHasModifiedSampleMask = false;
127 bool fForceHighPrecision = false;
128
130 friend class GrGLProgramBuilder;
132};
133
134#endif
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition GrTypes.h:42
GrSurfaceOrigin
Definition GrTypes.h:147
virtual const char * dstColor()=0
virtual void forceHighPrecision()=0
void enableAdvancedBlendEquationIfNeeded(skgpu::BlendEquation) override
virtual bool hasSecondaryOutput() const =0
virtual const char * dstColor()=0
virtual void enableAdvancedBlendEquationIfNeeded(skgpu::BlendEquation)=0
BlendEquation
Definition Blend.h:26