Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
GrGLSLProgramBuilder Class Referenceabstract

#include <GrGLSLProgramBuilder.h>

Inheritance diagram for GrGLSLProgramBuilder:
GrD3DPipelineStateBuilder GrGLProgramBuilder GrMtlPipelineStateBuilder GrVkPipelineStateBuilder

Public Types

using UniformHandle = GrGLSLUniformHandler::UniformHandle
 
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle
 

Public Member Functions

virtual ~GrGLSLProgramBuilder ()
 
virtual const GrCapscaps () const =0
 
const GrShaderCapsshaderCaps () const
 
GrSurfaceOrigin origin () const
 
const GrPipelinepipeline () const
 
const GrGeometryProcessorgeometryProcessor () const
 
bool snapVerticesToPixelCenters () const
 
bool hasPointSize () const
 
const GrProgramDescdesc () const
 
void appendUniformDecls (GrShaderFlags visibility, SkString *) const
 
const char * samplerVariable (SamplerHandle handle) const
 
skgpu::Swizzle samplerSwizzle (SamplerHandle handle) const
 
const char * inputSamplerVariable (SamplerHandle handle) const
 
skgpu::Swizzle inputSamplerSwizzle (SamplerHandle handle) const
 
void addRTFlipUniform (const char *name)
 
SkString nameVariable (char prefix, const char *name, bool mangle=true)
 
bool emitTextureSamplersForFPs (const GrFragmentProcessor &fp, GrFragmentProcessor::ProgramImpl &impl, int *samplerIndex)
 
void advanceStage ()
 
void writeFPFunction (const GrFragmentProcessor &fp, GrFragmentProcessor::ProgramImpl &impl)
 
std::string invokeFP (const GrFragmentProcessor &fp, const GrFragmentProcessor::ProgramImpl &impl, const char *inputColor, const char *destColor, const char *coords) const
 
bool fragmentProcessorHasCoordsParam (const GrFragmentProcessor *) const
 
virtual GrGLSLUniformHandleruniformHandler ()=0
 
virtual const GrGLSLUniformHandleruniformHandler () const =0
 
virtual GrGLSLVaryingHandlervaryingHandler ()=0
 
virtual void finalizeFragmentSecondaryColor (GrShaderVar &outputColor)
 

Public Attributes

GrGLSLVertexBuilder fVS
 
GrGLSLFragmentShaderBuilder fFS
 
const GrProgramDescfDesc
 
const GrProgramInfofProgramInfo
 
GrGLSLBuiltinUniformHandles fUniformHandles
 
std::unique_ptr< GrGeometryProcessor::ProgramImplfGPImpl
 
std::unique_ptr< GrXferProcessor::ProgramImplfXPImpl
 
std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fFPImpls
 
SamplerHandle fDstTextureSamplerHandle
 
GrSurfaceOrigin fDstTextureOrigin
 

Static Public Attributes

static const int kVarsPerBlock = 8
 

Protected Member Functions

 GrGLSLProgramBuilder (const GrProgramDesc &, const GrProgramInfo &)
 
void addFeature (GrShaderFlags shaders, uint32_t featureBit, const char *extensionName)
 
bool emitAndInstallProcs ()
 
void finalizeShaders ()
 
bool fragColorIsInOut () const
 

Detailed Description

Definition at line 39 of file GrGLSLProgramBuilder.h.

Member Typedef Documentation

◆ SamplerHandle

using GrGLSLProgramBuilder::SamplerHandle = GrGLSLUniformHandler::SamplerHandle

Definition at line 42 of file GrGLSLProgramBuilder.h.

◆ UniformHandle

Definition at line 41 of file GrGLSLProgramBuilder.h.

Constructor & Destructor Documentation

◆ ~GrGLSLProgramBuilder()

GrGLSLProgramBuilder::~GrGLSLProgramBuilder ( )
virtualdefault

◆ GrGLSLProgramBuilder()

GrGLSLProgramBuilder::GrGLSLProgramBuilder ( const GrProgramDesc desc,
const GrProgramInfo programInfo 
)
explicitprotected

Definition at line 40 of file GrGLSLProgramBuilder.cpp.

42 : fVS(this)
43 , fFS(this)
44 , fDesc(desc)
45 , fProgramInfo(programInfo)
46 , fNumFragmentSamplers(0) {}
const GrProgramDesc & fDesc
const GrProgramDesc & desc() const
GrGLSLVertexBuilder fVS
const GrProgramInfo & fProgramInfo
GrGLSLFragmentShaderBuilder fFS

Member Function Documentation

◆ addFeature()

void GrGLSLProgramBuilder::addFeature ( GrShaderFlags  shaders,
uint32_t  featureBit,
const char *  extensionName 
)
protected

Definition at line 50 of file GrGLSLProgramBuilder.cpp.

52 {
53 if (shaders & kVertex_GrShaderFlag) {
54 fVS.addFeature(featureBit, extensionName);
55 }
56 if (shaders & kFragment_GrShaderFlag) {
57 fFS.addFeature(featureBit, extensionName);
58 }
59}
@ kVertex_GrShaderFlag
Definition: GrTypesPriv.h:286
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
bool addFeature(uint32_t featureBit, const char *extensionName)

◆ addRTFlipUniform()

void GrGLSLProgramBuilder::addRTFlipUniform ( const char *  name)

Definition at line 514 of file GrGLSLProgramBuilder.cpp.

514 {
518 uniformHandler->internalAddUniformArray(nullptr,
521 name,
522 false,
523 0,
524 nullptr);
525}
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual GrGLSLUniformHandler * uniformHandler()=0
GrGLSLBuiltinUniformHandles fUniformHandles
virtual UniformHandle internalAddUniformArray(const GrProcessor *owner, uint32_t visibility, SkSLType type, const char *name, bool mangleName, int arrayCount, const char **outName)=0
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
GrGLSLProgramDataManager::UniformHandle fRTFlipUni

◆ advanceStage()

void GrGLSLProgramBuilder::advanceStage ( )
inline

advanceStage is called by program creator between each processor's emit code. It increments the stage index for variable name mangling, and also ensures verification variables in the fragment shader are cleared.

Definition at line 100 of file GrGLSLProgramBuilder.h.

100 {
101 fStageIndex++;
102 SkDEBUGCODE(fFS.debugOnly_resetPerStageVerification();)
103 fFS.nextStage();
104 }
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()

◆ appendUniformDecls()

void GrGLSLProgramBuilder::appendUniformDecls ( GrShaderFlags  visibility,
SkString out 
) const

Definition at line 510 of file GrGLSLProgramBuilder.cpp.

510 {
511 this->uniformHandler()->appendUniformDecls(visibility, out);
512}
virtual void appendUniformDecls(GrShaderFlags visibility, SkString *) const =0

◆ caps()

virtual const GrCaps * GrGLSLProgramBuilder::caps ( ) const
pure virtual

◆ desc()

const GrProgramDesc & GrGLSLProgramBuilder::desc ( ) const
inline

Definition at line 57 of file GrGLSLProgramBuilder.h.

57{ return fDesc; }

◆ emitAndInstallProcs()

bool GrGLSLProgramBuilder::emitAndInstallProcs ( )
protected

Definition at line 61 of file GrGLSLProgramBuilder.cpp.

61 {
62 // First we loop over all of the installed processors and collect coord transforms. These will
63 // be sent to the ProgramImpl in its emitCode function
64 SkString inputColor;
65 SkString inputCoverage;
66 if (!this->emitAndInstallPrimProc(&inputColor, &inputCoverage)) {
67 return false;
68 }
69 if (!this->emitAndInstallDstTexture()) {
70 return false;
71 }
72 if (!this->emitAndInstallFragProcs(&inputColor, &inputCoverage)) {
73 return false;
74 }
75 if (!this->emitAndInstallXferProc(inputColor, inputCoverage)) {
76 return false;
77 }
78 fGPImpl->emitTransformCode(&fVS, this->uniformHandler());
79
80 return this->checkSamplerCounts();
81}
std::unique_ptr< GrGeometryProcessor::ProgramImpl > fGPImpl

◆ emitTextureSamplersForFPs()

bool GrGLSLProgramBuilder::emitTextureSamplersForFPs ( const GrFragmentProcessor fp,
GrFragmentProcessor::ProgramImpl impl,
int samplerIndex 
)

Emits samplers for TextureEffect fragment processors as needed. fp can be a TextureEffect, or a tree containing zero or more TextureEffects.

Definition at line 151 of file GrGLSLProgramBuilder.cpp.

153 {
154 bool ok = true;
155 fp.visitWithImpls([&](const GrFragmentProcessor& fp, GrFragmentProcessor::ProgramImpl& impl) {
156 if (const GrTextureEffect* te = fp.asTextureEffect()) {
157 SkString name = SkStringPrintf("TextureSampler_%d", *samplerIndex);
158 *samplerIndex += 1;
159
160 GrSamplerState samplerState = te->samplerState();
161 const GrBackendFormat& format = te->view().proxy()->backendFormat();
162 skgpu::Swizzle swizzle = te->view().swizzle();
163 SamplerHandle handle = this->emitSampler(format, samplerState, swizzle, name.c_str());
164 if (!handle.isValid()) {
165 ok = false;
166 return;
167 }
168 static_cast<GrTextureEffect::Impl&>(impl).setSamplerHandle(handle);
169 }
170 }, impl);
171
172 return ok;
173}
static bool ok(int result)
void setSamplerHandle(GrGLSLShaderBuilder::SamplerHandle handle)
const uint32_t fp

◆ finalizeFragmentSecondaryColor()

virtual void GrGLSLProgramBuilder::finalizeFragmentSecondaryColor ( GrShaderVar outputColor)
inlinevirtual

Reimplemented in GrD3DPipelineStateBuilder, and GrVkPipelineStateBuilder.

Definition at line 130 of file GrGLSLProgramBuilder.h.

130{}

◆ finalizeShaders()

void GrGLSLProgramBuilder::finalizeShaders ( )
protected

Definition at line 533 of file GrGLSLProgramBuilder.cpp.

533 {
534 this->varyingHandler()->finalize();
537}
virtual GrGLSLVaryingHandler * varyingHandler()=0
void finalize(uint32_t visibility)

◆ fragColorIsInOut()

bool GrGLSLProgramBuilder::fragColorIsInOut ( ) const
inlineprotected

Definition at line 159 of file GrGLSLProgramBuilder.h.

159{ return fFS.primaryColorOutputIsInOut(); }

◆ fragmentProcessorHasCoordsParam()

bool GrGLSLProgramBuilder::fragmentProcessorHasCoordsParam ( const GrFragmentProcessor fp) const

If the FP's coords are unused or all uses have been lifted to interpolated varyings then don't put coords in the FP's function signature or call sites.

Definition at line 527 of file GrGLSLProgramBuilder.cpp.

527 {
528 auto iter = fFPCoordsMap.find(fp);
529 return (iter != fFPCoordsMap.end()) ? iter->second.hasCoordsParam
530 : fp->usesSampleCoords();
531}

◆ geometryProcessor()

const GrGeometryProcessor & GrGLSLProgramBuilder::geometryProcessor ( ) const
inline

Definition at line 51 of file GrGLSLProgramBuilder.h.

51{ return fProgramInfo.geomProc(); }
const GrGeometryProcessor & geomProc() const
Definition: GrProgramInfo.h:40

◆ hasPointSize()

bool GrGLSLProgramBuilder::hasPointSize ( ) const
inline

Definition at line 55 of file GrGLSLProgramBuilder.h.

GrPrimitiveType primitiveType() const
Definition: GrProgramInfo.h:42

◆ inputSamplerSwizzle()

skgpu::Swizzle GrGLSLProgramBuilder::inputSamplerSwizzle ( SamplerHandle  handle) const
inline

Definition at line 73 of file GrGLSLProgramBuilder.h.

73 {
74 return this->uniformHandler()->inputSamplerSwizzle(handle);
75 }
virtual skgpu::Swizzle inputSamplerSwizzle(SamplerHandle) const

◆ inputSamplerVariable()

const char * GrGLSLProgramBuilder::inputSamplerVariable ( SamplerHandle  handle) const
inline

Definition at line 69 of file GrGLSLProgramBuilder.h.

69 {
70 return this->uniformHandler()->inputSamplerVariable(handle);
71 }
virtual const char * inputSamplerVariable(SamplerHandle) const

◆ invokeFP()

std::string GrGLSLProgramBuilder::invokeFP ( const GrFragmentProcessor fp,
const GrFragmentProcessor::ProgramImpl impl,
const char *  inputColor,
const char *  destColor,
const char *  coords 
) const

Returns a function-call invocation of fp in string form, passing the appropriate combination of inputColor, destColor and fLocalCoordsVar for the FP.

Definition at line 175 of file GrGLSLProgramBuilder.cpp.

179 {
180 if (fp.isBlendFunction()) {
181 if (this->fragmentProcessorHasCoordsParam(&fp)) {
182 return SkSL::String::printf("%s(%s, %s, %s)", impl.functionName(), inputColor,
183 destColor, coords);
184 } else {
185 return SkSL::String::printf("%s(%s, %s)", impl.functionName(), inputColor, destColor);
186 }
187 }
188
189 if (this->fragmentProcessorHasCoordsParam(&fp)) {
190 return SkSL::String::printf("%s(%s, %s)", impl.functionName(), inputColor, coords);
191 } else {
192 return SkSL::String::printf("%s(%s)", impl.functionName(), inputColor);
193 }
194}
bool fragmentProcessorHasCoordsParam(const GrFragmentProcessor *) const
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83

◆ nameVariable()

SkString GrGLSLProgramBuilder::nameVariable ( char  prefix,
const char *  name,
bool  mangle = true 
)

Definition at line 486 of file GrGLSLProgramBuilder.cpp.

486 {
488 if ('\0' == prefix) {
489 out = name;
490 } else {
491 out.printf("%c%s", prefix, name);
492 }
493 if (mangle) {
494 SkString suffix = this->getMangleSuffix();
495 // Names containing "__" are reserved; add "x" if needed to avoid consecutive underscores.
496 const char *underscoreSplitter = out.endsWith('_') ? "x" : "";
497 out.appendf("%s%s", underscoreSplitter, suffix.c_str());
498 }
499 return out;
500}

◆ origin()

GrSurfaceOrigin GrGLSLProgramBuilder::origin ( ) const
inline

Definition at line 49 of file GrGLSLProgramBuilder.h.

49{ return fProgramInfo.origin(); }
GrSurfaceOrigin origin() const
Definition: GrProgramInfo.h:38

◆ pipeline()

const GrPipeline & GrGLSLProgramBuilder::pipeline ( ) const
inline

Definition at line 50 of file GrGLSLProgramBuilder.h.

50{ return fProgramInfo.pipeline(); }
const GrPipeline & pipeline() const
Definition: GrProgramInfo.h:39

◆ samplerSwizzle()

skgpu::Swizzle GrGLSLProgramBuilder::samplerSwizzle ( SamplerHandle  handle) const
inline

Definition at line 65 of file GrGLSLProgramBuilder.h.

65 {
66 return this->uniformHandler()->samplerSwizzle(handle);
67 }
virtual skgpu::Swizzle samplerSwizzle(SamplerHandle) const =0

◆ samplerVariable()

const char * GrGLSLProgramBuilder::samplerVariable ( SamplerHandle  handle) const
inline

Definition at line 61 of file GrGLSLProgramBuilder.h.

61 {
62 return this->uniformHandler()->samplerVariable(handle);
63 }
virtual const char * samplerVariable(SamplerHandle) const =0

◆ shaderCaps()

const GrShaderCaps * GrGLSLProgramBuilder::shaderCaps ( ) const
inline

Definition at line 47 of file GrGLSLProgramBuilder.h.

47{ return this->caps()->shaderCaps(); }
const GrShaderCaps * shaderCaps() const
Definition: GrCaps.h:63
virtual const GrCaps * caps() const =0

◆ snapVerticesToPixelCenters()

bool GrGLSLProgramBuilder::snapVerticesToPixelCenters ( ) const
inline

Definition at line 52 of file GrGLSLProgramBuilder.h.

52 {
54 }
bool snapVerticesToPixelCenters() const
Definition: GrPipeline.h:171

◆ uniformHandler() [1/2]

virtual const GrGLSLUniformHandler * GrGLSLProgramBuilder::uniformHandler ( ) const
pure virtual

◆ uniformHandler() [2/2]

virtual GrGLSLUniformHandler * GrGLSLProgramBuilder::uniformHandler ( )
pure virtual

◆ varyingHandler()

virtual GrGLSLVaryingHandler * GrGLSLProgramBuilder::varyingHandler ( )
pure virtual

◆ writeFPFunction()

void GrGLSLProgramBuilder::writeFPFunction ( const GrFragmentProcessor fp,
GrFragmentProcessor::ProgramImpl impl 
)

Adds the SkSL function that implements an FP assuming its children are already written.

Definition at line 243 of file GrGLSLProgramBuilder.cpp.

244 {
245 constexpr const char* kDstColor = "_dst";
246 const char* const inputColor = fp.isBlendFunction() ? "_src" : "_input";
247 const char* sampleCoords = "_coords";
248 fFS.nextStage();
249 // Conceptually, an FP is always sampled at a particular coordinate. However, if it is only
250 // sampled by a chain of uniform matrix expressions (or legacy coord transforms), the value that
251 // would have been passed to _coords is lifted to the vertex shader and
252 // varying. In that case it uses that variable and we do not pass a second argument for _coords.
254 int numParams = 0;
255
256 params[numParams++] = GrShaderVar(inputColor, SkSLType::kHalf4);
257
258 if (fp.isBlendFunction()) {
259 // Blend functions take a dest color as input.
260 params[numParams++] = GrShaderVar(kDstColor, SkSLType::kHalf4);
261 }
262
263 auto fpCoordsIter = fFPCoordsMap.find(&fp);
264 if (fpCoordsIter == fFPCoordsMap.end()) {
265 // This FP isn't in our coords map at all, so its coords (if any) couldn't have been lifted
266 // to a varying.
267 if (fp.usesSampleCoords()) {
268 params[numParams++] = GrShaderVar(sampleCoords, SkSLType::kFloat2);
269 }
270 } else if (fpCoordsIter->second.hasCoordsParam) {
271 // This FP is in our map, and it takes an explicit coords param.
272 params[numParams++] = GrShaderVar(sampleCoords, SkSLType::kFloat2);
273 } else {
274 // Either doesn't use coords at all or sampled through a chain of passthrough/matrix
275 // samples usages. In the latter case the coords are emitted in the vertex shader as a
276 // varying, so this only has to access it. Add a float2 _coords variable that maps to the
277 // associated varying and replaces the absent 2nd argument to the fp's function.
278 GrShaderVar varying = fpCoordsIter->second.coordsVarying;
279
280 switch (varying.getType()) {
281 case SkSLType::kVoid:
282 SkASSERT(!fp.usesSampleCoordsDirectly());
283 break;
285 // Just point the local coords to the varying
286 sampleCoords = varying.getName().c_str();
287 break;
289 // Must perform the perspective divide in the frag shader based on the
290 // varying, and since we won't actually have a function parameter for local
291 // coords, add it as a local variable.
292 fFS.codeAppendf("float2 %s = %s.xy / %s.z;\n",
293 sampleCoords,
294 varying.getName().c_str(),
295 varying.getName().c_str());
296 break;
297 default:
298 SkDEBUGFAILF("Unexpected varying type for coord: %s %d\n",
299 varying.getName().c_str(),
300 (int)varying.getType());
301 break;
302 }
303 }
304
305 SkASSERT(numParams <= (int)std::size(params));
306
307 // First, emit every child's function. This needs to happen (even for children that aren't
308 // sampled), so that all of the expected uniforms are registered.
309 this->writeChildFPFunctions(fp, impl);
311 this->uniformHandler(),
312 this->shaderCaps(),
313 fp,
314 inputColor,
315 kDstColor,
316 sampleCoords);
317
318 impl.emitCode(args);
320
322 impl.functionName(),
323 SkSpan(params, numParams),
324 fFS.code().c_str());
326}
#define SkDEBUGFAILF(fmt,...)
Definition: SkAssert.h:119
virtual void emitCode(EmitArgs &)=0
const GrShaderCaps * shaderCaps() const
void emitFunction(SkSLType returnType, const char *mangledName, SkSpan< const GrShaderVar > args, const char *body)
this code().appendVAList(format
SkString getMangledFunctionName(const char *baseName)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
SkSLType getType() const
Definition: GrShaderVar.h:97
const SkString & getName() const
Definition: GrShaderVar.h:91
const char * c_str() const
Definition: SkString.h:133
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
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

Member Data Documentation

◆ fDesc

const GrProgramDesc& GrGLSLProgramBuilder::fDesc

Definition at line 138 of file GrGLSLProgramBuilder.h.

◆ fDstTextureOrigin

GrSurfaceOrigin GrGLSLProgramBuilder::fDstTextureOrigin

Definition at line 148 of file GrGLSLProgramBuilder.h.

◆ fDstTextureSamplerHandle

SamplerHandle GrGLSLProgramBuilder::fDstTextureSamplerHandle

Definition at line 147 of file GrGLSLProgramBuilder.h.

◆ fFPImpls

std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl> > GrGLSLProgramBuilder::fFPImpls

Definition at line 145 of file GrGLSLProgramBuilder.h.

◆ fFS

GrGLSLFragmentShaderBuilder GrGLSLProgramBuilder::fFS

Definition at line 136 of file GrGLSLProgramBuilder.h.

◆ fGPImpl

std::unique_ptr<GrGeometryProcessor::ProgramImpl> GrGLSLProgramBuilder::fGPImpl

Definition at line 143 of file GrGLSLProgramBuilder.h.

◆ fProgramInfo

const GrProgramInfo& GrGLSLProgramBuilder::fProgramInfo

Definition at line 139 of file GrGLSLProgramBuilder.h.

◆ fUniformHandles

GrGLSLBuiltinUniformHandles GrGLSLProgramBuilder::fUniformHandles

Definition at line 141 of file GrGLSLProgramBuilder.h.

◆ fVS

GrGLSLVertexBuilder GrGLSLProgramBuilder::fVS

Definition at line 135 of file GrGLSLProgramBuilder.h.

◆ fXPImpl

std::unique_ptr<GrXferProcessor::ProgramImpl> GrGLSLProgramBuilder::fXPImpl

Definition at line 144 of file GrGLSLProgramBuilder.h.

◆ kVarsPerBlock

const int GrGLSLProgramBuilder::kVarsPerBlock = 8
static

Definition at line 133 of file GrGLSLProgramBuilder.h.


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