36#define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
37#define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X)
40 for (
int i = 0;
i < shaderIDs.
size(); ++
i) {
66 if (persistentCache && !precompiledProgram) {
73 if (!
builder.emitAndInstallProcs()) {
76 return builder.finalize(precompiledProgram);
81GrGLProgramBuilder::GrGLProgramBuilder(
GrGLGpu* gpu,
86 , fVaryingHandler(this)
87 , fUniformHandler(this)
88 , fVertexAttributeCnt(0)
89 , fInstanceAttributeCnt(0)
91 , fInstanceStride(0) {}
97bool GrGLProgramBuilder::compileAndAttachShaders(
const std::string& glsl,
101 bool shaderWasCached,
115 *shaderIds->
append() = shaderId;
119void GrGLProgramBuilder::computeCountsAndStrides(
GrGLuint programID,
121 bool bindAttribLocations) {
124 fAttributes = std::make_unique<GrGLProgram::Attribute[]>(
125 fVertexAttributeCnt + fInstanceAttributeCnt);
126 auto addAttr = [&](
int i,
const auto&
a) {
127 fAttributes[
i].fCPUType =
a.cpuType();
128 fAttributes[
i].fGPUType =
a.gpuType();
129 fAttributes[
i].fOffset = *
a.offset();
130 fAttributes[
i].fLocation =
i;
131 if (bindAttribLocations) {
132 GL_CALL(BindAttribLocation(programID,
i,
a.name()));
150 useRTFlip &=
~SkSL::Program::Interface::kRTFlip_FragCoord;
164 const std::string shaders[],
167 if (!this->
gpu()->getContext()->
priv().getPersistentCache()) {
181 writer.writePad32(&interface,
sizeof(interface));
187 writer.writeUInt(binaryFormat);
191 auto data = writer.snapshotAsData();
207 shaders, &interface, 1, &meta);
217 if (precompiledProgram) {
222 if (0 == programID) {
226 if (this->
gpu()->glCaps().programBinarySupport() &&
227 this->
gpu()->glCaps().programParameterSupport() &&
228 this->
gpu()->getContext()->
priv().getPersistentCache() &&
229 !precompiledProgram) {
245 bool cached = fCached.
get() !=
nullptr;
246 bool usedProgramBinaries =
false;
253 if (precompiledProgram) {
256 this->addInputVars(precompiledProgram->
fInterface);
257 this->computeCountsAndStrides(programID, geomProc,
false);
258 usedProgramBinaries =
true;
264 switch (shaderType) {
272 reader.readPad32(&interface,
sizeof(interface));
273 GrGLenum binaryFormat = reader.readUInt();
276 if (!reader.isValid()) {
279 if (length <= 0 || !fGpu->glCaps().programBinaryFormatIsValid(binaryFormat)) {
289 nullptr,
nullptr,
nullptr);
291 this->addInputVars(interface);
292 this->computeCountsAndStrides(programID, geomProc,
false);
294 usedProgramBinaries = cached;
306 &reader, cached_sksl, &interface, 1)) {
308 sksl[
i] = &cached_sksl[
i];
315 reader.validate(
false);
318 if (!reader.isValid()) {
322 if (!usedProgramBinaries) {
331 if (
fFS.fForceHighPrecision) {
332 settings.fForceHighPrecision =
true;
346 this->addInputVars(interface);
385 this->computeCountsAndStrides(programID, geomProc,
true);
387 this->bindProgramResourceLocations(programID);
398 this->resolveProgramResourceLocations(programID, usedProgramBinaries);
404 if (!cached && !precompiledProgram) {
413 this->storeShaderInCache(interface, programID, glsl, isSkSL, &
settings);
415 return this->createProgram(programID);
418void GrGLProgramBuilder::bindProgramResourceLocations(
GrGLuint programID) {
419 fUniformHandler.bindUniformLocations(programID, fGpu->
glCaps());
424 GL_CALL(BindFragDataLocation(programID, 0,
425 GrGLSLFragmentShaderBuilder::DeclaredColorOutputName()));
427 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1,
428 GrGLSLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
433void GrGLProgramBuilder::resolveProgramResourceLocations(
GrGLuint programID,
bool force) {
434 fUniformHandler.getUniformLocations(programID, fGpu->
glCaps(), force);
441 fUniformHandler.fUniforms,
442 fUniformHandler.fSamplers,
446 std::move(fAttributes),
448 fInstanceAttributeCnt,
455 const SkData& cachedData) {
481 if (0 == programID) {
530 if (
caps.bindFragDataLocationSupport()) {
533 BindFragDataLocation(programID, 0,
534 GrGLSLFragmentShaderBuilder::DeclaredColorOutputName()));
538 BindFragDataLocationIndexed(programID, 0, 1,
539 GrGLSLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
#define GR_GL_LINK_STATUS
#define GL_PROGRAM_BINARY_LENGTH
#define GR_GL_PROGRAM_BINARY_RETRIEVABLE_HINT
#define GR_GL_FRAGMENT_SHADER
#define GR_GL_VERTEX_SHADER
static void cleanup_program(GrGLGpu *gpu, GrGLuint programID, const SkTDArray< GrGLuint > &shaderIDs)
static constexpr SkFourByteTag kGLSL_Tag
#define GL_CALL_RET(R, X)
static constexpr SkFourByteTag kGLPB_Tag
static void cleanup_shaders(GrGLGpu *gpu, const SkTDArray< GrGLuint > &shaderIDs)
static constexpr SkFourByteTag kSKSL_Tag
bool GrGLCheckLinkStatus(const GrGLGpu *gpu, GrGLuint programID, bool shaderWasCached, GrContextOptions::ShaderErrorHandler *errorHandler, const std::string *sksl[kGrShaderTypeCount], const std::string glsl[kGrShaderTypeCount])
GrGLuint GrGLCompileAndAttachShader(const GrGLContext &glCtx, GrGLuint programId, GrGLenum type, const std::string &glsl, bool shaderWasCached, GrThreadSafePipelineBuilder::Stats *stats, GrContextOptions::ShaderErrorHandler *errorHandler)
#define GR_GL_CALL(IFACE, X)
#define GR_GL_CALL_RET(IFACE, RET, X)
static const int kGrShaderTypeCount
#define INHERITED(method,...)
#define TRACE_EVENT0_ALWAYS(category_group, name)
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
const GrContextOptions & options() const
GrContextOptions::ShaderErrorHandler * getShaderErrorHandler() const
const GrShaderCaps * shaderCaps() const
virtual void store(const SkData &, const SkData &)
GrContextOptions::PersistentCache * getPersistentCache()
GrDirectContextPriv priv()
bool programBinarySupport() const
bool bindFragDataLocationSupport() const
const GrGLCaps & glCaps() const
GrThreadSafePipelineBuilder * pipelineBuilder() override
const GrGLInterface * glInterface() const
const GrGLContext & glContext() const
const GrCaps * caps() const override
static bool PrecompileProgram(GrDirectContext *, GrGLPrecompiledProgram *, const SkData &)
static sk_sp< GrGLProgram > CreateProgram(GrDirectContext *, const GrProgramDesc &, const GrProgramInfo &, const GrGLPrecompiledProgram *=nullptr)
static sk_sp< GrGLProgram > Make(GrGLGpu *, const GrGLSLBuiltinUniformHandles &, GrGLuint programID, const UniformInfoArray &uniforms, const UniformInfoArray &textureSamplers, std::unique_ptr< GrGeometryProcessor::ProgramImpl >, std::unique_ptr< GrXferProcessor::ProgramImpl >, std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fps, std::unique_ptr< Attribute[]>, int vertexAttributeCnt, int instanceAttributeCnt, int vertexStride, int instanceStride)
bool hasSecondaryOutput() const override
const GrProgramDesc & desc() const
std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fFPImpls
std::unique_ptr< GrGeometryProcessor::ProgramImpl > fGPImpl
const GrShaderCaps * shaderCaps() const
bool fragColorIsInOut() const
const GrGeometryProcessor & geometryProcessor() const
std::unique_ptr< GrXferProcessor::ProgramImpl > fXPImpl
GrGLSLBuiltinUniformHandles fUniformHandles
const GrProgramInfo & fProgramInfo
GrGLSLFragmentShaderBuilder fFS
void addRTFlipUniform(const char *name)
std::string fCompilerString
int numVertexAttributes() const
int numInstanceAttributes() const
size_t vertexStride() const
const AttributeSet & vertexAttributes() const
const AttributeSet & instanceAttributes() const
size_t instanceStride() const
const GrCaps * caps() const
GrDirectContext * getContext()
uint32_t keyLength() const
const uint32_t * asKey() const
static SkString Describe(const GrProgramInfo &, const GrCaps &)
void writeInt(int32_t value) override
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
const void * data() const
void push_back(const T &v)
T & emplace_back(Args &&... args)
EMSCRIPTEN_KEEPALIVE void empty()
FlPixelBufferTexturePrivate * priv
sk_sp< SkData > PackCachedShaders(SkFourByteTag shaderType, const std::string shaders[], const SkSL::Program::Interface interfaces[], int numInterfaces, const ShaderMetadata *meta)
bool UnpackCachedShaders(SkReadBuffer *reader, std::string shaders[], SkSL::Program::Interface interfaces[], int numInterfaces, ShaderMetadata *meta)
SkFourByteTag GetType(SkReadBuffer *reader)
std::string PrettyPrint(const std::string &string)
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)
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)
ShaderCacheStrategy fShaderCacheStrategy
SkSL::Program::Interface fInterface
bool mustDeclareFragmentShaderOutput() const
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)