Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
GrGLSLShaderBuilder Class Referenceabstract

#include <GrGLSLShaderBuilder.h>

Inheritance diagram for GrGLSLShaderBuilder:
GrGLSLFPFragmentBuilder GrGLSLVertexGeoBuilder GrGLSLXPFragmentBuilder GrGLSLFragmentShaderBuilder GrGLSLVertexBuilder GrGLSLFragmentShaderBuilder

Classes

class  ShaderBlock
 

Public Types

using SamplerHandle = GrGLSLUniformHandler::SamplerHandle
 

Public Member Functions

 GrGLSLShaderBuilder (GrGLSLProgramBuilder *program)
 
virtual ~GrGLSLShaderBuilder ()
 
void appendTextureLookup (SkString *out, SamplerHandle, const char *coordName) const
 
void appendTextureLookup (SamplerHandle, const char *coordName, GrGLSLColorSpaceXformHelper *colorXformHelper=nullptr)
 
void appendTextureLookupAndBlend (const char *dst, SkBlendMode, SamplerHandle, const char *coordName, GrGLSLColorSpaceXformHelper *colorXformHelper=nullptr)
 
void appendInputLoad (SamplerHandle)
 
void appendColorGamutXform (SkString *out, const char *srcColor, GrGLSLColorSpaceXformHelper *colorXformHelper)
 
void appendColorGamutXform (const char *srcColor, GrGLSLColorSpaceXformHelper *colorXformHelper)
 
void defineConstant (const char *type, const char *name, const char *value)
 
void defineConstant (const char *name, int value)
 
void defineConstant (const char *name, float value)
 
void defineConstantf (const char *type, const char *name, const char *fmt,...) SK_PRINTF_LIKE(4
 
 va_start (args, fmt)
 
this definitions ().appendVAList(fmt
 
 va_end (args)
 
this definitions ().append("
 
void definitionAppend (const char *str)
 
void declareGlobal (const GrShaderVar &)
 
SkString newTmpVarName (const char *suffix)
 
void codeAppendf (const char format[],...) SK_PRINTF_LIKE(2
 
void va_start (args, format)
 
this code ().appendVAList(format
 
 va_end (args)
 
void codeAppend (const char *str)
 
void codeAppend (const char *str, size_t length)
 
void codePrependf (const char format[],...) SK_PRINTF_LIKE(2
 
void va_start (args, format)
 
this code ().prependVAList(format
 
 va_end (args)
 
void declAppend (const GrShaderVar &var)
 
SkString getMangledFunctionName (const char *baseName)
 
void emitFunctionPrototype (SkSLType returnType, const char *mangledName, SkSpan< const GrShaderVar > args)
 
void emitFunctionPrototype (const char *declaration)
 
void emitFunction (SkSLType returnType, const char *mangledName, SkSpan< const GrShaderVar > args, const char *body)
 
void emitFunction (const char *declaration, const char *body)
 
void finalize (uint32_t visibility)
 
GrGLSLProgramBuildergetProgramBuilder ()
 

Public Attributes

void va_list args
 
this args
 
 n
 

Protected Types

enum  GLSLPrivateFeature {
  kFragCoordConventions_GLSLPrivateFeature , kBlendEquationAdvanced_GLSLPrivateFeature , kBlendFuncExtended_GLSLPrivateFeature , kFramebufferFetch_GLSLPrivateFeature ,
  kNoPerspectiveInterpolation_GLSLPrivateFeature , kSampleVariables_GLSLPrivateFeature , kLastGLSLPrivateFeature = kSampleVariables_GLSLPrivateFeature
}
 
enum  InterfaceQualifier { kIn_InterfaceQualifier , kOut_InterfaceQualifier , kLastInterfaceQualifier = kOut_InterfaceQualifier }
 
enum  {
  kExtensions , kDefinitions , kPrecisionQualifier , kLayoutQualifiers ,
  kUniforms , kInputs , kOutputs , kFunctions ,
  kMain , kCode , kPrealloc = kCode + 6
}
 
typedef SkTBlockList< GrShaderVarVarArray
 

Protected Member Functions

void appendDecls (const VarArray &vars, SkString *out) const
 
void appendFunctionDecl (SkSLType returnType, const char *mangledName, SkSpan< const GrShaderVar > args)
 
bool addFeature (uint32_t featureBit, const char *extensionName)
 
void addLayoutQualifier (const char *param, InterfaceQualifier)
 
void compileAndAppendLayoutQualifiers ()
 
void nextStage ()
 
void deleteStage ()
 
SkStringextensions ()
 
SkStringdefinitions ()
 
SkStringprecisionQualifier ()
 
SkStringlayoutQualifiers ()
 
SkStringuniforms ()
 
SkStringinputs ()
 
SkStringoutputs ()
 
SkStringfunctions ()
 
SkStringmain ()
 
SkStringcode ()
 
virtual void onFinalize ()=0
 

Protected Attributes

GrGLSLProgramBuilderfProgramBuilder
 
std::string fCompilerString
 
skia_private::STArray< kPrealloc, SkStringfShaderStrings
 
SkString fCode
 
SkString fFunctions
 
SkString fExtensions
 
SkSL::StatementArray fDeclarations
 
VarArray fInputs
 
VarArray fOutputs
 
uint32_t fFeaturesAddedMask
 
skia_private::STArray< 1, SkStringfLayoutParams [kLastInterfaceQualifier+1]
 
int fCodeIndex
 
bool fFinalized
 
int fTmpVariableCounter
 

Friends

class GrGLSLProgramBuilder
 
class GrGLProgramBuilder
 
class GrD3DPipelineStateBuilder
 
class GrDawnProgramBuilder
 
class GrGLSLVaryingHandler
 
class GrGLPathProgramBuilder
 
class GrVkPipelineStateBuilder
 
class GrMtlPipelineStateBuilder
 

Detailed Description

base class for all shaders builders

Definition at line 34 of file GrGLSLShaderBuilder.h.

Member Typedef Documentation

◆ SamplerHandle

using GrGLSLShaderBuilder::SamplerHandle = GrGLSLUniformHandler::SamplerHandle

Definition at line 39 of file GrGLSLShaderBuilder.h.

◆ VarArray

Definition at line 185 of file GrGLSLShaderBuilder.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
kExtensions 
kDefinitions 
kPrecisionQualifier 
kLayoutQualifiers 
kUniforms 
kInputs 
kOutputs 
kFunctions 
kMain 
kCode 
kPrealloc 

Definition at line 252 of file GrGLSLShaderBuilder.h.

◆ GLSLPrivateFeature

Features that should only be enabled internally by the builders.

Enumerator
kFragCoordConventions_GLSLPrivateFeature 
kBlendEquationAdvanced_GLSLPrivateFeature 
kBlendFuncExtended_GLSLPrivateFeature 
kFramebufferFetch_GLSLPrivateFeature 
kNoPerspectiveInterpolation_GLSLPrivateFeature 
kSampleVariables_GLSLPrivateFeature 
kLastGLSLPrivateFeature 

Definition at line 195 of file GrGLSLShaderBuilder.h.

◆ InterfaceQualifier

Enumerator
kIn_InterfaceQualifier 
kOut_InterfaceQualifier 
kLastInterfaceQualifier 

Definition at line 212 of file GrGLSLShaderBuilder.h.

Constructor & Destructor Documentation

◆ GrGLSLShaderBuilder()

GrGLSLShaderBuilder::GrGLSLShaderBuilder ( GrGLSLProgramBuilder program)

Definition at line 23 of file GrGLSLShaderBuilder.cpp.

24 : fProgramBuilder(program)
29 , fFinalized(false)
31 // We push back some placeholder pointers which will later become our header
32 for (int i = 0; i <= kCode; i++) {
34 }
35
36 this->main() = "void main() {";
37}
static const int kVarsPerBlock
skia_private::STArray< kPrealloc, SkString > fShaderStrings
GrGLSLProgramBuilder * fProgramBuilder

◆ ~GrGLSLShaderBuilder()

virtual GrGLSLShaderBuilder::~GrGLSLShaderBuilder ( )
inlinevirtual

Definition at line 37 of file GrGLSLShaderBuilder.h.

37{}

Member Function Documentation

◆ addFeature()

bool GrGLSLShaderBuilder::addFeature ( uint32_t  featureBit,
const char *  extensionName 
)
protected

Definition at line 258 of file GrGLSLShaderBuilder.cpp.

258 {
259 if (featureBit & fFeaturesAddedMask) {
260 return false;
261 }
262 this->extensions().appendf("#extension %s: require\n", extensionName);
263 fFeaturesAddedMask |= featureBit;
264 return true;
265}
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550

◆ addLayoutQualifier()

void GrGLSLShaderBuilder::addLayoutQualifier ( const char *  param,
InterfaceQualifier  interface 
)
protected

Definition at line 274 of file GrGLSLShaderBuilder.cpp.

274 {
277 fLayoutParams[interface].push_back() = param;
278}
#define SkASSERT(cond)
Definition SkAssert.h:116
const GrShaderCaps * shaderCaps() const
skia_private::STArray< 1, SkString > fLayoutParams[kLastInterfaceQualifier+1]
bool mustEnableAdvBlendEqs() const
Definition SkSLUtil.h:39
SkSL::GLSLGeneration fGLSLGeneration
Definition SkSLUtil.h:82

◆ appendColorGamutXform() [1/2]

void GrGLSLShaderBuilder::appendColorGamutXform ( const char *  srcColor,
GrGLSLColorSpaceXformHelper colorXformHelper 
)

Version of above that appends the result to the shader code instead.

Definition at line 251 of file GrGLSLShaderBuilder.cpp.

252 {
253 SkString xform;
254 this->appendColorGamutXform(&xform, srcColor, colorXformHelper);
255 this->codeAppend(xform.c_str());
256}
void codeAppend(const char *str)
void appendColorGamutXform(SkString *out, const char *srcColor, GrGLSLColorSpaceXformHelper *colorXformHelper)
const char * c_str() const
Definition SkString.h:133

◆ appendColorGamutXform() [2/2]

void GrGLSLShaderBuilder::appendColorGamutXform ( SkString out,
const char *  srcColor,
GrGLSLColorSpaceXformHelper colorXformHelper 
)

Adds a helper function to facilitate color gamut transformation, and produces code that returns the srcColor transformed into a new gamut (via multiplication by the xform from colorXformHelper). Premultiplied sources are also handled correctly (colorXformHelper determines if the source is premultipled or not).

Definition at line 141 of file GrGLSLShaderBuilder.cpp.

143 {
144 if (!colorXformHelper || colorXformHelper->isNoop()) {
145 *out = srcColor;
146 return;
147 }
148
150
151 // We define up to three helper functions, to keep things clearer. One for the source transfer
152 // function, one for the (inverse) destination transfer function, and one for the gamut xform.
153 // Any combination of these may be present, although some configurations are much more likely.
154
155 auto emitTFFunc = [this, &uniformHandler](const char* name,
156 GrGLSLProgramDataManager::UniformHandle uniform,
157 skcms_TFType tfType) {
158 const GrShaderVar gTFArgs[] = { GrShaderVar("x", SkSLType::kFloat) };
159 const char* coeffs = uniformHandler->getUniformCStr(uniform);
160 SkString body;
161 // Temporaries to make evaluation line readable. We always use the sRGBish names, so the
162 // PQ and HLG math is confusing.
163 body.appendf("float G = %s[0];", coeffs);
164 body.appendf("float A = %s[1];", coeffs);
165 body.appendf("float B = %s[2];", coeffs);
166 body.appendf("float C = %s[3];", coeffs);
167 body.appendf("float D = %s[4];", coeffs);
168 body.appendf("float E = %s[5];", coeffs);
169 body.appendf("float F = %s[6];", coeffs);
170 body.append("float s = sign(x);");
171 body.append("x = abs(x);");
172 switch (tfType) {
174 body.append("x = (x < D) ? (C * x) + F : pow(A * x + B, G) + E;");
175 break;
177 body.append("x = pow(max(A + B * pow(x, C), 0) / (D + E * pow(x, C)), F);");
178 break;
180 body.append("x = (x*A <= 1) ? pow(x*A, B) : exp((x-E)*C) + D; x *= (F+1);");
181 break;
183 body.append("x /= (F+1); x = (x <= 1) ? A * pow(x, B) : C * log(x - D) + E;");
184 break;
185 default:
186 SkASSERT(false);
187 break;
188 }
189 body.append("return s * x;");
190 SkString funcName = this->getMangledFunctionName(name);
191 this->emitFunction(SkSLType::kFloat, funcName.c_str(), {gTFArgs, std::size(gTFArgs)},
192 body.c_str());
193 return funcName;
194 };
195
196 SkString srcTFFuncName;
197 if (colorXformHelper->applySrcTF()) {
198 srcTFFuncName = emitTFFunc("src_tf", colorXformHelper->srcTFUniform(),
199 colorXformHelper->srcTFType());
200 }
201
202 SkString dstTFFuncName;
203 if (colorXformHelper->applyDstTF()) {
204 dstTFFuncName = emitTFFunc("dst_tf", colorXformHelper->dstTFUniform(),
205 colorXformHelper->dstTFType());
206 }
207
208 SkString gamutXformFuncName;
209 if (colorXformHelper->applyGamutXform()) {
210 const GrShaderVar gGamutXformArgs[] = { GrShaderVar("color", SkSLType::kFloat4) };
211 const char* xform = uniformHandler->getUniformCStr(colorXformHelper->gamutXformUniform());
212 SkString body;
213 body.appendf("color.rgb = (%s * color.rgb);", xform);
214 body.append("return color;");
215 gamutXformFuncName = this->getMangledFunctionName("gamut_xform");
216 this->emitFunction(SkSLType::kFloat4, gamutXformFuncName.c_str(),
217 {gGamutXformArgs, std::size(gGamutXformArgs)}, body.c_str());
218 }
219
220 // Now define a wrapper function that applies all the intermediate steps
221 {
222 const GrShaderVar gColorXformArgs[] = { GrShaderVar("color", SkSLType::kFloat4) };
223 SkString body;
224 if (colorXformHelper->applyUnpremul()) {
225 body.append("color = unpremul(color);");
226 }
227 if (colorXformHelper->applySrcTF()) {
228 body.appendf("color.r = %s(color.r);", srcTFFuncName.c_str());
229 body.appendf("color.g = %s(color.g);", srcTFFuncName.c_str());
230 body.appendf("color.b = %s(color.b);", srcTFFuncName.c_str());
231 }
232 if (colorXformHelper->applyGamutXform()) {
233 body.appendf("color = %s(color);", gamutXformFuncName.c_str());
234 }
235 if (colorXformHelper->applyDstTF()) {
236 body.appendf("color.r = %s(color.r);", dstTFFuncName.c_str());
237 body.appendf("color.g = %s(color.g);", dstTFFuncName.c_str());
238 body.appendf("color.b = %s(color.b);", dstTFFuncName.c_str());
239 }
240 if (colorXformHelper->applyPremul()) {
241 body.append("color.rgb *= color.a;");
242 }
243 body.append("return half4(color);");
244 SkString colorXformFuncName = this->getMangledFunctionName("color_xform");
245 this->emitFunction(SkSLType::kHalf4, colorXformFuncName.c_str(),
246 {gColorXformArgs, std::size(gColorXformArgs)}, body.c_str());
247 out->appendf("%s(%s)", colorXformFuncName.c_str(), srcColor);
248 }
249}
GrGLSLProgramDataManager::UniformHandle gamutXformUniform() const
GrGLSLProgramDataManager::UniformHandle srcTFUniform() const
GrGLSLProgramDataManager::UniformHandle dstTFUniform() const
virtual GrGLSLUniformHandler * uniformHandler()=0
void emitFunction(SkSLType returnType, const char *mangledName, SkSpan< const GrShaderVar > args, const char *body)
SkString getMangledFunctionName(const char *baseName)
virtual const char * getUniformCStr(UniformHandle u) const =0
void append(const char text[])
Definition SkString.h:203
const char * name
Definition fuchsia.cc:50
skcms_TFType
@ skcms_TFType_HLGish
@ skcms_TFType_sRGBish
@ skcms_TFType_HLGinvish
@ skcms_TFType_PQish

◆ appendDecls()

void GrGLSLShaderBuilder::appendDecls ( const VarArray vars,
SkString out 
) const
protected

Definition at line 267 of file GrGLSLShaderBuilder.cpp.

267 {
268 for (const auto& v : vars.items()) {
269 v.appendDecl(fProgramBuilder->shaderCaps(), out);
270 out->append(";\n");
271 }
272}

◆ appendFunctionDecl()

void GrGLSLShaderBuilder::appendFunctionDecl ( SkSLType  returnType,
const char *  mangledName,
SkSpan< const GrShaderVar args 
)
protected

Definition at line 54 of file GrGLSLShaderBuilder.cpp.

56 {
57 this->functions().appendf("%s %s(", SkSLTypeString(returnType), mangledName);
58 for (size_t i = 0; i < args.size(); ++i) {
59 if (i > 0) {
60 this->functions().append(", ");
61 }
62 args[i].appendDecl(fProgramBuilder->shaderCaps(), &this->functions());
63 }
64
65 this->functions().append(")");
66}
const char * SkSLTypeString(SkSLType t)

◆ appendInputLoad()

void GrGLSLShaderBuilder::appendInputLoad ( SamplerHandle  samplerHandle)

Appends a load of an input attachment into the shader code.

Definition at line 133 of file GrGLSLShaderBuilder.cpp.

133 {
134 const char* input = fProgramBuilder->inputSamplerVariable(samplerHandle);
136 load.appendf("subpassLoad(%s)", input);
138 this->codeAppend(load.c_str());
139}
static void append_texture_swizzle(SkString *out, skgpu::Swizzle swizzle)
SI T load(const P *ptr)
const char * inputSamplerVariable(SamplerHandle handle) const
skgpu::Swizzle inputSamplerSwizzle(SamplerHandle handle) const

◆ appendTextureLookup() [1/2]

void GrGLSLShaderBuilder::appendTextureLookup ( SamplerHandle  samplerHandle,
const char *  coordName,
GrGLSLColorSpaceXformHelper colorXformHelper = nullptr 
)

Version of above that appends the result to the shader code instead.

Definition at line 109 of file GrGLSLShaderBuilder.cpp.

111 {
112 SkString lookup;
113 this->appendTextureLookup(&lookup, samplerHandle, coordName);
114 this->appendColorGamutXform(lookup.c_str(), colorXformHelper);
115}
void appendTextureLookup(SkString *out, SamplerHandle, const char *coordName) const

◆ appendTextureLookup() [2/2]

void GrGLSLShaderBuilder::appendTextureLookup ( SkString out,
SamplerHandle  samplerHandle,
const char *  coordName 
) const

Appends a 2D texture sample with projection if necessary. The vec length and swizzle order of the result depends on the GrProcessor::TextureSampler associated with the SamplerHandle.

Definition at line 101 of file GrGLSLShaderBuilder.cpp.

103 {
104 const char* sampler = fProgramBuilder->samplerVariable(samplerHandle);
105 out->appendf("sample(%s, %s)", sampler, coordName);
107}
const char * samplerVariable(SamplerHandle handle) const
skgpu::Swizzle samplerSwizzle(SamplerHandle handle) const

◆ appendTextureLookupAndBlend()

void GrGLSLShaderBuilder::appendTextureLookupAndBlend ( const char *  dst,
SkBlendMode  mode,
SamplerHandle  samplerHandle,
const char *  coordName,
GrGLSLColorSpaceXformHelper colorXformHelper = nullptr 
)

Does the work of appendTextureLookup and blends the result by dst, treating the texture lookup as the src input to the blend. The dst is assumed to be half4 and the result is always a half4. If dst is nullptr we use half4(1) as the blend dst.

Definition at line 117 of file GrGLSLShaderBuilder.cpp.

122 {
123 if (!dst) {
124 dst = "half4(1)";
125 }
126 SkString lookup;
127 this->codeAppendf("%s(", skgpu::BlendFuncName(mode));
128 this->appendTextureLookup(&lookup, samplerHandle, coordName);
129 this->appendColorGamutXform(lookup.c_str(), colorXformHelper);
130 this->codeAppendf(", %s)", dst);
131}
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
dst
Definition cp.py:12
const char * BlendFuncName(SkBlendMode mode)
Definition Blend.cpp:18

◆ code() [1/3]

SkString & GrGLSLShaderBuilder::code ( )
inlineprotected

Definition at line 248 of file GrGLSLShaderBuilder.h.

248{ return fShaderStrings[fCodeIndex]; }

◆ code() [2/3]

this GrGLSLShaderBuilder::code ( )

◆ code() [3/3]

this GrGLSLShaderBuilder::code ( )

◆ codeAppend() [1/2]

void GrGLSLShaderBuilder::codeAppend ( const char *  str)
inline

Definition at line 120 of file GrGLSLShaderBuilder.h.

120{ this->code().append(str); }
this code().appendVAList(format

◆ codeAppend() [2/2]

void GrGLSLShaderBuilder::codeAppend ( const char *  str,
size_t  length 
)
inline

Definition at line 122 of file GrGLSLShaderBuilder.h.

122{ this->code().append(str, length); }
size_t length

◆ codeAppendf()

void GrGLSLShaderBuilder::codeAppendf ( const char  format[],
  ... 
)

Called by GrGLSLProcessors to add code to one of the shaders.

◆ codePrependf()

void GrGLSLShaderBuilder::codePrependf ( const char  format[],
  ... 
)

◆ compileAndAppendLayoutQualifiers()

void GrGLSLShaderBuilder::compileAndAppendLayoutQualifiers ( )
protected

Definition at line 280 of file GrGLSLShaderBuilder.cpp.

280 {
281 static const char* interfaceQualifierNames[] = {
282 "in",
283 "out"
284 };
285
286 for (int interface = 0; interface <= kLastInterfaceQualifier; ++interface) {
287 const TArray<SkString>& params = fLayoutParams[interface];
288 if (params.empty()) {
289 continue;
290 }
291 this->layoutQualifiers().appendf("layout(%s", params[0].c_str());
292 for (int i = 1; i < params.size(); ++i) {
293 this->layoutQualifiers().appendf(", %s", params[i].c_str());
294 }
295 this->layoutQualifiers().appendf(") %s;\n", interfaceQualifierNames[interface]);
296 }
297
300 static_assert(std::size(interfaceQualifierNames) == kLastInterfaceQualifier + 1);
301}
const EmbeddedViewParams * params

◆ declAppend()

void GrGLSLShaderBuilder::declAppend ( const GrShaderVar var)

Appends a variable declaration to one of the shaders

Definition at line 39 of file GrGLSLShaderBuilder.cpp.

39 {
40 SkString tempDecl;
41 var.appendDecl(fProgramBuilder->shaderCaps(), &tempDecl);
42 this->codeAppendf("%s;", tempDecl.c_str());
43}
void appendDecl(const GrShaderCaps *, SkString *out) const

◆ declareGlobal()

void GrGLSLShaderBuilder::declareGlobal ( const GrShaderVar v)

Definition at line 45 of file GrGLSLShaderBuilder.cpp.

45 {
46 v.appendDecl(this->getProgramBuilder()->shaderCaps(), &this->definitions());
47 this->definitions().append(";");
48}
this definitions().appendVAList(fmt
GrGLSLProgramBuilder * getProgramBuilder()

◆ defineConstant() [1/3]

void GrGLSLShaderBuilder::defineConstant ( const char *  name,
float  value 
)
inline

Definition at line 85 of file GrGLSLShaderBuilder.h.

85 {
86 this->definitions().appendf("const float %s = %f;\n", name, value);
87 }

◆ defineConstant() [2/3]

void GrGLSLShaderBuilder::defineConstant ( const char *  name,
int  value 
)
inline

Definition at line 81 of file GrGLSLShaderBuilder.h.

81 {
82 this->definitions().appendf("const int %s = %i;\n", name, value);
83 }

◆ defineConstant() [3/3]

void GrGLSLShaderBuilder::defineConstant ( const char *  type,
const char *  name,
const char *  value 
)
inline

Adds a constant declaration to the top of the shader.

Definition at line 77 of file GrGLSLShaderBuilder.h.

77 {
78 this->definitions().appendf("const %s %s = %s;\n", type, name, value);
79 }

◆ defineConstantf()

void GrGLSLShaderBuilder::defineConstantf ( const char *  type,
const char *  name,
const char *  fmt,
  ... 
)

◆ definitionAppend()

void GrGLSLShaderBuilder::definitionAppend ( const char *  str)
inline

Definition at line 99 of file GrGLSLShaderBuilder.h.

99{ this->definitions().append(str); }

◆ definitions() [1/3]

SkString & GrGLSLShaderBuilder::definitions ( )
inlineprotected

Definition at line 240 of file GrGLSLShaderBuilder.h.

240{ return fShaderStrings[kDefinitions]; }

◆ definitions() [2/3]

this GrGLSLShaderBuilder::definitions ( )

◆ definitions() [3/3]

this GrGLSLShaderBuilder::definitions ( )

◆ deleteStage()

void GrGLSLShaderBuilder::deleteStage ( )
inlineprotected

Definition at line 234 of file GrGLSLShaderBuilder.h.

234 {
236 fCodeIndex--;
237 }

◆ emitFunction() [1/2]

void GrGLSLShaderBuilder::emitFunction ( const char *  declaration,
const char *  body 
)

Definition at line 78 of file GrGLSLShaderBuilder.cpp.

78 {
79 this->functions().appendf("%s {\n"
80 "%s"
81 "}\n\n", declaration, body);
82}

◆ emitFunction() [2/2]

void GrGLSLShaderBuilder::emitFunction ( SkSLType  returnType,
const char *  mangledName,
SkSpan< const GrShaderVar args,
const char *  body 
)

Emits a helper function outside of main() in the fragment shader.

Definition at line 68 of file GrGLSLShaderBuilder.cpp.

71 {
72 this->appendFunctionDecl(returnType, mangledName, args);
73 this->functions().appendf(" {\n"
74 "%s"
75 "}\n\n", body);
76}
void appendFunctionDecl(SkSLType returnType, const char *mangledName, SkSpan< const GrShaderVar > args)

◆ emitFunctionPrototype() [1/2]

void GrGLSLShaderBuilder::emitFunctionPrototype ( const char *  declaration)

Definition at line 91 of file GrGLSLShaderBuilder.cpp.

91 {
92 this->functions().appendf("%s\n", declaration);
93}

◆ emitFunctionPrototype() [2/2]

void GrGLSLShaderBuilder::emitFunctionPrototype ( SkSLType  returnType,
const char *  mangledName,
SkSpan< const GrShaderVar args 
)

Emits a prototype for a helper function outside of main() in the fragment shader.

Definition at line 84 of file GrGLSLShaderBuilder.cpp.

86 {
87 this->appendFunctionDecl(returnType, mangledName, args);
88 this->functions().append(";\n");
89}

◆ extensions()

SkString & GrGLSLShaderBuilder::extensions ( )
inlineprotected

Definition at line 239 of file GrGLSLShaderBuilder.h.

239{ return fShaderStrings[kExtensions]; }

◆ finalize()

void GrGLSLShaderBuilder::finalize ( uint32_t  visibility)

Combines the various parts of the shader to create a single finalized shader string.

Definition at line 303 of file GrGLSLShaderBuilder.cpp.

303 {
306 SkASSERT(visibility);
308 this->appendDecls(fInputs, &this->inputs());
309 this->appendDecls(fOutputs, &this->outputs());
310 this->onFinalize();
311 // append the 'footer' to code
312 this->code().append("}");
313
314 for (int i = 0; i <= fCodeIndex; i++) {
315 fCompilerString.append(fShaderStrings[i].c_str(), fShaderStrings[i].size());
316 }
317
318 fFinalized = true;
319}
GrShaderFlags
void appendUniformDecls(GrShaderFlags visibility, SkString *) const
virtual void onFinalize()=0
void appendDecls(const VarArray &vars, SkString *out) const
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ functions()

SkString & GrGLSLShaderBuilder::functions ( )
inlineprotected

Definition at line 246 of file GrGLSLShaderBuilder.h.

246{ return fShaderStrings[kFunctions]; }

◆ getMangledFunctionName()

SkString GrGLSLShaderBuilder::getMangledFunctionName ( const char *  baseName)

Generates a mangled name for a helper function in the fragment shader. Will give consistent results if called more than once.

Definition at line 50 of file GrGLSLShaderBuilder.cpp.

50 {
51 return fProgramBuilder->nameVariable(/*prefix=*/'\0', baseName);
52}
SkString nameVariable(char prefix, const char *name, bool mangle=true)

◆ getProgramBuilder()

GrGLSLProgramBuilder * GrGLSLShaderBuilder::getProgramBuilder ( )
inline

Get parent builder for adding uniforms.

Definition at line 165 of file GrGLSLShaderBuilder.h.

165{ return fProgramBuilder; }

◆ inputs()

SkString & GrGLSLShaderBuilder::inputs ( )
inlineprotected

Definition at line 244 of file GrGLSLShaderBuilder.h.

244{ return fShaderStrings[kInputs]; }

◆ layoutQualifiers()

SkString & GrGLSLShaderBuilder::layoutQualifiers ( )
inlineprotected

Definition at line 242 of file GrGLSLShaderBuilder.h.

◆ main()

SkString & GrGLSLShaderBuilder::main ( )
inlineprotected

Definition at line 247 of file GrGLSLShaderBuilder.h.

247{ return fShaderStrings[kMain]; }

◆ newTmpVarName()

SkString GrGLSLShaderBuilder::newTmpVarName ( const char *  suffix)
inline

Definition at line 105 of file GrGLSLShaderBuilder.h.

105 {
106 int tmpIdx = fTmpVariableCounter++;
107 return SkStringPrintf("_tmp_%d_%s", tmpIdx, suffix);
108 }
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287

◆ nextStage()

void GrGLSLShaderBuilder::nextStage ( )
inlineprotected

Definition at line 229 of file GrGLSLShaderBuilder.h.

229 {
231 fCodeIndex++;
232 }

◆ onFinalize()

virtual void GrGLSLShaderBuilder::onFinalize ( )
protectedpure virtual

◆ outputs()

SkString & GrGLSLShaderBuilder::outputs ( )
inlineprotected

Definition at line 245 of file GrGLSLShaderBuilder.h.

245{ return fShaderStrings[kOutputs]; }

◆ precisionQualifier()

SkString & GrGLSLShaderBuilder::precisionQualifier ( )
inlineprotected

Definition at line 241 of file GrGLSLShaderBuilder.h.

◆ uniforms()

SkString & GrGLSLShaderBuilder::uniforms ( )
inlineprotected

Definition at line 243 of file GrGLSLShaderBuilder.h.

243{ return fShaderStrings[kUniforms]; }

◆ va_end() [1/3]

GrGLSLShaderBuilder::va_end ( args  )

◆ va_end() [2/3]

GrGLSLShaderBuilder::va_end ( args  )

◆ va_end() [3/3]

GrGLSLShaderBuilder::va_end ( args  )

◆ va_start() [1/3]

GrGLSLShaderBuilder::va_start ( args  ,
fmt   
)

◆ va_start() [2/3]

void GrGLSLShaderBuilder::va_start ( args  ,
format   
)

◆ va_start() [3/3]

void GrGLSLShaderBuilder::va_start ( args  ,
format   
)

Friends And Related Symbol Documentation

◆ GrD3DPipelineStateBuilder

friend class GrD3DPipelineStateBuilder
friend

Definition at line 288 of file GrGLSLShaderBuilder.h.

◆ GrDawnProgramBuilder

friend class GrDawnProgramBuilder
friend

Definition at line 289 of file GrGLSLShaderBuilder.h.

◆ GrGLPathProgramBuilder

friend class GrGLPathProgramBuilder
friend

Definition at line 291 of file GrGLSLShaderBuilder.h.

◆ GrGLProgramBuilder

friend class GrGLProgramBuilder
friend

Definition at line 287 of file GrGLSLShaderBuilder.h.

◆ GrGLSLProgramBuilder

friend class GrGLSLProgramBuilder
friend

Definition at line 286 of file GrGLSLShaderBuilder.h.

◆ GrGLSLVaryingHandler

friend class GrGLSLVaryingHandler
friend

Definition at line 290 of file GrGLSLShaderBuilder.h.

◆ GrMtlPipelineStateBuilder

friend class GrMtlPipelineStateBuilder
friend

Definition at line 293 of file GrGLSLShaderBuilder.h.

◆ GrVkPipelineStateBuilder

friend class GrVkPipelineStateBuilder
friend

Definition at line 292 of file GrGLSLShaderBuilder.h.

Member Data Documentation

◆ args [1/2]

this GrGLSLShaderBuilder::args
Initial value:
{
this->definitions().appendf("const %s %s = ", type, name)

Definition at line 92 of file GrGLSLShaderBuilder.h.

◆ args [2/2]

this GrGLSLShaderBuilder::args

Definition at line 94 of file GrGLSLShaderBuilder.h.

◆ fCode

SkString GrGLSLShaderBuilder::fCode
protected

Definition at line 270 of file GrGLSLShaderBuilder.h.

◆ fCodeIndex

int GrGLSLShaderBuilder::fCodeIndex
protected

Definition at line 280 of file GrGLSLShaderBuilder.h.

◆ fCompilerString

std::string GrGLSLShaderBuilder::fCompilerString
protected

Definition at line 268 of file GrGLSLShaderBuilder.h.

◆ fDeclarations

SkSL::StatementArray GrGLSLShaderBuilder::fDeclarations
protected

Definition at line 274 of file GrGLSLShaderBuilder.h.

◆ fExtensions

SkString GrGLSLShaderBuilder::fExtensions
protected

Definition at line 272 of file GrGLSLShaderBuilder.h.

◆ fFeaturesAddedMask

uint32_t GrGLSLShaderBuilder::fFeaturesAddedMask
protected

Definition at line 278 of file GrGLSLShaderBuilder.h.

◆ fFinalized

bool GrGLSLShaderBuilder::fFinalized
protected

Definition at line 281 of file GrGLSLShaderBuilder.h.

◆ fFunctions

SkString GrGLSLShaderBuilder::fFunctions
protected

Definition at line 271 of file GrGLSLShaderBuilder.h.

◆ fInputs

VarArray GrGLSLShaderBuilder::fInputs
protected

Definition at line 276 of file GrGLSLShaderBuilder.h.

◆ fLayoutParams

skia_private::STArray<1, SkString> GrGLSLShaderBuilder::fLayoutParams[kLastInterfaceQualifier+1]
protected

Definition at line 279 of file GrGLSLShaderBuilder.h.

◆ fOutputs

VarArray GrGLSLShaderBuilder::fOutputs
protected

Definition at line 277 of file GrGLSLShaderBuilder.h.

◆ fProgramBuilder

GrGLSLProgramBuilder* GrGLSLShaderBuilder::fProgramBuilder
protected

Definition at line 267 of file GrGLSLShaderBuilder.h.

◆ fShaderStrings

skia_private::STArray<kPrealloc, SkString> GrGLSLShaderBuilder::fShaderStrings
protected

Definition at line 269 of file GrGLSLShaderBuilder.h.

◆ fTmpVariableCounter

int GrGLSLShaderBuilder::fTmpVariableCounter
protected

Definition at line 284 of file GrGLSLShaderBuilder.h.

◆ n

GrGLSLShaderBuilder::n

Definition at line 96 of file GrGLSLShaderBuilder.h.


The documentation for this class was generated from the following files: