Tracking uniform ownership

This is a prerequisite change for the upcoming sample(child, matrix)
function. By itself, this CL doesn't really change anything; it just
adds an ownership tracking feature which sample(child, matrix) depends
on.

Change-Id: I98b12e5fb062a2535af367931e7a932ea9c63a59
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281337
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2020-04-06 13:53:05 -04:00 committed by Skia Commit-Bot
parent 17f05c737e
commit 16464c3232
65 changed files with 460 additions and 356 deletions

View File

@ -96,8 +96,8 @@ class FwidthSquircleTestProcessor::Impl : public GrGLSLGeometryProcessor {
const auto& proc = args.fGP.cast<FwidthSquircleTestProcessor>(); const auto& proc = args.fGP.cast<FwidthSquircleTestProcessor>();
auto* uniforms = args.fUniformHandler; auto* uniforms = args.fUniformHandler;
fViewMatrixHandle = fViewMatrixHandle = uniforms->addUniform(nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType,
uniforms->addUniform(kVertex_GrShaderFlag, kFloat3x3_GrSLType, "viewmatrix"); "viewmatrix");
auto* varyings = args.fVaryingHandler; auto* varyings = args.fVaryingHandler;
varyings->emitAttributes(proc); varyings->emitAttributes(proc);

View File

@ -70,7 +70,7 @@ private:
args.fVaryingHandler->emitAttributes(args.fGP.cast<TessellationTestTriShader>()); args.fVaryingHandler->emitAttributes(args.fGP.cast<TessellationTestTriShader>());
const char* viewMatrix; const char* viewMatrix;
fViewMatrixUniform = args.fUniformHandler->addUniform( fViewMatrixUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix); nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
args.fVertBuilder->declareGlobal( args.fVertBuilder->declareGlobal(
GrShaderVar("P_", kFloat3_GrSLType, GrShaderVar::TypeModifier::Out)); GrShaderVar("P_", kFloat3_GrSLType, GrShaderVar::TypeModifier::Out));
args.fVertBuilder->codeAppendf(R"( args.fVertBuilder->codeAppendf(R"(
@ -184,7 +184,7 @@ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const char* viewMatrix; const char* viewMatrix;
fViewMatrixUniform = args.fUniformHandler->addUniform( fViewMatrixUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix); nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
args.fVertBuilder->declareGlobal( args.fVertBuilder->declareGlobal(
GrShaderVar("M_", kFloat3x3_GrSLType, GrShaderVar::TypeModifier::Out)); GrShaderVar("M_", kFloat3x3_GrSLType, GrShaderVar::TypeModifier::Out));
args.fVertBuilder->codeAppendf("M_ = %s;", viewMatrix); args.fVertBuilder->codeAppendf("M_ = %s;", viewMatrix);

View File

@ -298,7 +298,7 @@ void GLHighContrastFilterEffect::emitCode(EmitArgs& args) {
const SkHighContrastConfig& config = hcfe.config(); const SkHighContrastConfig& config = hcfe.config();
const char* contrast; const char* contrast;
fContrastUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, fContrastUni = args.fUniformHandler->addUniform(&hcfe, kFragment_GrShaderFlag, kHalf_GrSLType,
"contrast", &contrast); "contrast", &contrast);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;

View File

@ -566,7 +566,8 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
const GrDisplacementMapEffect& displacementMap = args.fFp.cast<GrDisplacementMapEffect>(); const GrDisplacementMapEffect& displacementMap = args.fFp.cast<GrDisplacementMapEffect>();
const GrTextureDomain& domain = displacementMap.domain(); const GrTextureDomain& domain = displacementMap.domain();
fScaleUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "Scale"); fScaleUni = args.fUniformHandler->addUniform(&displacementMap, kFragment_GrShaderFlag,
kHalf2_GrSLType, "Scale");
const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni);
const char* dColor = "dColor"; const char* dColor = "dColor";
const char* cCoords = "cCoords"; const char* cCoords = "cCoords";
@ -623,7 +624,8 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
} }
fragBuilder->codeAppend("-half2(0.5));\t\t"); fragBuilder->codeAppend("-half2(0.5));\t\t");
fGLDomain.sampleTexture(fragBuilder, fGLDomain.sampleTexture(&displacementMap,
fragBuilder,
args.fUniformHandler, args.fUniformHandler,
args.fShaderCaps, args.fShaderCaps,
domain, domain,

View File

@ -748,7 +748,7 @@ public:
* This is called by GrGLLightingEffect::emitCode() before either of the two virtual functions * This is called by GrGLLightingEffect::emitCode() before either of the two virtual functions
* below. It adds a half3 uniform visible in the FS that represents the constant light color. * below. It adds a half3 uniform visible in the FS that represents the constant light color.
*/ */
void emitLightColorUniform(GrGLSLUniformHandler*); void emitLightColorUniform(const GrFragmentProcessor*, GrGLSLUniformHandler*);
/** /**
* These two functions are called from GrGLLightingEffect's emitCode() function. * These two functions are called from GrGLLightingEffect's emitCode() function.
@ -758,10 +758,12 @@ public:
* the FS. The default of emitLightColor appends the name of the constant light color uniform * the FS. The default of emitLightColor appends the name of the constant light color uniform
* and so this function only needs to be overridden if the light color varies spatially. * and so this function only needs to be overridden if the light color varies spatially.
*/ */
virtual void emitSurfaceToLight(GrGLSLUniformHandler*, virtual void emitSurfaceToLight(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, GrGLSLFPFragmentBuilder*,
const char* z) = 0; const char* z) = 0;
virtual void emitLightColor(GrGLSLUniformHandler*, virtual void emitLightColor(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, GrGLSLFPFragmentBuilder*,
const char *surfaceToLight); const char *surfaceToLight);
@ -788,7 +790,8 @@ class GrGLDistantLight : public GrGLLight {
public: public:
~GrGLDistantLight() override {} ~GrGLDistantLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override; void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, const char* z) override; void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, const char* z) override;
private: private:
typedef GrGLLight INHERITED; typedef GrGLLight INHERITED;
@ -801,7 +804,8 @@ class GrGLPointLight : public GrGLLight {
public: public:
~GrGLPointLight() override {} ~GrGLPointLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override; void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, const char* z) override; void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, const char* z) override;
private: private:
typedef GrGLLight INHERITED; typedef GrGLLight INHERITED;
@ -814,8 +818,10 @@ class GrGLSpotLight : public GrGLLight {
public: public:
~GrGLSpotLight() override {} ~GrGLSpotLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override; void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, const char* z) override; void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
void emitLightColor(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, const char* z) override;
void emitLightColor(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, GrGLSLFPFragmentBuilder*,
const char *surfaceToLight) override; const char *surfaceToLight) override;
@ -1550,7 +1556,8 @@ protected:
*/ */
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
virtual void emitLightFunc(GrGLSLUniformHandler*, virtual void emitLightFunc(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, GrGLSLFPFragmentBuilder*,
SkString* funcName) = 0; SkString* funcName) = 0;
@ -1567,7 +1574,8 @@ private:
class GrGLDiffuseLightingEffect : public GrGLLightingEffect { class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
public: public:
void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, SkString* funcName) override; void emitLightFunc(const GrFragmentProcessor*, GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*,
SkString* funcName) override;
protected: protected:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
@ -1582,7 +1590,8 @@ private:
class GrGLSpecularLightingEffect : public GrGLLightingEffect { class GrGLSpecularLightingEffect : public GrGLLightingEffect {
public: public:
void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, SkString* funcName) override; void emitLightFunc(const GrFragmentProcessor*, GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*,
SkString* funcName) override;
protected: protected:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
@ -1736,14 +1745,16 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
} }
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, fImageIncrementUni = uniformHandler->addUniform(&le,
kFragment_GrShaderFlag,
kHalf2_GrSLType, "ImageIncrement"); kHalf2_GrSLType, "ImageIncrement");
fSurfaceScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, fSurfaceScaleUni = uniformHandler->addUniform(&le,
kFragment_GrShaderFlag,
kHalf_GrSLType, "SurfaceScale"); kHalf_GrSLType, "SurfaceScale");
fLight->emitLightColorUniform(uniformHandler); fLight->emitLightColorUniform(&le, uniformHandler);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString lightFunc; SkString lightFunc;
this->emitLightFunc(uniformHandler, fragBuilder, &lightFunc); this->emitLightFunc(&le, uniformHandler, fragBuilder, &lightFunc);
const GrShaderVar gSobelArgs[] = { const GrShaderVar gSobelArgs[] = {
GrShaderVar("a", kHalf_GrSLType), GrShaderVar("a", kHalf_GrSLType),
GrShaderVar("b", kHalf_GrSLType), GrShaderVar("b", kHalf_GrSLType),
@ -1804,7 +1815,8 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
SkString temp; SkString temp;
temp.appendf("temp%d", index); temp.appendf("temp%d", index);
fragBuilder->codeAppendf("half4 %s;", temp.c_str()); fragBuilder->codeAppendf("half4 %s;", temp.c_str());
fDomain.sampleTexture(fragBuilder, fDomain.sampleTexture(&le,
fragBuilder,
args.fUniformHandler, args.fUniformHandler,
args.fShaderCaps, args.fShaderCaps,
le.domain(), le.domain(),
@ -1818,11 +1830,11 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppend("\t\thalf3 surfaceToLight = "); fragBuilder->codeAppend("\t\thalf3 surfaceToLight = ");
SkString arg; SkString arg;
arg.appendf("%s * m[4]", surfScale); arg.appendf("%s * m[4]", surfScale);
fLight->emitSurfaceToLight(uniformHandler, fragBuilder, arg.c_str()); fLight->emitSurfaceToLight(&le, uniformHandler, fragBuilder, arg.c_str());
fragBuilder->codeAppend(";\n"); fragBuilder->codeAppend(";\n");
fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
args.fOutputColor, lightFunc.c_str(), normalName.c_str(), surfScale); args.fOutputColor, lightFunc.c_str(), normalName.c_str(), surfScale);
fLight->emitLightColor(uniformHandler, fragBuilder, "surfaceToLight"); fLight->emitLightColor(&le, uniformHandler, fragBuilder, "surfaceToLight");
fragBuilder->codeAppend(");\n"); fragBuilder->codeAppend(");\n");
fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor); fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
} }
@ -1857,11 +1869,12 @@ void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandler, void GrGLDiffuseLightingEffect::emitLightFunc(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
SkString* funcName) { SkString* funcName) {
const char* kd; const char* kd;
fKDUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "KD", &kd); fKDUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType, "KD", &kd);
const GrShaderVar gLightArgs[] = { const GrShaderVar gLightArgs[] = {
GrShaderVar("normal", kHalf3_GrSLType), GrShaderVar("normal", kHalf3_GrSLType),
@ -1948,14 +1961,16 @@ std::unique_ptr<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProc
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandler, void GrGLSpecularLightingEffect::emitLightFunc(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
SkString* funcName) { SkString* funcName) {
const char* ks; const char* ks;
const char* shininess; const char* shininess;
fKSUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "KS", &ks); fKSUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType, "KS", &ks);
fShininessUni = uniformHandler->addUniform(kFragment_GrShaderFlag, fShininessUni = uniformHandler->addUniform(owner,
kFragment_GrShaderFlag,
kHalf_GrSLType, kHalf_GrSLType,
"Shininess", "Shininess",
&shininess); &shininess);
@ -1988,11 +2003,14 @@ void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void GrGLLight::emitLightColorUniform(GrGLSLUniformHandler* uniformHandler) { void GrGLLight::emitLightColorUniform(const GrFragmentProcessor* owner,
fColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, "LightColor"); GrGLSLUniformHandler* uniformHandler) {
fColorUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightColor");
} }
void GrGLLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, void GrGLLight::emitLightColor(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
const char *surfaceToLight) { const char *surfaceToLight) {
fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni())); fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni()));
@ -2014,11 +2032,12 @@ void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); setUniformNormal3(pdman, fDirectionUni, distantLight->direction());
} }
void GrGLDistantLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, void GrGLDistantLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
const char* z) { const char* z) {
const char* dir; const char* dir;
fDirectionUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, fDirectionUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightDirection", &dir); "LightDirection", &dir);
fragBuilder->codeAppend(dir); fragBuilder->codeAppend(dir);
} }
@ -2033,11 +2052,12 @@ void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformPoint3(pdman, fLocationUni, pointLight->location()); setUniformPoint3(pdman, fLocationUni, pointLight->location());
} }
void GrGLPointLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, void GrGLPointLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
const char* z) { const char* z) {
const char* loc; const char* loc;
fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, fLocationUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightLocation", &loc); "LightLocation", &loc);
fragBuilder->codeAppendf("normalize(%s - half3(sk_FragCoord.xy, %s))", fragBuilder->codeAppendf("normalize(%s - half3(sk_FragCoord.xy, %s))",
loc, z); loc, z);
@ -2058,18 +2078,20 @@ void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformNormal3(pdman, fSUni, spotLight->s()); setUniformNormal3(pdman, fSUni, spotLight->s());
} }
void GrGLSpotLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, void GrGLSpotLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
const char* z) { const char* z) {
const char* location; const char* location;
fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, fLocationUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightLocation", &location); "LightLocation", &location);
fragBuilder->codeAppendf("normalize(%s - half3(sk_FragCoord.xy, %s))", fragBuilder->codeAppendf("normalize(%s - half3(sk_FragCoord.xy, %s))",
location, z); location, z);
} }
void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, void GrGLSpotLight::emitLightColor(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLFPFragmentBuilder* fragBuilder,
const char *surfaceToLight) { const char *surfaceToLight) {
@ -2080,15 +2102,17 @@ void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler,
const char* cosOuter; const char* cosOuter;
const char* coneScale; const char* coneScale;
const char* s; const char* s;
fExponentUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, fExponentUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType,
"Exponent", &exponent); "Exponent", &exponent);
fCosInnerConeAngleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, fCosInnerConeAngleUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag,
"CosInnerConeAngle", &cosInner); kHalf_GrSLType, "CosInnerConeAngle",
fCosOuterConeAngleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, &cosInner);
"CosOuterConeAngle", &cosOuter); fCosOuterConeAngleUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag,
fConeScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, kHalf_GrSLType, "CosOuterConeAngle",
&cosOuter);
fConeScaleUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType,
"ConeScale", &coneScale); "ConeScale", &coneScale);
fSUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, "S", &s); fSUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType, "S", &s);
const GrShaderVar gLightColorArgs[] = { const GrShaderVar gLightColorArgs[] = {
GrShaderVar("surfaceToLight", kHalf3_GrSLType) GrShaderVar("surfaceToLight", kHalf3_GrSLType)

View File

@ -285,9 +285,10 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) {
const GrMorphologyEffect& me = args.fFp.cast<GrMorphologyEffect>(); const GrMorphologyEffect& me = args.fFp.cast<GrMorphologyEffect>();
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fPixelSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "PixelSize"); fPixelSizeUni = uniformHandler->addUniform(&me, kFragment_GrShaderFlag, kHalf_GrSLType,
"PixelSize");
const char* pixelSizeInc = uniformHandler->getUniformCStr(fPixelSizeUni); const char* pixelSizeInc = uniformHandler->getUniformCStr(fPixelSizeUni);
fRangeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloat2_GrSLType, "Range"); fRangeUni = uniformHandler->addUniform(&me, kFragment_GrShaderFlag, kFloat2_GrSLType, "Range");
const char* range = uniformHandler->getUniformCStr(fRangeUni); const char* range = uniformHandler->getUniformCStr(fRangeUni);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;

View File

@ -83,7 +83,8 @@ public:
vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name()); vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
} else { } else {
const char* colorUniformName; const char* colorUniformName;
fColorUniform = uniformHandler->addUniform(kVertex_GrShaderFlag, fColorUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kHalf4_GrSLType, kHalf4_GrSLType,
"Color", "Color",
&colorUniformName); &colorUniformName);
@ -128,7 +129,8 @@ public:
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage); fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
} else { } else {
const char* fragCoverage; const char* fragCoverage;
fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, fCoverageUniform = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf_GrSLType, kHalf_GrSLType,
"Coverage", "Coverage",
&fragCoverage); &fragCoverage);

View File

@ -42,7 +42,8 @@ public:
// Setup uniform color // Setup uniform color
const char* stagedLocalVarName; const char* stagedLocalVarName;
fColorUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, fColorUniform = args.fUniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf4_GrSLType, kHalf4_GrSLType,
"Color", "Color",
&stagedLocalVarName); &stagedLocalVarName);
@ -81,7 +82,8 @@ public:
uni.fType = kFloat3x3_GrSLType; uni.fType = kFloat3x3_GrSLType;
} }
uni.fHandle = uniformHandler uni.fHandle = uniformHandler
->addUniform(kFragment_GrShaderFlag, ->addUniform(nullptr,
kFragment_GrShaderFlag,
uni.fType, uni.fType,
strUniName.c_str(), strUniName.c_str(),
&name) &name)

View File

@ -76,16 +76,18 @@ public:
if (proc.fMustCheckBounds) { if (proc.fMustCheckBounds) {
const char* pathIBounds; const char* pathIBounds;
fPathIBoundsUniform = uniHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, fPathIBoundsUniform = uniHandler->addUniform(&proc, kFragment_GrShaderFlag,
"path_ibounds", &pathIBounds); kFloat4_GrSLType, "path_ibounds",
&pathIBounds);
f->codeAppendf("if (all(greaterThan(float4(sk_FragCoord.xy, %s.zw), " f->codeAppendf("if (all(greaterThan(float4(sk_FragCoord.xy, %s.zw), "
"float4(%s.xy, sk_FragCoord.xy)))) {", "float4(%s.xy, sk_FragCoord.xy)))) {",
pathIBounds, pathIBounds); pathIBounds, pathIBounds);
} }
const char* atlasTransform; const char* atlasTransform;
fAtlasTransformUniform = uniHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, fAtlasTransformUniform = uniHandler->addUniform(&proc, kFragment_GrShaderFlag,
"atlas_transform", &atlasTransform); kFloat4_GrSLType, "atlas_transform",
&atlasTransform);
f->codeAppendf("float2 texcoord = sk_FragCoord.xy * %s.xy + %s.zw;", f->codeAppendf("float2 texcoord = sk_FragCoord.xy * %s.xy + %s.zw;",
atlasTransform, atlasTransform); atlasTransform, atlasTransform);

View File

@ -158,7 +158,7 @@ void GrCCPathProcessor::Impl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const char* atlasAdjust; const char* atlasAdjust;
fAtlasAdjustUniform = uniHandler->addUniform( fAtlasAdjustUniform = uniHandler->addUniform(
kVertex_GrShaderFlag, kFloat2_GrSLType, "atlas_adjust", &atlasAdjust); nullptr, kVertex_GrShaderFlag, kFloat2_GrSLType, "atlas_adjust", &atlasAdjust);
varyingHandler->emitAttributes(proc); varyingHandler->emitAttributes(proc);

View File

@ -22,8 +22,8 @@ GrDawnProgramDataManager::GrDawnProgramDataManager(const UniformInfoArray& unifo
for (const auto& uniformInfo : uniforms.items()) { for (const auto& uniformInfo : uniforms.items()) {
Uniform& uniform = fUniforms[i]; Uniform& uniform = fUniforms[i];
SkDEBUGCODE( SkDEBUGCODE(
uniform.fArrayCount = uniformInfo.fVar.getArrayCount(); uniform.fArrayCount = uniformInfo.fVariable.getArrayCount();
uniform.fType = uniformInfo.fVar.getType(); uniform.fType = uniformInfo.fVariable.getType();
) )
uniform.fOffset = uniformInfo.fUBOOffset; uniform.fOffset = uniformInfo.fUBOOffset;
++i; ++i;

View File

@ -17,11 +17,11 @@ GrDawnUniformHandler::GrDawnUniformHandler(GrGLSLProgramBuilder* program)
} }
const GrShaderVar& GrDawnUniformHandler::getUniformVariable(UniformHandle u) const { const GrShaderVar& GrDawnUniformHandler::getUniformVariable(UniformHandle u) const {
return fUniforms.item(u.toIndex()).fVar; return fUniforms.item(u.toIndex()).fVariable;
} }
const char* GrDawnUniformHandler::getUniformCStr(UniformHandle u) const { const char* GrDawnUniformHandler::getUniformCStr(UniformHandle u) const {
return fUniforms.item(u.toIndex()).fVar.getName().c_str(); return fUniforms.item(u.toIndex()).fVariable.getName().c_str();
} }
// FIXME: this code was ripped from GrVkUniformHandler; should be refactored. // FIXME: this code was ripped from GrVkUniformHandler; should be refactored.
@ -200,6 +200,7 @@ uint32_t get_ubo_offset(uint32_t* currentOffset, GrSLType type, int arrayCount)
} }
GrGLSLUniformHandler::UniformHandle GrDawnUniformHandler::internalAddUniformArray( GrGLSLUniformHandler::UniformHandle GrDawnUniformHandler::internalAddUniformArray(
const GrFragmentProcessor* owner,
uint32_t visibility, uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
@ -217,14 +218,17 @@ GrGLSLUniformHandler::UniformHandle GrDawnUniformHandler::internalAddUniformArra
SkString layoutQualifier; SkString layoutQualifier;
layoutQualifier.appendf("offset = %d", offset); layoutQualifier.appendf("offset = %d", offset);
UniformInfo& info = fUniforms.push_back(GrDawnUniformHandler::UniformInfo{ UniformInfo& info = fUniforms.push_back(DawnUniformInfo{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount, {
std::move(layoutQualifier), SkString()}, GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
offset, static_cast<int>(visibility) std::move(layoutQualifier), SkString()},
visibility, owner, SkString(name)
},
offset
}); });
if (outName) { if (outName) {
*outName = info.fVar.c_str(); *outName = info.fVariable.c_str();
} }
return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
} }
@ -240,11 +244,14 @@ GrGLSLUniformHandler::SamplerHandle GrDawnUniformHandler::addSampler(const GrBac
fProgramBuilder->nameVariable(&mangleName, 's', name, true); fProgramBuilder->nameVariable(&mangleName, 's', name, true);
SkString layoutQualifier; SkString layoutQualifier;
layoutQualifier.appendf("set = 1, binding = %d", binding); layoutQualifier.appendf("set = 1, binding = %d", binding);
UniformInfo& info = fSamplers.push_back(GrDawnUniformHandler::UniformInfo{ DawnUniformInfo& info = fSamplers.push_back(DawnUniformInfo{
GrShaderVar{std::move(mangleName), kSampler_GrSLType, {
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray, GrShaderVar{std::move(mangleName), kSampler_GrSLType,
std::move(layoutQualifier), SkString()}, GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
0, kFragment_GrShaderFlag std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag, nullptr, SkString(name)
},
0
}); });
fSamplerSwizzles.push_back(swizzle); fSamplerSwizzles.push_back(swizzle);
@ -254,16 +261,19 @@ GrGLSLUniformHandler::SamplerHandle GrDawnUniformHandler::addSampler(const GrBac
fProgramBuilder->nameVariable(&mangleTexName, 't', name, true); fProgramBuilder->nameVariable(&mangleTexName, 't', name, true);
SkString texLayoutQualifier; SkString texLayoutQualifier;
texLayoutQualifier.appendf("set = 1, binding = %d", binding + 1); texLayoutQualifier.appendf("set = 1, binding = %d", binding + 1);
UniformInfo& texInfo = fTextures.push_back(GrDawnUniformHandler::UniformInfo{ UniformInfo& texInfo = fTextures.push_back(DawnUniformInfo{
GrShaderVar{std::move(mangleTexName), kTexture2D_GrSLType, {
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray, GrShaderVar{std::move(mangleTexName), kTexture2D_GrSLType,
std::move(texLayoutQualifier), SkString()}, GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
0, kFragment_GrShaderFlag std::move(texLayoutQualifier), SkString()},
kFragment_GrShaderFlag, nullptr, SkString(name)
},
0
}); });
SkString reference; SkString reference;
reference.printf("makeSampler2D(%s, %s)", texInfo.fVar.getName().c_str(), reference.printf("makeSampler2D(%s, %s)", texInfo.fVariable.getName().c_str(),
info.fVar.getName().c_str()); info.fVariable.getName().c_str());
fSamplerReferences.emplace_back(std::move(reference)); fSamplerReferences.emplace_back(std::move(reference));
return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
} }
@ -279,11 +289,11 @@ GrSwizzle GrDawnUniformHandler::samplerSwizzle(GrGLSLUniformHandler::SamplerHand
void GrDawnUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const { void GrDawnUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
auto textures = fTextures.items().begin(); auto textures = fTextures.items().begin();
for (const UniformInfo& sampler : fSamplers.items()) { for (const DawnUniformInfo& sampler : fSamplers.items()) {
if (sampler.fVisibility & visibility) { if (sampler.fVisibility & visibility) {
sampler.fVar.appendDecl(fProgramBuilder->shaderCaps(), out); sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
out->append(";\n"); out->append(";\n");
(*textures).fVar.appendDecl(fProgramBuilder->shaderCaps(), out); (*textures).fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
out->append(";\n"); out->append(";\n");
} }
++textures; ++textures;
@ -291,7 +301,7 @@ void GrDawnUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString
SkString uniformsString; SkString uniformsString;
for (const UniformInfo& uniform : fUniforms.items()) { for (const UniformInfo& uniform : fUniforms.items()) {
if (uniform.fVisibility & visibility) { if (uniform.fVisibility & visibility) {
uniform.fVar.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString); uniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);
uniformsString.append(";\n"); uniformsString.append(";\n");
} }
} }

View File

@ -20,12 +20,10 @@ public:
const GrShaderVar& getUniformVariable(UniformHandle u) const override; const GrShaderVar& getUniformVariable(UniformHandle u) const override;
const char* getUniformCStr(UniformHandle u) const override; const char* getUniformCStr(UniformHandle u) const override;
struct UniformInfo { struct DawnUniformInfo : public UniformInfo {
GrShaderVar fVar; int fUBOOffset;
int fUBOOffset;
int fVisibility;
}; };
typedef GrTAllocator<UniformInfo> UniformInfoArray; typedef GrTAllocator<DawnUniformInfo> UniformInfoArray;
enum { enum {
kUniformBinding = 0, kUniformBinding = 0,
}; };
@ -39,18 +37,20 @@ private:
const char* samplerVariable(SamplerHandle handle) const override; const char* samplerVariable(SamplerHandle handle) const override;
GrSwizzle samplerSwizzle(SamplerHandle handle) const override; GrSwizzle samplerSwizzle(SamplerHandle handle) const override;
void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; void appendUniformDecls(GrShaderFlags visibility, SkString*) const override;
UniformHandle internalAddUniformArray(uint32_t visibility, UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
bool mangleName, bool mangleName,
int arrayCount, int arrayCount,
const char** outName) override; const char** outName) override;
UniformInfoArray fUniforms;
UniformInfoArray fSamplers; UniformInfoArray fUniforms;
UniformInfoArray fTextures; UniformInfoArray fSamplers;
SkTArray<GrSwizzle> fSamplerSwizzles; UniformInfoArray fTextures;
SkTArray<SkString> fSamplerReferences; SkTArray<GrSwizzle> fSamplerSwizzles;
SkTArray<SkString> fSamplerReferences;
uint32_t fCurrentUBOOffset = 0; uint32_t fCurrentUBOOffset = 0;
uint32_t fRTHeightOffset = 0; uint32_t fRTHeightOffset = 0;

View File

@ -192,7 +192,8 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// TODO should we really be doing this? // TODO should we really be doing this?
if (gp.coverageScale() != 0xff) { if (gp.coverageScale() != 0xff) {
const char* coverageScale; const char* coverageScale;
fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, fCoverageScaleUniform = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kFloat_GrSLType, kFloat_GrSLType,
"Coverage", "Coverage",
&coverageScale); &coverageScale);
@ -393,7 +394,8 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
if (0xff != gp.coverageScale()) { if (0xff != gp.coverageScale()) {
const char* coverageScale; const char* coverageScale;
fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, fCoverageScaleUniform = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf_GrSLType, kHalf_GrSLType,
"Coverage", "Coverage",
&coverageScale); &coverageScale);

View File

@ -33,8 +33,8 @@ public:
varyingHandler->emitAttributes(btgp); varyingHandler->emitAttributes(btgp);
const char* atlasDimensionsInvName; const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform( fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr, kVertex_GrShaderFlag,
kVertex_GrShaderFlag, kFloat2_GrSLType, "AtlasSizeInv", &atlasDimensionsInvName); kFloat2_GrSLType, "AtlasSizeInv", &atlasDimensionsInvName);
GrGLSLVarying uv(kFloat2_GrSLType); GrGLSLVarying uv(kFloat2_GrSLType);
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType; GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;

View File

@ -41,7 +41,8 @@ void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
const char *edgeArrayName; const char *edgeArrayName;
fEdgeUniform = args.fUniformHandler->addUniformArray(kFragment_GrShaderFlag, fEdgeUniform = args.fUniformHandler->addUniformArray(&cpe,
kFragment_GrShaderFlag,
kHalf3_GrSLType, kHalf3_GrSLType,
"edges", "edges",
cpe.getEdgeCount(), cpe.getEdgeCount(),

View File

@ -38,7 +38,8 @@ public:
varyingHandler->emitAttributes(dfTexEffect); varyingHandler->emitAttributes(dfTexEffect);
const char* atlasDimensionsInvName; const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag, fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat2_GrSLType, kFloat2_GrSLType,
"AtlasDimensionsInv", "AtlasDimensionsInv",
&atlasDimensionsInvName); &atlasDimensionsInvName);
@ -46,8 +47,9 @@ public:
// adjust based on gamma // adjust based on gamma
const char* distanceAdjustUniName = nullptr; const char* distanceAdjustUniName = nullptr;
// width, height, 1/(3*width) // width, height, 1/(3*width)
fDistanceAdjustUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, fDistanceAdjustUni = uniformHandler->addUniform(nullptr, kFragment_GrShaderFlag,
"DistanceAdjust", &distanceAdjustUniName); kHalf_GrSLType, "DistanceAdjust",
&distanceAdjustUniName);
#endif #endif
// Setup pass through color // Setup pass through color
@ -334,7 +336,8 @@ public:
varyingHandler->emitAttributes(dfPathEffect); varyingHandler->emitAttributes(dfPathEffect);
const char* atlasDimensionsInvName; const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag, fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat2_GrSLType, kFloat2_GrSLType,
"AtlasDimensionsInv", "AtlasDimensionsInv",
&atlasDimensionsInvName); &atlasDimensionsInvName);
@ -618,7 +621,8 @@ public:
varyingHandler->emitAttributes(dfTexEffect); varyingHandler->emitAttributes(dfTexEffect);
const char* atlasDimensionsInvName; const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag, fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat2_GrSLType, kFloat2_GrSLType,
"AtlasDimensionsInv", "AtlasDimensionsInv",
&atlasDimensionsInvName); &atlasDimensionsInvName);
@ -722,8 +726,9 @@ public:
// adjust width based on gamma // adjust width based on gamma
const char* distanceAdjustUniName = nullptr; const char* distanceAdjustUniName = nullptr;
fDistanceAdjustUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, fDistanceAdjustUni = uniformHandler->addUniform(nullptr, kFragment_GrShaderFlag,
"DistanceAdjust", &distanceAdjustUniName); kHalf3_GrSLType, "DistanceAdjust",
&distanceAdjustUniName);
fragBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); fragBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName);
// To be strictly correct, we should compute the anti-aliasing factor separately // To be strictly correct, we should compute the anti-aliasing factor separately

View File

@ -40,10 +40,10 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
args.fFp.cast<GrGaussianConvolutionFragmentProcessor>(); args.fFp.cast<GrGaussianConvolutionFragmentProcessor>();
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fImageIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
"ImageIncrement"); "ImageIncrement");
if (ce.useBounds()) { if (ce.useBounds()) {
fBoundsUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fBoundsUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
"Bounds"); "Bounds");
} }
@ -52,7 +52,7 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
int arrayCount = (width + 3) / 4; int arrayCount = (width + 3) / 4;
SkASSERT(4 * arrayCount >= width); SkASSERT(4 * arrayCount >= width);
fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, kHalf4_GrSLType, fKernelUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, kHalf4_GrSLType,
"Kernel", arrayCount); "Kernel", arrayCount);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;

View File

@ -46,15 +46,15 @@ void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
SkASSERT(4 * arrayCount >= kWidth * kHeight); SkASSERT(4 * arrayCount >= kWidth * kHeight);
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fImageIncrementUni = uniformHandler->addUniform(&mce, kFragment_GrShaderFlag, kHalf2_GrSLType,
"ImageIncrement"); "ImageIncrement");
fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, kHalf4_GrSLType, fKernelUni = uniformHandler->addUniformArray(&mce, kFragment_GrShaderFlag, kHalf4_GrSLType,
"Kernel", "Kernel",
arrayCount); arrayCount);
fKernelOffsetUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fKernelOffsetUni = uniformHandler->addUniform(&mce, kFragment_GrShaderFlag, kHalf2_GrSLType,
"KernelOffset"); "KernelOffset");
fGainUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "Gain"); fGainUni = uniformHandler->addUniform(&mce, kFragment_GrShaderFlag, kHalf_GrSLType, "Gain");
fBiasUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "Bias"); fBiasUni = uniformHandler->addUniform(&mce, kFragment_GrShaderFlag, kHalf_GrSLType, "Bias");
const char* kernelOffset = uniformHandler->getUniformCStr(fKernelOffsetUni); const char* kernelOffset = uniformHandler->getUniformCStr(fKernelOffsetUni);
const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
@ -78,7 +78,8 @@ void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
kVecSuffix[offset & 0x3]); kVecSuffix[offset & 0x3]);
SkString coord; SkString coord;
coord.printf("coord + half2(%d, %d) * %s", x, y, imgInc); coord.printf("coord + half2(%d, %d) * %s", x, y, imgInc);
fDomain.sampleTexture(fragBuilder, fDomain.sampleTexture(&mce,
fragBuilder,
uniformHandler, uniformHandler,
args.fShaderCaps, args.fShaderCaps,
domain, domain,
@ -98,7 +99,8 @@ void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);", fragBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);",
args.fOutputColor, args.fOutputColor, args.fOutputColor); args.fOutputColor, args.fOutputColor, args.fOutputColor);
} else { } else {
fDomain.sampleTexture(fragBuilder, fDomain.sampleTexture(&mce,
fragBuilder,
uniformHandler, uniformHandler,
args.fShaderCaps, args.fShaderCaps,
domain, domain,

View File

@ -607,8 +607,8 @@ public:
private: private:
void emitOutputsForBlendState(const EmitArgs& args) override { void emitOutputsForBlendState(const EmitArgs& args) override {
const char* alpha; const char* alpha;
fAlphaUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, fAlphaUniform = args.fUniformHandler->addUniform(nullptr, kFragment_GrShaderFlag,
"alpha", &alpha); kHalf_GrSLType, "alpha", &alpha);
GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
// We want to force our primary output to be alpha * Coverage, where alpha is the alpha // We want to force our primary output to be alpha * Coverage, where alpha is the alpha
// value of the src color. We know that there are no color stages (or we wouldn't have // value of the src color. We know that there are no color stages (or we wouldn't have

View File

@ -157,11 +157,12 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
// edges correspond to components x, y, z, and w, respectively. When a side of the rrect has // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has
// only rectangular corners, that side's value corresponds to the rect edge's value outset by // only rectangular corners, that side's value corresponds to the rect edge's value outset by
// half a pixel. // half a pixel.
fInnerRectUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, fInnerRectUniform = uniformHandler->addUniform(&crre, kFragment_GrShaderFlag, kFloat4_GrSLType,
"innerRect", &rectName); "innerRect", &rectName);
// x is (r + .5) and y is 1/(r + .5) // x is (r + .5) and y is 1/(r + .5)
fRadiusPlusHalfUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fRadiusPlusHalfUniform = uniformHandler->addUniform(&crre, kFragment_GrShaderFlag,
"radiusPlusHalf", &radiusPlusHalfName); kHalf2_GrSLType, "radiusPlusHalf",
&radiusPlusHalfName);
// If we're on a device where float != fp32 then the length calculation could overflow. // If we're on a device where float != fp32 then the length calculation could overflow.
SkString clampedCircleDistance; SkString clampedCircleDistance;
@ -503,7 +504,7 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
const char *rectName; const char *rectName;
// The inner rect is the rrect bounds inset by the x/y radii // The inner rect is the rrect bounds inset by the x/y radii
fInnerRectUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, fInnerRectUniform = uniformHandler->addUniform(&erre, kFragment_GrShaderFlag, kFloat4_GrSLType,
"innerRect", &rectName); "innerRect", &rectName);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
@ -527,15 +528,16 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
// radii uniform values are already in this normalized space. // radii uniform values are already in this normalized space.
const char* scaleName = nullptr; const char* scaleName = nullptr;
if (!args.fShaderCaps->floatIs32Bits()) { if (!args.fShaderCaps->floatIs32Bits()) {
fScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "scale", fScaleUniform = uniformHandler->addUniform(&erre, kFragment_GrShaderFlag, kHalf2_GrSLType,
&scaleName); "scale", &scaleName);
} }
// The uniforms with the inv squared radii are highp to prevent underflow. // The uniforms with the inv squared radii are highp to prevent underflow.
switch (erre.getRRect().getType()) { switch (erre.getRRect().getType()) {
case SkRRect::kSimple_Type: { case SkRRect::kSimple_Type: {
const char *invRadiiXYSqdName; const char *invRadiiXYSqdName;
fInvRadiiSqdUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, fInvRadiiSqdUniform = uniformHandler->addUniform(&erre,
kFragment_GrShaderFlag,
kFloat2_GrSLType, kFloat2_GrSLType,
"invRadiiXY", "invRadiiXY",
&invRadiiXYSqdName); &invRadiiXYSqdName);
@ -549,7 +551,8 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
} }
case SkRRect::kNinePatch_Type: { case SkRRect::kNinePatch_Type: {
const char *invRadiiLTRBSqdName; const char *invRadiiLTRBSqdName;
fInvRadiiSqdUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, fInvRadiiSqdUniform = uniformHandler->addUniform(&erre,
kFragment_GrShaderFlag,
kFloat4_GrSLType, kFloat4_GrSLType,
"invRadiiLTRB", "invRadiiLTRB",
&invRadiiLTRBSqdName); &invRadiiLTRBSqdName);

View File

@ -79,7 +79,8 @@ public:
const GrSkSLFP& fp = args.fFp.cast<GrSkSLFP>(); const GrSkSLFP& fp = args.fFp.cast<GrSkSLFP>();
for (const auto& v : fp.fEffect->inputs()) { for (const auto& v : fp.fEffect->inputs()) {
if (v.fQualifier == SkRuntimeEffect::Variable::Qualifier::kUniform) { if (v.fQualifier == SkRuntimeEffect::Variable::Qualifier::kUniform) {
auto handle = args.fUniformHandler->addUniformArray(kFragment_GrShaderFlag, auto handle = args.fUniformHandler->addUniformArray(&fp,
kFragment_GrShaderFlag,
v.fGPUType, v.fGPUType,
v.fName.c_str(), v.fName.c_str(),
v.isArray() ? v.fCount : 0); v.isArray() ? v.fCount : 0);

View File

@ -85,7 +85,8 @@ static void append_wrap(GrGLSLShaderBuilder* builder, GrTextureDomain::Mode mode
} }
} }
void GrTextureDomain::GLDomain::sampleProcessor(const GrTextureDomain& textureDomain, void GrTextureDomain::GLDomain::sampleProcessor(const GrFragmentProcessor* owner,
const GrTextureDomain& textureDomain,
const char* inColor, const char* inColor,
const char* outColor, const char* outColor,
const SkString& inCoords, const SkString& inCoords,
@ -95,11 +96,12 @@ void GrTextureDomain::GLDomain::sampleProcessor(const GrTextureDomain& textureDo
auto appendProcessorSample = [parent, &args, childIndex, inColor](const char* coord) { auto appendProcessorSample = [parent, &args, childIndex, inColor](const char* coord) {
return parent->invokeChild(childIndex, inColor, args, coord); return parent->invokeChild(childIndex, inColor, args, coord);
}; };
this->sample(args.fFragBuilder, args.fUniformHandler, textureDomain, outColor, inCoords, this->sample(owner, args.fFragBuilder, args.fUniformHandler, textureDomain, outColor, inCoords,
appendProcessorSample); appendProcessorSample);
} }
void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder, void GrTextureDomain::GLDomain::sampleTexture(const GrFragmentProcessor* owner,
GrGLSLShaderBuilder* builder,
GrGLSLUniformHandler* uniformHandler, GrGLSLUniformHandler* uniformHandler,
const GrShaderCaps* shaderCaps, const GrShaderCaps* shaderCaps,
const GrTextureDomain& textureDomain, const GrTextureDomain& textureDomain,
@ -114,10 +116,12 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
builder->codeAppend(";"); builder->codeAppend(";");
return SkString("textureColor"); return SkString("textureColor");
}; };
this->sample(builder, uniformHandler, textureDomain, outColor, inCoords, appendTextureSample); this->sample(owner, builder, uniformHandler, textureDomain, outColor, inCoords,
appendTextureSample);
} }
void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder, void GrTextureDomain::GLDomain::sample(const GrFragmentProcessor* owner,
GrGLSLShaderBuilder* builder,
GrGLSLUniformHandler* uniformHandler, GrGLSLUniformHandler* uniformHandler,
const GrTextureDomain& textureDomain, const GrTextureDomain& textureDomain,
const char* outColor, const char* outColor,
@ -136,7 +140,7 @@ void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder,
if (textureDomain.fIndex >= 0) { if (textureDomain.fIndex >= 0) {
uniName.appendS32(textureDomain.fIndex); uniName.appendS32(textureDomain.fIndex);
} }
fDomainUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, fDomainUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf4_GrSLType,
uniName.c_str(), &name); uniName.c_str(), &name);
fDomainName = name; fDomainName = name;
} }
@ -150,7 +154,7 @@ void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder,
uniName.appendS32(textureDomain.fIndex); uniName.appendS32(textureDomain.fIndex);
} }
// Half3 since this will hold texture width, height, and then a step function control param // Half3 since this will hold texture width, height, and then a step function control param
fDecalUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, fDecalUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
uniName.c_str(), &name); uniName.c_str(), &name);
fDecalName = name; fDecalName = name;
} }

View File

@ -137,7 +137,8 @@ public:
* domain. * domain.
* @param inColor color passed to the child processor. * @param inColor color passed to the child processor.
*/ */
void sampleProcessor(const GrTextureDomain& textureDomain, void sampleProcessor(const GrFragmentProcessor* owner,
const GrTextureDomain& textureDomain,
const char* inColor, const char* inColor,
const char* outColor, const char* outColor,
const SkString& inCoords, const SkString& inCoords,
@ -155,7 +156,8 @@ public:
* @param inModulateColor if non-nullptr the sampled color will be modulated with this * @param inModulateColor if non-nullptr the sampled color will be modulated with this
* expression before being written to outColor. * expression before being written to outColor.
*/ */
void sampleTexture(GrGLSLShaderBuilder* builder, void sampleTexture(const GrFragmentProcessor* owner,
GrGLSLShaderBuilder* builder,
GrGLSLUniformHandler* uniformHandler, GrGLSLUniformHandler* uniformHandler,
const GrShaderCaps* shaderCaps, const GrShaderCaps* shaderCaps,
const GrTextureDomain& textureDomain, const GrTextureDomain& textureDomain,
@ -203,7 +205,8 @@ public:
// the evaluates to a half4 color. // the evaluates to a half4 color.
using AppendSample = SkString(const char* coord); using AppendSample = SkString(const char* coord);
void sample(GrGLSLShaderBuilder* builder, void sample(const GrFragmentProcessor* owner,
GrGLSLShaderBuilder* builder,
GrGLSLUniformHandler* uniformHandler, GrGLSLUniformHandler* uniformHandler,
const GrTextureDomain& textureDomain, const GrTextureDomain& textureDomain,
const char* outColor, const char* outColor,

View File

@ -275,7 +275,7 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
if (te.fShaderModes[0] == ShaderMode::kClampToBorder || if (te.fShaderModes[0] == ShaderMode::kClampToBorder ||
te.fShaderModes[1] == ShaderMode::kClampToBorder) { te.fShaderModes[1] == ShaderMode::kClampToBorder) {
fBorderUni = args.fUniformHandler->addUniform( fBorderUni = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "border", &borderName); &te, kFragment_GrShaderFlag, kHalf4_GrSLType, "border", &borderName);
} }
auto modeUsesSubset = [](ShaderMode m) { auto modeUsesSubset = [](ShaderMode m) {
return m == ShaderMode::kRepeat || m == ShaderMode::kMirrorRepeat || return m == ShaderMode::kRepeat || m == ShaderMode::kMirrorRepeat ||
@ -293,13 +293,13 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
const char* subsetName = nullptr; const char* subsetName = nullptr;
if (useSubset[0] || useSubset[1]) { if (useSubset[0] || useSubset[1]) {
fSubsetUni = args.fUniformHandler->addUniform( fSubsetUni = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "subset", &subsetName); &te, kFragment_GrShaderFlag, kFloat4_GrSLType, "subset", &subsetName);
} }
const char* clampName = nullptr; const char* clampName = nullptr;
if (useClamp[0] || useClamp[1]) { if (useClamp[0] || useClamp[1]) {
fClampUni = args.fUniformHandler->addUniform( fClampUni = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "clamp", &clampName); &te, kFragment_GrShaderFlag, kFloat4_GrSLType, "clamp", &clampName);
} }
// To keep things a little simpler, when we have filtering logic in the shader we // To keep things a little simpler, when we have filtering logic in the shader we
@ -310,7 +310,7 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
filterLogic[1] != FilterLogic::kNone)) { filterLogic[1] != FilterLogic::kNone)) {
// TODO: Detect support for textureSize() or polyfill textureSize() in SkSL and // TODO: Detect support for textureSize() or polyfill textureSize() in SkSL and
// always use? // always use?
fNormUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, fNormUni = args.fUniformHandler->addUniform(&te, kFragment_GrShaderFlag,
kFloat4_GrSLType, "norm", &norm); kFloat4_GrSLType, "norm", &norm);
// TODO: Remove the normalization from the CoordTransform to skip unnormalizing // TODO: Remove the normalization from the CoordTransform to skip unnormalizing
// step here. // step here.

View File

@ -162,9 +162,9 @@ GrGLSLFragmentProcessor* GrYUVtoRGBEffect::onCreateGLSLInstance() const {
rgba[0].c_str(), rgba[1].c_str(), rgba[2].c_str(), rgba[3].c_str()); rgba[0].c_str(), rgba[1].c_str(), rgba[2].c_str(), rgba[3].c_str());
if (kIdentity_SkYUVColorSpace != yuvEffect.fYUVColorSpace) { if (kIdentity_SkYUVColorSpace != yuvEffect.fYUVColorSpace) {
fColorSpaceMatrixVar = args.fUniformHandler->addUniform( fColorSpaceMatrixVar = args.fUniformHandler->addUniform(&yuvEffect,
kFragment_GrShaderFlag, kHalf3x3_GrSLType, "colorSpaceMatrix"); kFragment_GrShaderFlag, kHalf3x3_GrSLType, "colorSpaceMatrix");
fColorSpaceTranslateVar = args.fUniformHandler->addUniform( fColorSpaceTranslateVar = args.fUniformHandler->addUniform(&yuvEffect,
kFragment_GrShaderFlag, kHalf3_GrSLType, "colorSpaceTranslate"); kFragment_GrShaderFlag, kHalf3_GrSLType, "colorSpaceTranslate");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"color.rgb = saturate(color.rgb * %s + %s);", "color.rgb = saturate(color.rgb * %s + %s);",

View File

@ -29,7 +29,7 @@ public:
(void)rect; (void)rect;
prevRect = float4(-1.0); prevRect = float4(-1.0);
rectUniformVar = args.fUniformHandler->addUniform( rectUniformVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "rectUniform"); &_outer, kFragment_GrShaderFlag, kFloat4_GrSLType, "rectUniform");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"float4 prevRect = float4(%f, %f, %f, %f);\nhalf alpha;\n@switch (%d) {\n case " "float4 prevRect = float4(%f, %f, %f, %f);\nhalf alpha;\n@switch (%d) {\n case "
"0:\n case 2:\n alpha = half(all(greaterThan(float4(sk_FragCoord.xy, " "0:\n case 2:\n alpha = half(all(greaterThan(float4(sk_FragCoord.xy, "

View File

@ -37,10 +37,10 @@ public:
(void)innerThreshold; (void)innerThreshold;
auto outerThreshold = _outer.outerThreshold; auto outerThreshold = _outer.outerThreshold;
(void)outerThreshold; (void)outerThreshold;
innerThresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, innerThresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"innerThreshold"); kHalf_GrSLType, "innerThreshold");
outerThresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, outerThresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"outerThreshold"); kHalf_GrSLType, "outerThreshold");
SkString sk_TransformedCoords2D_0 = SkString sk_TransformedCoords2D_0 =
fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
fragBuilder->codeAppendf( fragBuilder->codeAppendf(

View File

@ -286,8 +286,8 @@ public:
(void)textureRadius; (void)textureRadius;
auto solidRadius = _outer.solidRadius; auto solidRadius = _outer.solidRadius;
(void)solidRadius; (void)solidRadius;
circleDataVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, circleDataVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"circleData"); kHalf4_GrSLType, "circleData");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"half2 vec = half2(half((sk_FragCoord.x - float(%s.x)) * float(%s.w)), " "half2 vec = half2(half((sk_FragCoord.x - float(%s.x)) * float(%s.w)), "
"half((sk_FragCoord.y - float(%s.y)) * float(%s.w)));\nhalf dist = length(vec) + " "half((sk_FragCoord.y - float(%s.y)) * float(%s.w)));\nhalf dist = length(vec) + "

View File

@ -30,8 +30,8 @@ public:
auto radius = _outer.radius; auto radius = _outer.radius;
(void)radius; (void)radius;
prevRadius = -1.0; prevRadius = -1.0;
circleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, circleVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"circle"); kFloat4_GrSLType, "circle");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"float2 prevCenter;\nfloat prevRadius = %f;\nhalf d;\n@if (%d == 2 || %d == 3) {\n " "float2 prevCenter;\nfloat prevRadius = %f;\nhalf d;\n@if (%d == 2 || %d == 3) {\n "
" d = half((length((%s.xy - sk_FragCoord.xy) * %s.w) - 1.0) * %s.z);\n} else {\n " " d = half((length((%s.xy - sk_FragCoord.xy) * %s.w) - 1.0) * %s.z);\n} else {\n "

View File

@ -34,8 +34,10 @@ public:
(void)clampRGBOutput; (void)clampRGBOutput;
auto premulOutput = _outer.premulOutput; auto premulOutput = _outer.premulOutput;
(void)premulOutput; (void)premulOutput;
mVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4x4_GrSLType, "m"); mVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf4x4_GrSLType,
vVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "v"); "m");
vVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf4_GrSLType,
"v");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"half4 inputColor = %s;\n@if (%s) {\n half nonZeroAlpha = max(inputColor.w, " "half4 inputColor = %s;\n@if (%s) {\n half nonZeroAlpha = max(inputColor.w, "
"9.9999997473787516e-05);\n inputColor = half4(inputColor.xyz / nonZeroAlpha, " "9.9999997473787516e-05);\n inputColor = half4(inputColor.xyz / nonZeroAlpha, "

View File

@ -25,8 +25,8 @@ public:
(void)_outer; (void)_outer;
auto weight = _outer.weight; auto weight = _outer.weight;
(void)weight; (void)weight;
weightVar = weightVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat_GrSLType, "weight"); kFloat_GrSLType, "weight");
SkString _sample290; SkString _sample290;
if (_outer.child1_index >= 0) { if (_outer.child1_index >= 0) {
_sample290 = this->invokeChild(_outer.child1_index, args); _sample290 = this->invokeChild(_outer.child1_index, args);

View File

@ -27,8 +27,8 @@ public:
(void)color; (void)color;
auto mode = _outer.mode; auto mode = _outer.mode;
(void)mode; (void)mode;
colorVar = colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "color"); kHalf4_GrSLType, "color");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"@switch (%d) {\n case 0:\n %s = %s;\n break;\n case 1:\n " "@switch (%d) {\n case 0:\n %s = %s;\n break;\n case 1:\n "
" %s = %s * %s;\n break;\n case 2:\n %s = %s.w * %s;\n " " %s = %s * %s;\n break;\n case 2:\n %s = %s.w * %s;\n "

View File

@ -31,11 +31,11 @@ public:
(void)radii; (void)radii;
prevRadii = float2(-1.0); prevRadii = float2(-1.0);
medPrecision = !sk_Caps.floatIs32Bits; medPrecision = !sk_Caps.floatIs32Bits;
ellipseVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, ellipseVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"ellipse"); kFloat4_GrSLType, "ellipse");
if (medPrecision) { if (medPrecision) {
scaleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat2_GrSLType, scaleVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale"); kFloat2_GrSLType, "scale");
} }
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"float2 prevCenter;\nfloat2 prevRadii = float2(%f, %f);\nbool medPrecision = " "float2 prevCenter;\nfloat2 prevRadii = float2(%f, %f);\nbool medPrecision = "

View File

@ -36,17 +36,17 @@ public:
auto yInvInset = _outer.yInvInset; auto yInvInset = _outer.yInvInset;
(void)yInvInset; (void)yInvInset;
boundsUniformVar = args.fUniformHandler->addUniform( boundsUniformVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "boundsUniform"); &_outer, kFragment_GrShaderFlag, kFloat4_GrSLType, "boundsUniform");
xInvZoomVar = args.fUniformHandler->addUniform( xInvZoomVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat_GrSLType, "xInvZoom"); &_outer, kFragment_GrShaderFlag, kFloat_GrSLType, "xInvZoom");
yInvZoomVar = args.fUniformHandler->addUniform( yInvZoomVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat_GrSLType, "yInvZoom"); &_outer, kFragment_GrShaderFlag, kFloat_GrSLType, "yInvZoom");
xInvInsetVar = args.fUniformHandler->addUniform( xInvInsetVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat_GrSLType, "xInvInset"); &_outer, kFragment_GrShaderFlag, kFloat_GrSLType, "xInvInset");
yInvInsetVar = args.fUniformHandler->addUniform( yInvInsetVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat_GrSLType, "yInvInset"); &_outer, kFragment_GrShaderFlag, kFloat_GrSLType, "yInvInset");
offsetVar = offsetVar = args.fUniformHandler->addUniform(
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "offset"); &_outer, kFragment_GrShaderFlag, kHalf2_GrSLType, "offset");
SkString sk_TransformedCoords2D_0 = SkString sk_TransformedCoords2D_0 =
fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
fragBuilder->codeAppendf( fragBuilder->codeAppendf(

View File

@ -25,8 +25,8 @@ public:
(void)_outer; (void)_outer;
auto weight = _outer.weight; auto weight = _outer.weight;
(void)weight; (void)weight;
weightVar = weightVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "weight"); kHalf_GrSLType, "weight");
SkString _input1278 = SkStringPrintf("%s", args.fInputColor); SkString _input1278 = SkStringPrintf("%s", args.fInputColor);
SkString _sample1278; SkString _sample1278;
_sample1278 = this->invokeChild(_outer.fp0_index, _input1278.c_str(), args); _sample1278 = this->invokeChild(_outer.fp0_index, _input1278.c_str(), args);

View File

@ -31,7 +31,7 @@ public:
auto literalColor = _outer.literalColor; auto literalColor = _outer.literalColor;
(void)literalColor; (void)literalColor;
if (useUniform) { if (useUniform) {
uniformColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, uniformColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "uniformColor"); kHalf4_GrSLType, "uniformColor");
} }
fragBuilder->codeAppendf( fragBuilder->codeAppendf(

View File

@ -68,12 +68,12 @@ public:
(void)rect; (void)rect;
auto cornerRadius = _outer.cornerRadius; auto cornerRadius = _outer.cornerRadius;
(void)cornerRadius; (void)cornerRadius;
cornerRadiusVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, cornerRadiusVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"cornerRadius"); kHalf_GrSLType, "cornerRadius");
proxyRectVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, proxyRectVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"proxyRect"); kFloat4_GrSLType, "proxyRect");
blurRadiusVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, blurRadiusVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"blurRadius"); kHalf_GrSLType, "blurRadius");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"\nhalf2 translatedFragPos = half2(sk_FragCoord.xy - %s.xy);\nhalf threshold = %s " "\nhalf2 translatedFragPos = half2(sk_FragCoord.xy - %s.xy);\nhalf threshold = %s "
"+ 2.0 * %s;\nhalf2 middle = half2((%s.zw - %s.xy) - float(2.0 * threshold));\nif " "+ 2.0 * %s;\nhalf2 middle = half2((%s.zw - %s.xy) - float(2.0 * threshold));\nif "

View File

@ -33,15 +33,15 @@ public:
abs(rect.right()) > 16000.0) || abs(rect.right()) > 16000.0) ||
abs(rect.bottom()) > 16000.0; abs(rect.bottom()) > 16000.0;
if (highp) { if (highp) {
rectFVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, rectFVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"rectF"); kFloat4_GrSLType, "rectF");
} }
if (!highp) { if (!highp) {
rectHVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, rectHVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"rectH"); kHalf4_GrSLType, "rectH");
} }
invSixSigmaVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, invSixSigmaVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"invSixSigma"); kHalf_GrSLType, "invSixSigma");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"/* key */ bool highp = %s;\nhalf xCoverage, yCoverage;\n@if (%s) {\n half x, " "/* key */ bool highp = %s;\nhalf xCoverage, yCoverage;\n@if (%s) {\n half x, "
"y;\n @if (highp) {\n x = max(half(%s.x - sk_FragCoord.x), " "y;\n @if (highp) {\n x = max(half(%s.x - sk_FragCoord.x), "

View File

@ -21,7 +21,7 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID,
, fProgramID(programID) { , fProgramID(programID) {
fUniforms.push_back_n(uniforms.count()); fUniforms.push_back_n(uniforms.count());
int i = 0; int i = 0;
for (const UniformInfo& builderUniform : uniforms.items()) { for (const GLUniformInfo& builderUniform : uniforms.items()) {
Uniform& uniform = fUniforms[i++]; Uniform& uniform = fUniforms[i++];
SkASSERT(GrShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() || SkASSERT(GrShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() ||
builderUniform.fVariable.getArrayCount() > 0); builderUniform.fVariable.getArrayCount() > 0);
@ -51,7 +51,7 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID,
void GrGLProgramDataManager::setSamplerUniforms(const UniformInfoArray& samplers, void GrGLProgramDataManager::setSamplerUniforms(const UniformInfoArray& samplers,
int startUnit) const { int startUnit) const {
int i = 0; int i = 0;
for (const UniformInfo& sampler : samplers.items()) { for (const GLUniformInfo& sampler : samplers.items()) {
SkASSERT(sampler.fVisibility); SkASSERT(sampler.fVisibility);
if (kUnusedUniform != sampler.fLocation) { if (kUnusedUniform != sampler.fLocation) {
GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i + startUnit)); GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i + startUnit));

View File

@ -12,6 +12,7 @@
#include "src/gpu/GrShaderVar.h" #include "src/gpu/GrShaderVar.h"
#include "src/gpu/GrTAllocator.h" #include "src/gpu/GrTAllocator.h"
#include "src/gpu/glsl/GrGLSLProgramDataManager.h" #include "src/gpu/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/glsl/GrGLSLUniformHandler.h"
#include "include/private/SkTArray.h" #include "include/private/SkTArray.h"
@ -25,22 +26,20 @@ class GrGLProgram;
*/ */
class GrGLProgramDataManager : public GrGLSLProgramDataManager { class GrGLProgramDataManager : public GrGLSLProgramDataManager {
public: public:
struct UniformInfo { struct GLUniformInfo : public GrGLSLUniformHandler::UniformInfo {
GrShaderVar fVariable; GrGLint fLocation;
uint32_t fVisibility;
GrGLint fLocation;
}; };
struct VaryingInfo { struct VaryingInfo {
GrShaderVar fVariable; GrShaderVar fVariable;
GrGLint fLocation; GrGLint fLocation;
}; };
// This uses an allocator rather than array so that the GrShaderVars don't move in memory // This uses an allocator rather than array so that the GrShaderVars don't move in memory
// after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
// name strings. Otherwise, we'd have to hand out copies. // name strings. Otherwise, we'd have to hand out copies.
typedef GrTAllocator<UniformInfo> UniformInfoArray; typedef GrTAllocator<GLUniformInfo> UniformInfoArray;
typedef GrTAllocator<VaryingInfo> VaryingInfoArray; typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&, GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
const VaryingInfoArray&); const VaryingInfoArray&);

View File

@ -25,12 +25,13 @@ bool valid_name(const char* name) {
} }
GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray( GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray(
uint32_t visibility, const GrFragmentProcessor* owner,
GrSLType type, uint32_t visibility,
const char* name, GrSLType type,
bool mangleName, const char* name,
int arrayCount, bool mangleName,
const char** outName) { int arrayCount,
const char** outName) {
SkASSERT(name && strlen(name)); SkASSERT(name && strlen(name));
SkASSERT(valid_name(name)); SkASSERT(valid_name(name));
SkASSERT(0 != visibility); SkASSERT(0 != visibility);
@ -47,10 +48,13 @@ GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray(
prefix = '\0'; prefix = '\0';
} }
fProgramBuilder->nameVariable(&resolvedName, prefix, name, mangleName); fProgramBuilder->nameVariable(&resolvedName, prefix, name, mangleName);
GLUniformInfo& uni = fUniforms.push_back(GrGLProgramDataManager::GLUniformInfo{
UniformInfo& uni = fUniforms.push_back(GrGLProgramDataManager::UniformInfo{ {
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::Uniform, arrayCount}, GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::Uniform,
visibility, -1 arrayCount},
visibility, owner, SkString(name)
},
-1
}); });
if (outName) { if (outName) {
@ -70,11 +74,13 @@ GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::addSampler(
GrTextureType type = backendFormat.textureType(); GrTextureType type = backendFormat.textureType();
fSamplers.push_back(GrGLProgramDataManager::UniformInfo{ fSamplers.push_back(GrGLProgramDataManager::GLUniformInfo{
GrShaderVar{std::move(mangleName), {
GrSLCombinedSamplerTypeForTextureType(type), GrShaderVar{std::move(mangleName), GrSLCombinedSamplerTypeForTextureType(type),
GrShaderVar::TypeModifier::Uniform}, GrShaderVar::TypeModifier::Uniform},
kFragment_GrShaderFlag, -1 kFragment_GrShaderFlag, nullptr, SkString(name)
},
-1
}); });
if (shaderCaps->textureSwizzleAppliedInShader()) { if (shaderCaps->textureSwizzleAppliedInShader()) {
@ -102,12 +108,12 @@ void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps& caps) { void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
if (caps.bindUniformLocationSupport()) { if (caps.bindUniformLocationSupport()) {
int currUniform = 0; int currUniform = 0;
for (UniformInfo& uniform : fUniforms.items()) { for (GLUniformInfo& uniform : fUniforms.items()) {
GL_CALL(BindUniformLocation(programID, currUniform, uniform.fVariable.c_str())); GL_CALL(BindUniformLocation(programID, currUniform, uniform.fVariable.c_str()));
uniform.fLocation = currUniform; uniform.fLocation = currUniform;
++currUniform; ++currUniform;
} }
for (UniformInfo& sampler : fSamplers.items()) { for (GLUniformInfo& sampler : fSamplers.items()) {
GL_CALL(BindUniformLocation(programID, currUniform, sampler.fVariable.c_str())); GL_CALL(BindUniformLocation(programID, currUniform, sampler.fVariable.c_str()));
sampler.fLocation = currUniform; sampler.fLocation = currUniform;
++currUniform; ++currUniform;
@ -117,12 +123,12 @@ void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force) { void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force) {
if (!caps.bindUniformLocationSupport() || force) { if (!caps.bindUniformLocationSupport() || force) {
for (UniformInfo& uniform : fUniforms.items()) { for (GLUniformInfo& uniform : fUniforms.items()) {
GrGLint location; GrGLint location;
GL_CALL_RET(location, GetUniformLocation(programID, uniform.fVariable.c_str())); GL_CALL_RET(location, GetUniformLocation(programID, uniform.fVariable.c_str()));
uniform.fLocation = location; uniform.fLocation = location;
} }
for (UniformInfo& sampler : fSamplers.items()) { for (GLUniformInfo& sampler : fSamplers.items()) {
GrGLint location; GrGLint location;
GL_CALL_RET(location, GetUniformLocation(programID, sampler.fVariable.c_str())); GL_CALL_RET(location, GetUniformLocation(programID, sampler.fVariable.c_str()));
sampler.fLocation = location; sampler.fLocation = location;

View File

@ -8,9 +8,10 @@
#ifndef GrGLUniformHandler_DEFINED #ifndef GrGLUniformHandler_DEFINED
#define GrGLUniformHandler_DEFINED #define GrGLUniformHandler_DEFINED
#include "src/gpu/gl/GrGLProgramDataManager.h"
#include "src/gpu/glsl/GrGLSLUniformHandler.h" #include "src/gpu/glsl/GrGLSLUniformHandler.h"
#include "src/gpu/gl/GrGLProgramDataManager.h" #include <vector>
class GrGLCaps; class GrGLCaps;
@ -31,7 +32,8 @@ private:
, fUniforms(kUniformsPerBlock) , fUniforms(kUniformsPerBlock)
, fSamplers(kUniformsPerBlock) {} , fSamplers(kUniformsPerBlock) {}
UniformHandle internalAddUniformArray(uint32_t visibility, UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
bool mangleName, bool mangleName,
@ -59,12 +61,12 @@ private:
const GrGLGpu* glGpu() const; const GrGLGpu* glGpu() const;
typedef GrGLProgramDataManager::UniformInfo UniformInfo; typedef GrGLProgramDataManager::GLUniformInfo GLUniformInfo;
typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
UniformInfoArray fUniforms; UniformInfoArray fUniforms;
UniformInfoArray fSamplers; UniformInfoArray fSamplers;
SkTArray<GrSwizzle> fSamplerSwizzles; SkTArray<GrSwizzle> fSamplerSwizzles;
friend class GrGLProgramBuilder; friend class GrGLProgramBuilder;

View File

@ -28,16 +28,16 @@ public:
if (colorSpaceXform) { if (colorSpaceXform) {
fFlags = colorSpaceXform->fSteps.flags; fFlags = colorSpaceXform->fSteps.flags;
if (this->applySrcTF()) { if (this->applySrcTF()) {
fSrcTFVar = uniformHandler->addUniformArray(visibility, kHalf_GrSLType, fSrcTFVar = uniformHandler->addUniformArray(nullptr, visibility, kHalf_GrSLType,
"SrcTF", kNumTransferFnCoeffs); "SrcTF", kNumTransferFnCoeffs);
fSrcTFKind = classify_transfer_fn(colorSpaceXform->fSteps.srcTF); fSrcTFKind = classify_transfer_fn(colorSpaceXform->fSteps.srcTF);
} }
if (this->applyGamutXform()) { if (this->applyGamutXform()) {
fGamutXformVar = uniformHandler->addUniform(visibility, kHalf3x3_GrSLType, fGamutXformVar = uniformHandler->addUniform(nullptr, visibility, kHalf3x3_GrSLType,
"ColorXform"); "ColorXform");
} }
if (this->applyDstTF()) { if (this->applyDstTF()) {
fDstTFVar = uniformHandler->addUniformArray(visibility, kHalf_GrSLType, fDstTFVar = uniformHandler->addUniformArray(nullptr, visibility, kHalf_GrSLType,
"DstTF", kNumTransferFnCoeffs); "DstTF", kNumTransferFnCoeffs);
fDstTFKind = classify_transfer_fn(colorSpaceXform->fSteps.dstTFInv); fDstTFKind = classify_transfer_fn(colorSpaceXform->fSteps.dstTFInv);
} }

View File

@ -97,7 +97,8 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb,
uni.fType = kFloat3x3_GrSLType; uni.fType = kFloat3x3_GrSLType;
} }
uni.fHandle = uni.fHandle =
uniformHandler->addUniform(flag, uni.fType, strUniName.c_str(), &matrixName); uniformHandler->addUniform(&fp, flag, uni.fType, strUniName.c_str(),
&matrixName);
transformVar = uniformHandler->getUniformVariable(uni.fHandle); transformVar = uniformHandler->getUniformVariable(uni.fHandle);
} else { } else {
// Install a coord transform that will be skipped. // Install a coord transform that will be skipped.
@ -181,7 +182,8 @@ void GrGLSLGeometryProcessor::writeOutputPosition(GrGLSLVertexBuilder* vertBuild
vertBuilder->codeAppendf("float2 %s = %s;", gpArgs->fPositionVar.c_str(), posName); vertBuilder->codeAppendf("float2 %s = %s;", gpArgs->fPositionVar.c_str(), posName);
} else { } else {
const char* viewMatrixName; const char* viewMatrixName;
*viewMatrixUniform = uniformHandler->addUniform(kVertex_GrShaderFlag, *viewMatrixUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat3x3_GrSLType, kFloat3x3_GrSLType,
"uViewM", "uViewM",
&viewMatrixName); &viewMatrixName);

View File

@ -54,7 +54,8 @@ void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLFPFragmentBuilder* fragBu
UniformHandle* colorUniform) { UniformHandle* colorUniform) {
SkASSERT(colorUniform); SkASSERT(colorUniform);
const char* stagedLocalVarName; const char* stagedLocalVarName;
*colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, *colorUniform = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf4_GrSLType, kHalf4_GrSLType,
"Color", "Color",
&stagedLocalVarName); &stagedLocalVarName);

View File

@ -79,7 +79,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(SkString* outputColor, SkStrin
rtAdjustVisibility = kVertex_GrShaderFlag; rtAdjustVisibility = kVertex_GrShaderFlag;
} }
fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform( fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform(
rtAdjustVisibility, kFloat4_GrSLType, SkSL::Compiler::RTADJUST_NAME); nullptr, rtAdjustVisibility, kFloat4_GrSLType, SkSL::Compiler::RTADJUST_NAME);
const char* rtAdjustName = const char* rtAdjustName =
this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni); this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni);
@ -335,16 +335,16 @@ void GrGLSLProgramBuilder::addRTWidthUniform(const char* name) {
SkASSERT(!fUniformHandles.fRTWidthUni.isValid()); SkASSERT(!fUniformHandles.fRTWidthUni.isValid());
GrGLSLUniformHandler* uniformHandler = this->uniformHandler(); GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
fUniformHandles.fRTWidthUni = fUniformHandles.fRTWidthUni =
uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name, uniformHandler->internalAddUniformArray(nullptr, kFragment_GrShaderFlag, kHalf_GrSLType,
false, 0, nullptr); name, false, 0, nullptr);
} }
void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) { void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
SkASSERT(!fUniformHandles.fRTHeightUni.isValid()); SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
GrGLSLUniformHandler* uniformHandler = this->uniformHandler(); GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
fUniformHandles.fRTHeightUni = fUniformHandles.fRTHeightUni =
uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name, uniformHandler->internalAddUniformArray(nullptr, kFragment_GrShaderFlag, kHalf_GrSLType,
false, 0, nullptr); name, false, 0, nullptr);
} }
void GrGLSLProgramBuilder::finalizeShaders() { void GrGLSLProgramBuilder::finalizeShaders() {

View File

@ -31,6 +31,13 @@ struct GrGLSLBuiltinUniformHandles {
class GrGLSLUniformHandler { class GrGLSLUniformHandler {
public: public:
struct UniformInfo {
GrShaderVar fVariable;
uint32_t fVisibility;
const GrFragmentProcessor* fOwner;
SkString fRawName;
};
virtual ~GrGLSLUniformHandler() {} virtual ~GrGLSLUniformHandler() {}
using UniformHandle = GrGLSLProgramDataManager::UniformHandle; using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
@ -43,22 +50,25 @@ public:
supported at this time. The actual uniform name will be mangled. If outName is not nullptr supported at this time. The actual uniform name will be mangled. If outName is not nullptr
then it will refer to the final uniform name after return. Use the addUniformArray variant then it will refer to the final uniform name after return. Use the addUniformArray variant
to add an array of uniforms. */ to add an array of uniforms. */
UniformHandle addUniform(uint32_t visibility, UniformHandle addUniform(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
const char** outName = nullptr) { const char** outName = nullptr) {
SkASSERT(!GrSLTypeIsCombinedSamplerType(type)); SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
return this->addUniformArray(visibility, type, name, 0, outName); return this->addUniformArray(owner, visibility, type, name, 0, outName);
} }
UniformHandle addUniformArray(uint32_t visibility, UniformHandle addUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
int arrayCount, int arrayCount,
const char** outName = nullptr) { const char** outName = nullptr) {
SkASSERT(!GrSLTypeIsCombinedSamplerType(type)); SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
bool mangle = strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX)); bool mangle = strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX));
return this->internalAddUniformArray(visibility, type, name, mangle, arrayCount, outName); return this->internalAddUniformArray(owner, visibility, type, name, mangle, arrayCount,
outName);
} }
virtual const GrShaderVar& getUniformVariable(UniformHandle u) const = 0; virtual const GrShaderVar& getUniformVariable(UniformHandle u) const = 0;
@ -82,7 +92,8 @@ private:
virtual SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, virtual SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&,
const char* name, const GrShaderCaps*) = 0; const char* name, const GrShaderCaps*) = 0;
virtual UniformHandle internalAddUniformArray(uint32_t visibility, virtual UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
bool mangleName, bool mangleName,

View File

@ -59,11 +59,13 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
const char* dstTopLeftName; const char* dstTopLeftName;
const char* dstCoordScaleName; const char* dstCoordScaleName;
fDstTopLeftUni = uniformHandler->addUniform(kFragment_GrShaderFlag, fDstTopLeftUni = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf2_GrSLType, kHalf2_GrSLType,
"DstTextureUpperLeft", "DstTextureUpperLeft",
&dstTopLeftName); &dstTopLeftName);
fDstScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, fDstScaleUni = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf2_GrSLType, kHalf2_GrSLType,
"DstTextureCoordScale", "DstTextureCoordScale",
&dstCoordScaleName); &dstCoordScaleName);

View File

@ -31,9 +31,9 @@ public:
(void)makePremul; (void)makePremul;
auto colorsAreOpaque = _outer.colorsAreOpaque; auto colorsAreOpaque = _outer.colorsAreOpaque;
(void)colorsAreOpaque; (void)colorsAreOpaque;
leftBorderColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, leftBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "leftBorderColor"); kHalf4_GrSLType, "leftBorderColor");
rightBorderColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, rightBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "rightBorderColor"); kHalf4_GrSLType, "rightBorderColor");
SkString _sample1099; SkString _sample1099;
_sample1099 = this->invokeChild(_outer.gradLayout_index, args); _sample1099 = this->invokeChild(_outer.gradLayout_index, args);

View File

@ -34,16 +34,16 @@ public:
(void)bias23; (void)bias23;
auto threshold = _outer.threshold; auto threshold = _outer.threshold;
(void)threshold; (void)threshold;
scale01Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale01Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale01"); kFloat4_GrSLType, "scale01");
bias01Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias01Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias01"); kFloat4_GrSLType, "bias01");
scale23Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale23Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale23"); kFloat4_GrSLType, "scale23");
bias23Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias23Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias23"); kFloat4_GrSLType, "bias23");
thresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, thresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"threshold"); kHalf_GrSLType, "threshold");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"half t = %s.x;\nfloat4 scale, bias;\nif (t < %s) {\n scale = %s;\n bias = " "half t = %s.x;\nfloat4 scale, bias;\nif (t < %s) {\n scale = %s;\n bias = "
"%s;\n} else {\n scale = %s;\n bias = %s;\n}\n%s = half4(float(t) * scale + " "%s;\n} else {\n scale = %s;\n bias = %s;\n}\n%s = half4(float(t) * scale + "

View File

@ -28,9 +28,10 @@ public:
(void)start; (void)start;
auto end = _outer.end; auto end = _outer.end;
(void)end; (void)end;
startVar = startVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "start"); kHalf4_GrSLType, "start");
endVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "end"); endVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf4_GrSLType,
"end");
fragBuilder->codeAppendf("half t = %s.x;\n%s = (1.0 - t) * %s + t * %s;\n", fragBuilder->codeAppendf("half t = %s.x;\n%s = (1.0 - t) * %s + t * %s;\n",
args.fInputColor, args.fOutputColor, args.fInputColor, args.fOutputColor,
args.fUniformHandler->getUniformCStr(startVar), args.fUniformHandler->getUniformCStr(startVar),

View File

@ -29,9 +29,10 @@ public:
(void)bias; (void)bias;
auto scale = _outer.scale; auto scale = _outer.scale;
(void)scale; (void)scale;
biasVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "bias"); biasVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf_GrSLType,
scaleVar = "bias");
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "scale"); scaleVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf_GrSLType,
"scale");
SkString sk_TransformedCoords2D_0 = SkString sk_TransformedCoords2D_0 =
fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
fragBuilder->codeAppendf( fragBuilder->codeAppendf(

View File

@ -40,8 +40,8 @@ public:
(void)isNativelyFocal; (void)isNativelyFocal;
auto focalParams = _outer.focalParams; auto focalParams = _outer.focalParams;
(void)focalParams; (void)focalParams;
focalParamsVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, focalParamsVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"focalParams"); kHalf2_GrSLType, "focalParams");
SkString sk_TransformedCoords2D_0 = SkString sk_TransformedCoords2D_0 =
fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
fragBuilder->codeAppendf( fragBuilder->codeAppendf(

View File

@ -62,69 +62,69 @@ public:
(void)thresholds1_7; (void)thresholds1_7;
auto thresholds9_13 = _outer.thresholds9_13; auto thresholds9_13 = _outer.thresholds9_13;
(void)thresholds9_13; (void)thresholds9_13;
scale0_1Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale0_1Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale0_1"); kFloat4_GrSLType, "scale0_1");
if (intervalCount > 1) { if (intervalCount > 1) {
scale2_3Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale2_3Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale2_3"); kFloat4_GrSLType, "scale2_3");
} }
if (intervalCount > 2) { if (intervalCount > 2) {
scale4_5Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale4_5Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale4_5"); kFloat4_GrSLType, "scale4_5");
} }
if (intervalCount > 3) { if (intervalCount > 3) {
scale6_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale6_7Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale6_7"); kFloat4_GrSLType, "scale6_7");
} }
if (intervalCount > 4) { if (intervalCount > 4) {
scale8_9Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, scale8_9Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"scale8_9"); kFloat4_GrSLType, "scale8_9");
} }
if (intervalCount > 5) { if (intervalCount > 5) {
scale10_11Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, scale10_11Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale10_11"); kFloat4_GrSLType, "scale10_11");
} }
if (intervalCount > 6) { if (intervalCount > 6) {
scale12_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, scale12_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale12_13"); kFloat4_GrSLType, "scale12_13");
} }
if (intervalCount > 7) { if (intervalCount > 7) {
scale14_15Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, scale14_15Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale14_15"); kFloat4_GrSLType, "scale14_15");
} }
bias0_1Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias0_1Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias0_1"); kFloat4_GrSLType, "bias0_1");
if (intervalCount > 1) { if (intervalCount > 1) {
bias2_3Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias2_3Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias2_3"); kFloat4_GrSLType, "bias2_3");
} }
if (intervalCount > 2) { if (intervalCount > 2) {
bias4_5Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias4_5Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias4_5"); kFloat4_GrSLType, "bias4_5");
} }
if (intervalCount > 3) { if (intervalCount > 3) {
bias6_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias6_7Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias6_7"); kFloat4_GrSLType, "bias6_7");
} }
if (intervalCount > 4) { if (intervalCount > 4) {
bias8_9Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, bias8_9Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"bias8_9"); kFloat4_GrSLType, "bias8_9");
} }
if (intervalCount > 5) { if (intervalCount > 5) {
bias10_11Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, bias10_11Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias10_11"); kFloat4_GrSLType, "bias10_11");
} }
if (intervalCount > 6) { if (intervalCount > 6) {
bias12_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, bias12_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias12_13"); kFloat4_GrSLType, "bias12_13");
} }
if (intervalCount > 7) { if (intervalCount > 7) {
bias14_15Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, bias14_15Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias14_15"); kFloat4_GrSLType, "bias14_15");
} }
thresholds1_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, thresholds1_7Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
"thresholds1_7"); kHalf4_GrSLType, "thresholds1_7");
thresholds9_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, thresholds9_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "thresholds9_13"); kHalf4_GrSLType, "thresholds9_13");
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
"half t = %s.x;\nfloat4 scale, bias;\nif (%d <= 4 || t < %s.w) {\n if (%d <= 2 " "half t = %s.x;\nfloat4 scale, bias;\nif (%d <= 4 || t < %s.w) {\n if (%d <= 2 "

View File

@ -12,6 +12,8 @@
#include "src/gpu/GrTAllocator.h" #include "src/gpu/GrTAllocator.h"
#include "src/gpu/glsl/GrGLSLUniformHandler.h" #include "src/gpu/glsl/GrGLSLUniformHandler.h"
#include <vector>
// TODO: this class is basically copy and pasted from GrVkUniformHandler so that we can have // TODO: this class is basically copy and pasted from GrVkUniformHandler so that we can have
// some shaders working. The SkSL Metal code generator was written to work with GLSL generated for // some shaders working. The SkSL Metal code generator was written to work with GLSL generated for
// the Ganesh Vulkan backend, so it should all work. There might be better ways to do things in // the Ganesh Vulkan backend, so it should all work. There might be better ways to do things in
@ -26,12 +28,10 @@ public:
}; };
// fUBOffset is only valid if the GrSLType of the fVariable is not a sampler // fUBOffset is only valid if the GrSLType of the fVariable is not a sampler
struct UniformInfo { struct MtlUniformInfo : public UniformInfo {
GrShaderVar fVariable; uint32_t fUBOffset;
uint32_t fVisibility;
uint32_t fUBOffset;
}; };
typedef GrTAllocator<UniformInfo> UniformInfoArray; typedef GrTAllocator<MtlUniformInfo> UniformInfoArray;
const GrShaderVar& getUniformVariable(UniformHandle u) const override { const GrShaderVar& getUniformVariable(UniformHandle u) const override {
return fUniforms.item(u.toIndex()).fVariable; return fUniforms.item(u.toIndex()).fVariable;
@ -50,7 +50,8 @@ private:
, fCurrentUBOMaxAlignment(0x0) { , fCurrentUBOMaxAlignment(0x0) {
} }
UniformHandle internalAddUniformArray(uint32_t visibility, UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
bool mangleName, bool mangleName,

View File

@ -200,12 +200,13 @@ static uint32_t get_ubo_aligned_offset(uint32_t* currentOffset,
} }
GrGLSLUniformHandler::UniformHandle GrMtlUniformHandler::internalAddUniformArray( GrGLSLUniformHandler::UniformHandle GrMtlUniformHandler::internalAddUniformArray(
uint32_t visibility, const GrFragmentProcessor* owner,
GrSLType type, uint32_t visibility,
const char* name, GrSLType type,
bool mangleName, const char* name,
int arrayCount, bool mangleName,
const char** outName) { int arrayCount,
const char** outName) {
SkASSERT(name && strlen(name)); SkASSERT(name && strlen(name));
GrSLTypeIsFloatType(type); GrSLTypeIsFloatType(type);
@ -229,10 +230,13 @@ GrGLSLUniformHandler::UniformHandle GrMtlUniformHandler::internalAddUniformArray
// When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
// we set the modifier to none for all uniforms declared inside the block. // we set the modifier to none for all uniforms declared inside the block.
UniformInfo& uni = fUniforms.push_back(GrMtlUniformHandler::UniformInfo{ UniformInfo& uni = fUniforms.push_back(MtlUniformInfo{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount, {
std::move(layoutQualifier), SkString()}, GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
kFragment_GrShaderFlag | kVertex_GrShaderFlag, offset std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag | kVertex_GrShaderFlag, owner, SkString(name)
},
offset
}); });
if (outName) { if (outName) {
@ -257,11 +261,14 @@ GrGLSLUniformHandler::SamplerHandle GrMtlUniformHandler::addSampler(
SkString layoutQualifier; SkString layoutQualifier;
layoutQualifier.appendf("binding=%d", binding); layoutQualifier.appendf("binding=%d", binding);
fSamplers.push_back(GrMtlUniformHandler::UniformInfo{ fSamplers.push_back(MtlUniformInfo{
GrShaderVar{std::move(mangleName), GrSLCombinedSamplerTypeForTextureType(type), {
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray, GrShaderVar{std::move(mangleName), GrSLCombinedSamplerTypeForTextureType(type),
std::move(layoutQualifier), SkString()}, GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
kFragment_GrShaderFlag, 0 std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag, nullptr, SkString(name)
},
0
}); });
SkASSERT(caps->textureSwizzleAppliedInShader()); SkASSERT(caps->textureSwizzleAppliedInShader());
@ -281,7 +288,7 @@ void GrMtlUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
#ifdef SK_DEBUG #ifdef SK_DEBUG
bool firstOffsetCheck = false; bool firstOffsetCheck = false;
for (const UniformInfo& localUniform : fUniforms.items()) { for (const MtlUniformInfo& localUniform : fUniforms.items()) {
if (!firstOffsetCheck) { if (!firstOffsetCheck) {
// Check to make sure we are starting our offset at 0 so the offset qualifier we // Check to make sure we are starting our offset at 0 so the offset qualifier we
// set on each variable in the uniform block is valid. // set on each variable in the uniform block is valid.

View File

@ -69,7 +69,7 @@ class DrawAtlasPathShader::Impl : public GrGLSLGeometryProcessor {
const char* atlasAdjust; const char* atlasAdjust;
fAtlasAdjustUniform = args.fUniformHandler->addUniform( fAtlasAdjustUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat2_GrSLType, "atlas_adjust", &atlasAdjust); nullptr, kVertex_GrShaderFlag, kFloat2_GrSLType, "atlas_adjust", &atlasAdjust);
args.fVertBuilder->codeAppendf(R"( args.fVertBuilder->codeAppendf(R"(
float2 T = float2(sk_VertexID & 1, sk_VertexID >> 1); float2 T = float2(sk_VertexID & 1, sk_VertexID >> 1);

View File

@ -19,7 +19,7 @@ public:
const char* viewMatrix; const char* viewMatrix;
fViewMatrixUniform = args.fUniformHandler->addUniform( fViewMatrixUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix); nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
args.fVaryingHandler->emitAttributes(shader); args.fVaryingHandler->emitAttributes(shader);
@ -34,7 +34,7 @@ public:
const char* color; const char* color;
fColorUniform = args.fUniformHandler->addUniform( fColorUniform = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "color", &color); nullptr, kFragment_GrShaderFlag, kHalf4_GrSLType, "color", &color);
args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, color); args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, color);
args.fFragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage); args.fFragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
@ -120,7 +120,7 @@ void GrFillBoundingBoxShader::emitVertexCode(Impl* impl, GrGLSLVertexBuilder* v,
GrGLSLUniformHandler* uniformHandler) const { GrGLSLUniformHandler* uniformHandler) const {
const char* pathBounds; const char* pathBounds;
impl->fPathBoundsUniform = uniformHandler->addUniform( impl->fPathBoundsUniform = uniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat4_GrSLType, "path_bounds", &pathBounds); nullptr, kVertex_GrShaderFlag, kFloat4_GrSLType, "path_bounds", &pathBounds);
v->codeAppendf(R"( v->codeAppendf(R"(
// Use sk_VertexID and uniforms (instead of vertex data) to find vertex positions. // Use sk_VertexID and uniforms (instead of vertex data) to find vertex positions.

View File

@ -43,7 +43,7 @@ class GrStencilPathShader::Impl : public GrGLSLGeometryProcessor {
if (!shader.viewMatrix().isIdentity()) { if (!shader.viewMatrix().isIdentity()) {
const char* viewMatrix; const char* viewMatrix;
fViewMatrixUniform = args.fUniformHandler->addUniform( fViewMatrixUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix); nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
args.fVertBuilder->codeAppendf( args.fVertBuilder->codeAppendf(
"float2 vertexpos = (%s * float3(point, 1)).xy;", viewMatrix); "float2 vertexpos = (%s * float3(point, 1)).xy;", viewMatrix);
vertexPos.set(kFloat2_GrSLType, "vertexpos"); vertexPos.set(kFloat2_GrSLType, "vertexpos");

View File

@ -203,7 +203,7 @@ static uint32_t get_ubo_aligned_offset(uint32_t* currentOffset,
} }
GrVkUniformHandler::~GrVkUniformHandler() { GrVkUniformHandler::~GrVkUniformHandler() {
for (UniformInfo& sampler : fSamplers.items()) { for (VkUniformInfo& sampler : fSamplers.items()) {
if (sampler.fImmutableSampler) { if (sampler.fImmutableSampler) {
sampler.fImmutableSampler->unref(); sampler.fImmutableSampler->unref();
sampler.fImmutableSampler = nullptr; sampler.fImmutableSampler = nullptr;
@ -212,12 +212,13 @@ GrVkUniformHandler::~GrVkUniformHandler() {
} }
GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray( GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
uint32_t visibility, const GrFragmentProcessor* owner,
GrSLType type, uint32_t visibility,
const char* name, GrSLType type,
bool mangleName, const char* name,
int arrayCount, bool mangleName,
const char** outName) { int arrayCount,
const char** outName) {
SkASSERT(name && strlen(name)); SkASSERT(name && strlen(name));
SkASSERT(GrSLTypeIsFloatType(type)); SkASSERT(GrSLTypeIsFloatType(type));
@ -238,10 +239,13 @@ GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
SkString layoutQualifier; SkString layoutQualifier;
layoutQualifier.appendf("offset=%d", offset); layoutQualifier.appendf("offset=%d", offset);
UniformInfo& uni = fUniforms.push_back(GrVkUniformHandler::UniformInfo{ VkUniformInfo& uni = fUniforms.push_back(VkUniformInfo{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount, {
std::move(layoutQualifier), SkString()}, GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
visibility, offset, nullptr std::move(layoutQualifier), SkString()},
visibility, owner, SkString(name)
},
offset, nullptr
}); });
if (outName) { if (outName) {
@ -263,12 +267,15 @@ GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(
SkString layoutQualifier; SkString layoutQualifier;
layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count()); layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count());
UniformInfo& info = fSamplers.push_back(GrVkUniformHandler::UniformInfo{ VkUniformInfo& info = fSamplers.push_back(VkUniformInfo{
GrShaderVar{std::move(mangleName), {
GrSLCombinedSamplerTypeForTextureType(backendFormat.textureType()), GrShaderVar{std::move(mangleName),
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray, GrSLCombinedSamplerTypeForTextureType(backendFormat.textureType()),
std::move(layoutQualifier), SkString()}, GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
kFragment_GrShaderFlag, 0, nullptr std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag, nullptr, SkString(name)
},
0, nullptr
}); });
// Check if we are dealing with an external texture and store the needed information if so. // Check if we are dealing with an external texture and store the needed information if so.
@ -287,7 +294,7 @@ GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(
} }
void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const { void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
for (const UniformInfo& sampler : fSamplers.items()) { for (const VkUniformInfo& sampler : fSamplers.items()) {
SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType || SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType ||
sampler.fVariable.getType() == kTextureExternalSampler_GrSLType); sampler.fVariable.getType() == kTextureExternalSampler_GrSLType);
if (visibility == sampler.fVisibility) { if (visibility == sampler.fVisibility) {
@ -298,7 +305,7 @@ void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
#ifdef SK_DEBUG #ifdef SK_DEBUG
bool firstOffsetCheck = false; bool firstOffsetCheck = false;
for (const UniformInfo& localUniform : fUniforms.items()) { for (const VkUniformInfo& localUniform : fUniforms.items()) {
if (!firstOffsetCheck) { if (!firstOffsetCheck) {
// Check to make sure we are starting our offset at 0 so the offset qualifier we // Check to make sure we are starting our offset at 0 so the offset qualifier we
// set on each variable in the uniform block is valid. // set on each variable in the uniform block is valid.
@ -309,7 +316,7 @@ void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
#endif #endif
SkString uniformsString; SkString uniformsString;
for (const UniformInfo& localUniform : fUniforms.items()) { for (const VkUniformInfo& localUniform : fUniforms.items()) {
if (visibility & localUniform.fVisibility) { if (visibility & localUniform.fVisibility) {
if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) { if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString); localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);

View File

@ -33,15 +33,13 @@ public:
kUniformBinding = 0 kUniformBinding = 0
}; };
struct UniformInfo { struct VkUniformInfo : public UniformInfo {
GrShaderVar fVariable;
uint32_t fVisibility;
// fUBOffset is only valid if the GrSLType of the fVariable is not a sampler // fUBOffset is only valid if the GrSLType of the fVariable is not a sampler
uint32_t fUBOffset; uint32_t fUBOffset;
// fImmutableSampler is used for sampling an image with a ycbcr conversion. // fImmutableSampler is used for sampling an image with a ycbcr conversion.
const GrVkSampler* fImmutableSampler = nullptr; const GrVkSampler* fImmutableSampler = nullptr;
}; };
typedef GrTAllocator<UniformInfo> UniformInfoArray; typedef GrTAllocator<VkUniformInfo> UniformInfoArray;
~GrVkUniformHandler() override; ~GrVkUniformHandler() override;
@ -66,7 +64,8 @@ private:
, fCurrentUBOOffset(0) { , fCurrentUBOOffset(0) {
} }
UniformHandle internalAddUniformArray(uint32_t visibility, UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type, GrSLType type,
const char* name, const char* name,
bool mangleName, bool mangleName,
@ -96,11 +95,10 @@ private:
void appendUniformDecls(GrShaderFlags, SkString*) const override; void appendUniformDecls(GrShaderFlags, SkString*) const override;
const UniformInfo& getUniformInfo(UniformHandle u) const { const VkUniformInfo& getUniformInfo(UniformHandle u) const {
return fUniforms.item(u.toIndex()); return fUniforms.item(u.toIndex());
} }
UniformInfoArray fUniforms; UniformInfoArray fUniforms;
UniformInfoArray fSamplers; UniformInfoArray fSamplers;
SkTArray<GrSwizzle> fSamplerSwizzles; SkTArray<GrSwizzle> fSamplerSwizzles;

View File

@ -838,13 +838,13 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
SkString vCoords = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); SkString vCoords = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fBaseFrequencyUni = uniformHandler->addUniform(&pne, kFragment_GrShaderFlag, kHalf2_GrSLType,
"baseFrequency"); "baseFrequency");
const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequencyUni); const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequencyUni);
const char* stitchDataUni = nullptr; const char* stitchDataUni = nullptr;
if (pne.stitchTiles()) { if (pne.stitchTiles()) {
fStitchDataUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fStitchDataUni = uniformHandler->addUniform(&pne, kFragment_GrShaderFlag, kHalf2_GrSLType,
"stitchData"); "stitchData");
stitchDataUni = uniformHandler->getUniformCStr(fStitchDataUni); stitchDataUni = uniformHandler->getUniformCStr(fStitchDataUni);
} }
@ -1249,11 +1249,11 @@ void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) {
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
SkString vCoords = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); SkString vCoords = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, fBaseFrequencyUni = uniformHandler->addUniform(&pne, kFragment_GrShaderFlag, kHalf2_GrSLType,
"baseFrequency"); "baseFrequency");
const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequencyUni); const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequencyUni);
fZUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "z"); fZUni = uniformHandler->addUniform(&pne, kFragment_GrShaderFlag, kHalf_GrSLType, "z");
const char* zUni = uniformHandler->getUniformCStr(fZUni); const char* zUni = uniformHandler->getUniformCStr(fZUni);
// fade function // fade function

View File

@ -621,8 +621,8 @@ void CPPCodeGenerator::addUniform(const Variable& var) {
} }
const char* type = glsltype_string(fContext, var.fType); const char* type = glsltype_string(fContext, var.fType);
String name(var.fName); String name(var.fName);
this->writef(" %sVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, %s, " this->writef(" %sVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,"
"\"%s\");\n", HCodeGenerator::FieldName(name.c_str()).c_str(), type, " %s, \"%s\");\n", HCodeGenerator::FieldName(name.c_str()).c_str(), type,
name.c_str()); name.c_str());
if (var.fModifiers.fLayout.fWhen.fLength) { if (var.fModifiers.fLayout.fWhen.fLength) {
this->write(" }\n"); this->write(" }\n");

View File

@ -195,8 +195,8 @@ DEF_TEST(SkSLFPUniform, r) {
"static std::unique_ptr<GrFragmentProcessor> Make()" "static std::unique_ptr<GrFragmentProcessor> Make()"
}, },
{ {
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " "colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, "
"\"color\");", "kHalf4_GrSLType, \"color\");",
}); });
} }
@ -214,8 +214,8 @@ DEF_TEST(SkSLFPInUniform, r) {
"static std::unique_ptr<GrFragmentProcessor> Make(SkRect color) {", "static std::unique_ptr<GrFragmentProcessor> Make(SkRect color) {",
}, },
{ {
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " "colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, "
"\"color\");", "kHalf4_GrSLType, \"color\");",
"pdman.set4fv(colorVar, 1, reinterpret_cast<const float*>(&(_outer.color)));" "pdman.set4fv(colorVar, 1, reinterpret_cast<const float*>(&(_outer.color)));"
}); });
} }
@ -232,8 +232,8 @@ DEF_TEST(SkSLFPInUniformCType, r) {
"static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f color) {", "static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f color) {",
}, },
{ {
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " "colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, "
"\"color\");", "kHalf4_GrSLType, \"color\");",
"pdman.set4fv(colorVar, 1, (_outer.color).vec());" "pdman.set4fv(colorVar, 1, (_outer.color).vec());"
}); });
} }
@ -253,8 +253,8 @@ DEF_TEST(SkSLFPTrackedInUniform, r) {
}, },
{ {
"SkRect colorPrev = SkRect::MakeEmpty();", "SkRect colorPrev = SkRect::MakeEmpty();",
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " "colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, "
"\"color\");", "kHalf4_GrSLType, \"color\");",
"const SkRect& colorValue = _outer.color;", "const SkRect& colorValue = _outer.color;",
"if (colorPrev.isEmpty() || colorPrev != colorValue) {", "if (colorPrev.isEmpty() || colorPrev != colorValue) {",
"colorPrev = colorValue;", "colorPrev = colorValue;",
@ -275,8 +275,8 @@ DEF_TEST(SkSLFPNonInlinedInUniform, r) {
"static std::unique_ptr<GrFragmentProcessor> Make(SkPoint point) {", "static std::unique_ptr<GrFragmentProcessor> Make(SkPoint point) {",
}, },
{ {
"pointVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, " "pointVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, "
"\"point\");", "kHalf2_GrSLType, \"point\");",
"const SkPoint& pointValue = _outer.point;", "const SkPoint& pointValue = _outer.point;",
"pdman.set2f(pointVar, pointValue.fX, pointValue.fY);" "pdman.set2f(pointVar, pointValue.fX, pointValue.fY);"
}); });
@ -303,8 +303,8 @@ DEF_TEST(SkSLFPConditionalInUniform, r) {
"SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}", "SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}",
"auto test = _outer.test;", "auto test = _outer.test;",
"if (test) {", "if (test) {",
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " "colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, "
"\"color\");", "kHalf4_GrSLType, \"color\");",
"if (colorVar.isValid()) {", "if (colorVar.isValid()) {",
"const SkPMColor4f& colorValue = _outer.color;", "const SkPMColor4f& colorValue = _outer.color;",
"if (colorPrev != colorValue) {", "if (colorPrev != colorValue) {",