Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
GrGLProgramBuilder Class Reference

#include <GrGLProgramBuilder.h>

Inheritance diagram for GrGLProgramBuilder:
GrGLSLProgramBuilder

Public Member Functions

const GrCapscaps () const override
 
GrGLGpugpu () const
 
- Public Member Functions inherited from GrGLSLProgramBuilder
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)
 

Static Public Member Functions

static sk_sp< GrGLProgramCreateProgram (GrDirectContext *, const GrProgramDesc &, const GrProgramInfo &, const GrGLPrecompiledProgram *=nullptr)
 
static bool PrecompileProgram (GrDirectContext *, GrGLPrecompiledProgram *, const SkData &)
 

Additional Inherited Members

- Public Types inherited from GrGLSLProgramBuilder
using UniformHandle = GrGLSLUniformHandler::UniformHandle
 
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle
 
- Public Attributes inherited from GrGLSLProgramBuilder
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 inherited from GrGLSLProgramBuilder
static const int kVarsPerBlock = 8
 
- Protected Member Functions inherited from GrGLSLProgramBuilder
 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 37 of file GrGLProgramBuilder.h.

Member Function Documentation

◆ caps()

const GrCaps * GrGLProgramBuilder::caps ( ) const
overridevirtual

Implements GrGLSLProgramBuilder.

Definition at line 93 of file GrGLProgramBuilder.cpp.

93 {
94 return fGpu->caps();
95}
const GrCaps * caps() const
Definition: GrGpu.h:73

◆ CreateProgram()

sk_sp< GrGLProgram > GrGLProgramBuilder::CreateProgram ( GrDirectContext dContext,
const GrProgramDesc desc,
const GrProgramInfo programInfo,
const GrGLPrecompiledProgram precompiledProgram = nullptr 
)
static

Generates a shader program.

The program implements what is specified in the stages given as input. After successful generation, the builder result objects are available to be used. If a GL program has already been created, the program ID and interface can be supplied to skip the shader compilation.

Returns
the created program if generation was successful.

Definition at line 51 of file GrGLProgramBuilder.cpp.

55 {
56 TRACE_EVENT0_ALWAYS("skia.shaders", "shader_compile");
57 GrAutoLocaleSetter als("C");
58
59 GrGLGpu* glGpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
60
61 // create a builder. This will be handed off to effects so they can use it to add
62 // uniforms, varyings, textures, etc
63 GrGLProgramBuilder builder(glGpu, desc, programInfo);
64
65 auto persistentCache = dContext->priv().getPersistentCache();
66 if (persistentCache && !precompiledProgram) {
68 builder.fCached = persistentCache->load(*key);
69 // the eventual end goal is to completely skip emitAndInstallProcs on a cache hit, but it's
70 // doing necessary setup in addition to generating the SkSL code. Currently we are only able
71 // to skip the SkSL->GLSL step on a cache hit.
72 }
73 if (!builder.emitAndInstallProcs()) {
74 return nullptr;
75 }
76 return builder.finalize(precompiledProgram);
77}
#define TRACE_EVENT0_ALWAYS(category_group, name)
GrContextOptions::PersistentCache * getPersistentCache()
GrDirectContextPriv priv()
const GrProgramDesc & desc() const
uint32_t keyLength() const
Definition: GrProgramDesc.h:40
const uint32_t * asKey() const
Definition: GrProgramDesc.h:35
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition: SkData.h:116

◆ gpu()

GrGLGpu * GrGLProgramBuilder::gpu ( ) const
inline

Definition at line 57 of file GrGLProgramBuilder.h.

57{ return fGpu; }

◆ PrecompileProgram()

bool GrGLProgramBuilder::PrecompileProgram ( GrDirectContext dContext,
GrGLPrecompiledProgram precompiledProgram,
const SkData cachedData 
)
static

Definition at line 453 of file GrGLProgramBuilder.cpp.

455 {
456 SkReadBuffer reader(cachedData.data(), cachedData.size());
458 if (shaderType != kSKSL_Tag) {
459 // TODO: Support GLSL, and maybe even program binaries, too?
460 return false;
461 }
462
463 GrGLGpu* glGpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
464
465 const GrGLInterface* gl = glGpu->glInterface();
466 auto errorHandler = dContext->priv().getShaderErrorHandler();
467
469 settings.fSharpenTextures = true;
471 meta.fSettings = &settings;
472
473 std::string shaders[kGrShaderTypeCount];
474 SkSL::Program::Interface interface;
475 if (!GrPersistentCacheUtils::UnpackCachedShaders(&reader, shaders, &interface, 1, &meta)) {
476 return false;
477 }
478
479 GrGLuint programID;
480 GR_GL_CALL_RET(gl, programID, CreateProgram());
481 if (0 == programID) {
482 return false;
483 }
484
485 SkTDArray<GrGLuint> shadersToDelete;
486
487 auto compileShader = [&](SkSL::ProgramKind kind, const std::string& sksl, GrGLenum type) {
488 std::string glsl;
489 SkSL::Program::Interface unusedInterface;
490 if (!skgpu::SkSLToGLSL(glGpu->caps()->shaderCaps(),
491 sksl,
492 kind,
493 settings,
494 &glsl,
495 &unusedInterface,
496 errorHandler)) {
497 return false;
498 }
499
500 if (GrGLuint shaderID = GrGLCompileAndAttachShader(glGpu->glContext(),
501 programID,
502 type,
503 glsl,
504 /*shaderWasCached=*/false,
505 glGpu->pipelineBuilder()->stats(),
506 errorHandler)) {
507 shadersToDelete.push_back(shaderID);
508 return true;
509 } else {
510 return false;
511 }
512 };
513
514 if (!compileShader(SkSL::ProgramKind::kFragment,
515 shaders[kFragment_GrShaderType],
517 !compileShader(SkSL::ProgramKind::kVertex,
518 shaders[kVertex_GrShaderType],
520 cleanup_program(glGpu, programID, shadersToDelete);
521 return false;
522 }
523
524 for (int i = 0; i < meta.fAttributeNames.size(); ++i) {
525 GR_GL_CALL(glGpu->glInterface(), BindAttribLocation(programID, i,
526 meta.fAttributeNames[i].c_str()));
527 }
528
529 const GrGLCaps& caps = glGpu->glCaps();
530 if (caps.bindFragDataLocationSupport()) {
532 GR_GL_CALL(glGpu->glInterface(),
533 BindFragDataLocation(programID, 0,
534 GrGLSLFragmentShaderBuilder::DeclaredColorOutputName()));
535
536 if (meta.fHasSecondaryColorOutput) {
537 GR_GL_CALL(glGpu->glInterface(),
538 BindFragDataLocationIndexed(programID, 0, 1,
539 GrGLSLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
540 }
541 }
542
543 GR_GL_CALL(glGpu->glInterface(), LinkProgram(programID));
544 GrGLint linked = GR_GL_INIT_ZERO;
545 GR_GL_CALL(glGpu->glInterface(), GetProgramiv(programID, GR_GL_LINK_STATUS, &linked));
546 if (!linked) {
547 cleanup_program(glGpu, programID, shadersToDelete);
548 return false;
549 }
550
551 cleanup_shaders(glGpu, shadersToDelete);
552
553 precompiledProgram->fProgramID = programID;
554 precompiledProgram->fInterface = interface;
555 return true;
556}
#define GR_GL_LINK_STATUS
Definition: GrGLDefines.h:565
#define GR_GL_FRAGMENT_SHADER
Definition: GrGLDefines.h:551
#define GR_GL_VERTEX_SHADER
Definition: GrGLDefines.h:552
static void cleanup_program(GrGLGpu *gpu, GrGLuint programID, const SkTDArray< GrGLuint > &shaderIDs)
static void cleanup_shaders(GrGLGpu *gpu, const SkTDArray< GrGLuint > &shaderIDs)
static constexpr SkFourByteTag kSKSL_Tag
GrGLuint GrGLCompileAndAttachShader(const GrGLContext &glCtx, GrGLuint programId, GrGLenum type, const std::string &glsl, bool shaderWasCached, GrThreadSafePipelineBuilder::Stats *stats, GrContextOptions::ShaderErrorHandler *errorHandler)
unsigned int GrGLuint
Definition: GrGLTypes.h:113
int GrGLint
Definition: GrGLTypes.h:108
unsigned int GrGLenum
Definition: GrGLTypes.h:102
#define GR_GL_INIT_ZERO
Definition: GrGLUtil.h:244
#define GR_GL_CALL(IFACE, X)
Definition: GrGLUtil.h:381
#define GR_GL_CALL_RET(IFACE, RET, X)
Definition: GrGLUtil.h:396
@ kFragment_GrShaderType
Definition: GrTypesPriv.h:278
@ kVertex_GrShaderType
Definition: GrTypesPriv.h:277
static const int kGrShaderTypeCount
Definition: GrTypesPriv.h:282
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkFourByteTag
Definition: SkTypes.h:166
GLenum type
GrContextOptions::ShaderErrorHandler * getShaderErrorHandler() const
const GrShaderCaps * shaderCaps() const
Definition: GrCaps.h:63
const GrGLCaps & glCaps() const
Definition: GrGLGpu.h:108
GrThreadSafePipelineBuilder * pipelineBuilder() override
Definition: GrGLGpu.cpp:574
const GrGLInterface * glInterface() const
Definition: GrGLGpu.h:103
const GrGLContext & glContext() const
Definition: GrGLGpu.h:101
const GrCaps * caps() const override
static sk_sp< GrGLProgram > CreateProgram(GrDirectContext *, const GrProgramDesc &, const GrProgramInfo &, const GrGLPrecompiledProgram *=nullptr)
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
void push_back(const T &v)
Definition: SkTDArray.h:219
int size() const
Definition: SkTArray.h:421
bool UnpackCachedShaders(SkReadBuffer *reader, std::string shaders[], SkSL::Program::Interface interfaces[], int numInterfaces, ShaderMetadata *meta)
SkFourByteTag GetType(SkReadBuffer *reader)
static bool LinkProgram(const ReactorGLES &reactor, const std::shared_ptr< PipelineGLES > &pipeline, const std::shared_ptr< const ShaderFunction > &vert_function, const std::shared_ptr< const ShaderFunction > &frag_function)
gl
Definition: malisc.py:41
bool SkSLToGLSL(const SkSL::ShaderCaps *caps, const std::string &sksl, SkSL::ProgramKind programKind, const SkSL::ProgramSettings &settings, std::string *glsl, SkSL::ProgramInterface *outInterface, ShaderErrorHandler *errorHandler)
SkSL::Program::Interface fInterface
skia_private::TArray< std::string > fAttributeNames
bool mustDeclareFragmentShaderOutput() const
Definition: SkSLUtil.h:43

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