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>();
auto* uniforms = args.fUniformHandler;
fViewMatrixHandle =
uniforms->addUniform(kVertex_GrShaderFlag, kFloat3x3_GrSLType, "viewmatrix");
fViewMatrixHandle = uniforms->addUniform(nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType,
"viewmatrix");
auto* varyings = args.fVaryingHandler;
varyings->emitAttributes(proc);

View File

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

View File

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

View File

@ -566,7 +566,8 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
const GrDisplacementMapEffect& displacementMap = args.fFp.cast<GrDisplacementMapEffect>();
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* dColor = "dColor";
const char* cCoords = "cCoords";
@ -623,7 +624,8 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
}
fragBuilder->codeAppend("-half2(0.5));\t\t");
fGLDomain.sampleTexture(fragBuilder,
fGLDomain.sampleTexture(&displacementMap,
fragBuilder,
args.fUniformHandler,
args.fShaderCaps,
domain,

View File

@ -748,7 +748,7 @@ public:
* 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.
*/
void emitLightColorUniform(GrGLSLUniformHandler*);
void emitLightColorUniform(const GrFragmentProcessor*, GrGLSLUniformHandler*);
/**
* 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
* 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*,
const char* z) = 0;
virtual void emitLightColor(GrGLSLUniformHandler*,
virtual void emitLightColor(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*,
const char *surfaceToLight);
@ -788,7 +790,8 @@ class GrGLDistantLight : public GrGLLight {
public:
~GrGLDistantLight() 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:
typedef GrGLLight INHERITED;
@ -801,7 +804,8 @@ class GrGLPointLight : public GrGLLight {
public:
~GrGLPointLight() 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:
typedef GrGLLight INHERITED;
@ -814,8 +818,10 @@ class GrGLSpotLight : public GrGLLight {
public:
~GrGLSpotLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, const char* z) override;
void emitLightColor(GrGLSLUniformHandler*,
void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, const char* z) override;
void emitLightColor(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*,
const char *surfaceToLight) override;
@ -1550,7 +1556,8 @@ protected:
*/
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
virtual void emitLightFunc(GrGLSLUniformHandler*,
virtual void emitLightFunc(const GrFragmentProcessor*,
GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*,
SkString* funcName) = 0;
@ -1567,7 +1574,8 @@ private:
class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
public:
void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, SkString* funcName) override;
void emitLightFunc(const GrFragmentProcessor*, GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*,
SkString* funcName) override;
protected:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
@ -1582,7 +1590,8 @@ private:
class GrGLSpecularLightingEffect : public GrGLLightingEffect {
public:
void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, SkString* funcName) override;
void emitLightFunc(const GrFragmentProcessor*, GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*,
SkString* funcName) override;
protected:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
@ -1736,14 +1745,16 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
}
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
fImageIncrementUni = uniformHandler->addUniform(&le,
kFragment_GrShaderFlag,
kHalf2_GrSLType, "ImageIncrement");
fSurfaceScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
fSurfaceScaleUni = uniformHandler->addUniform(&le,
kFragment_GrShaderFlag,
kHalf_GrSLType, "SurfaceScale");
fLight->emitLightColorUniform(uniformHandler);
fLight->emitLightColorUniform(&le, uniformHandler);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString lightFunc;
this->emitLightFunc(uniformHandler, fragBuilder, &lightFunc);
this->emitLightFunc(&le, uniformHandler, fragBuilder, &lightFunc);
const GrShaderVar gSobelArgs[] = {
GrShaderVar("a", kHalf_GrSLType),
GrShaderVar("b", kHalf_GrSLType),
@ -1804,7 +1815,8 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
SkString temp;
temp.appendf("temp%d", index);
fragBuilder->codeAppendf("half4 %s;", temp.c_str());
fDomain.sampleTexture(fragBuilder,
fDomain.sampleTexture(&le,
fragBuilder,
args.fUniformHandler,
args.fShaderCaps,
le.domain(),
@ -1818,11 +1830,11 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppend("\t\thalf3 surfaceToLight = ");
SkString arg;
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->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
args.fOutputColor, lightFunc.c_str(), normalName.c_str(), surfScale);
fLight->emitLightColor(uniformHandler, fragBuilder, "surfaceToLight");
fLight->emitLightColor(&le, uniformHandler, fragBuilder, "surfaceToLight");
fragBuilder->codeAppend(");\n");
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,
SkString* funcName) {
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[] = {
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,
SkString* funcName) {
const char* ks;
const char* shininess;
fKSUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "KS", &ks);
fShininessUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
fKSUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType, "KS", &ks);
fShininessUni = uniformHandler->addUniform(owner,
kFragment_GrShaderFlag,
kHalf_GrSLType,
"Shininess",
&shininess);
@ -1988,11 +2003,14 @@ void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman
}
///////////////////////////////////////////////////////////////////////////////
void GrGLLight::emitLightColorUniform(GrGLSLUniformHandler* uniformHandler) {
fColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, "LightColor");
void GrGLLight::emitLightColorUniform(const GrFragmentProcessor* owner,
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,
const char *surfaceToLight) {
fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni()));
@ -2014,11 +2032,12 @@ void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformNormal3(pdman, fDirectionUni, distantLight->direction());
}
void GrGLDistantLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler,
void GrGLDistantLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder,
const char* z) {
const char* dir;
fDirectionUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType,
fDirectionUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightDirection", &dir);
fragBuilder->codeAppend(dir);
}
@ -2033,11 +2052,12 @@ void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformPoint3(pdman, fLocationUni, pointLight->location());
}
void GrGLPointLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler,
void GrGLPointLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder,
const char* z) {
const char* loc;
fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType,
fLocationUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightLocation", &loc);
fragBuilder->codeAppendf("normalize(%s - half3(sk_FragCoord.xy, %s))",
loc, z);
@ -2058,18 +2078,20 @@ void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformNormal3(pdman, fSUni, spotLight->s());
}
void GrGLSpotLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler,
void GrGLSpotLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder,
const char* z) {
const char* location;
fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType,
fLocationUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightLocation", &location);
fragBuilder->codeAppendf("normalize(%s - half3(sk_FragCoord.xy, %s))",
location, z);
}
void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler,
void GrGLSpotLight::emitLightColor(const GrFragmentProcessor* owner,
GrGLSLUniformHandler* uniformHandler,
GrGLSLFPFragmentBuilder* fragBuilder,
const char *surfaceToLight) {
@ -2080,15 +2102,17 @@ void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler,
const char* cosOuter;
const char* coneScale;
const char* s;
fExponentUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
fExponentUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType,
"Exponent", &exponent);
fCosInnerConeAngleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"CosInnerConeAngle", &cosInner);
fCosOuterConeAngleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"CosOuterConeAngle", &cosOuter);
fConeScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
fCosInnerConeAngleUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag,
kHalf_GrSLType, "CosInnerConeAngle",
&cosInner);
fCosOuterConeAngleUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag,
kHalf_GrSLType, "CosOuterConeAngle",
&cosOuter);
fConeScaleUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType,
"ConeScale", &coneScale);
fSUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType, "S", &s);
fSUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType, "S", &s);
const GrShaderVar gLightColorArgs[] = {
GrShaderVar("surfaceToLight", kHalf3_GrSLType)

View File

@ -285,9 +285,10 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) {
const GrMorphologyEffect& me = args.fFp.cast<GrMorphologyEffect>();
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);
fRangeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloat2_GrSLType, "Range");
fRangeUni = uniformHandler->addUniform(&me, kFragment_GrShaderFlag, kFloat2_GrSLType, "Range");
const char* range = uniformHandler->getUniformCStr(fRangeUni);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,12 +20,10 @@ public:
const GrShaderVar& getUniformVariable(UniformHandle u) const override;
const char* getUniformCStr(UniformHandle u) const override;
struct UniformInfo {
GrShaderVar fVar;
int fUBOOffset;
int fVisibility;
struct DawnUniformInfo : public UniformInfo {
int fUBOOffset;
};
typedef GrTAllocator<UniformInfo> UniformInfoArray;
typedef GrTAllocator<DawnUniformInfo> UniformInfoArray;
enum {
kUniformBinding = 0,
};
@ -39,18 +37,20 @@ private:
const char* samplerVariable(SamplerHandle handle) const override;
GrSwizzle samplerSwizzle(SamplerHandle handle) const override;
void appendUniformDecls(GrShaderFlags visibility, SkString*) const override;
UniformHandle internalAddUniformArray(uint32_t visibility,
UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,
int arrayCount,
const char** outName) override;
UniformInfoArray fUniforms;
UniformInfoArray fSamplers;
UniformInfoArray fTextures;
SkTArray<GrSwizzle> fSamplerSwizzles;
SkTArray<SkString> fSamplerReferences;
UniformInfoArray fUniforms;
UniformInfoArray fSamplers;
UniformInfoArray fTextures;
SkTArray<GrSwizzle> fSamplerSwizzles;
SkTArray<SkString> fSamplerReferences;
uint32_t fCurrentUBOOffset = 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?
if (gp.coverageScale() != 0xff) {
const char* coverageScale;
fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
fCoverageScaleUniform = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kFloat_GrSLType,
"Coverage",
&coverageScale);
@ -393,7 +394,8 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
if (0xff != gp.coverageScale()) {
const char* coverageScale;
fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
fCoverageScaleUniform = uniformHandler->addUniform(nullptr,
kFragment_GrShaderFlag,
kHalf_GrSLType,
"Coverage",
&coverageScale);

View File

@ -33,8 +33,8 @@ public:
varyingHandler->emitAttributes(btgp);
const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat2_GrSLType, "AtlasSizeInv", &atlasDimensionsInvName);
fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr, kVertex_GrShaderFlag,
kFloat2_GrSLType, "AtlasSizeInv", &atlasDimensionsInvName);
GrGLSLVarying uv(kFloat2_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 char *edgeArrayName;
fEdgeUniform = args.fUniformHandler->addUniformArray(kFragment_GrShaderFlag,
fEdgeUniform = args.fUniformHandler->addUniformArray(&cpe,
kFragment_GrShaderFlag,
kHalf3_GrSLType,
"edges",
cpe.getEdgeCount(),

View File

@ -38,7 +38,8 @@ public:
varyingHandler->emitAttributes(dfTexEffect);
const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag,
fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat2_GrSLType,
"AtlasDimensionsInv",
&atlasDimensionsInvName);
@ -46,8 +47,9 @@ public:
// adjust based on gamma
const char* distanceAdjustUniName = nullptr;
// width, height, 1/(3*width)
fDistanceAdjustUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"DistanceAdjust", &distanceAdjustUniName);
fDistanceAdjustUni = uniformHandler->addUniform(nullptr, kFragment_GrShaderFlag,
kHalf_GrSLType, "DistanceAdjust",
&distanceAdjustUniName);
#endif
// Setup pass through color
@ -334,7 +336,8 @@ public:
varyingHandler->emitAttributes(dfPathEffect);
const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag,
fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat2_GrSLType,
"AtlasDimensionsInv",
&atlasDimensionsInvName);
@ -618,7 +621,8 @@ public:
varyingHandler->emitAttributes(dfTexEffect);
const char* atlasDimensionsInvName;
fAtlasDimensionsInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag,
fAtlasDimensionsInvUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat2_GrSLType,
"AtlasDimensionsInv",
&atlasDimensionsInvName);
@ -722,8 +726,9 @@ public:
// adjust width based on gamma
const char* distanceAdjustUniName = nullptr;
fDistanceAdjustUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf3_GrSLType,
"DistanceAdjust", &distanceAdjustUniName);
fDistanceAdjustUni = uniformHandler->addUniform(nullptr, kFragment_GrShaderFlag,
kHalf3_GrSLType, "DistanceAdjust",
&distanceAdjustUniName);
fragBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName);
// 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>();
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType,
fImageIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
"ImageIncrement");
if (ce.useBounds()) {
fBoundsUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType,
fBoundsUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
"Bounds");
}
@ -52,7 +52,7 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
int arrayCount = (width + 3) / 4;
SkASSERT(4 * arrayCount >= width);
fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, kHalf4_GrSLType,
fKernelUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, kHalf4_GrSLType,
"Kernel", arrayCount);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;

View File

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

View File

@ -607,8 +607,8 @@ public:
private:
void emitOutputsForBlendState(const EmitArgs& args) override {
const char* alpha;
fAlphaUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"alpha", &alpha);
fAlphaUniform = args.fUniformHandler->addUniform(nullptr, kFragment_GrShaderFlag,
kHalf_GrSLType, "alpha", &alpha);
GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
// 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

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

View File

@ -79,7 +79,8 @@ public:
const GrSkSLFP& fp = args.fFp.cast<GrSkSLFP>();
for (const auto& v : fp.fEffect->inputs()) {
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.fName.c_str(),
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* outColor,
const SkString& inCoords,
@ -95,11 +96,12 @@ void GrTextureDomain::GLDomain::sampleProcessor(const GrTextureDomain& textureDo
auto appendProcessorSample = [parent, &args, childIndex, inColor](const char* 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);
}
void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
void GrTextureDomain::GLDomain::sampleTexture(const GrFragmentProcessor* owner,
GrGLSLShaderBuilder* builder,
GrGLSLUniformHandler* uniformHandler,
const GrShaderCaps* shaderCaps,
const GrTextureDomain& textureDomain,
@ -114,10 +116,12 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
builder->codeAppend(";");
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,
const GrTextureDomain& textureDomain,
const char* outColor,
@ -136,7 +140,7 @@ void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder,
if (textureDomain.fIndex >= 0) {
uniName.appendS32(textureDomain.fIndex);
}
fDomainUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
fDomainUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf4_GrSLType,
uniName.c_str(), &name);
fDomainName = name;
}
@ -150,7 +154,7 @@ void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder,
uniName.appendS32(textureDomain.fIndex);
}
// 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);
fDecalName = name;
}

View File

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

View File

@ -275,7 +275,7 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
if (te.fShaderModes[0] == ShaderMode::kClampToBorder ||
te.fShaderModes[1] == ShaderMode::kClampToBorder) {
fBorderUni = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "border", &borderName);
&te, kFragment_GrShaderFlag, kHalf4_GrSLType, "border", &borderName);
}
auto modeUsesSubset = [](ShaderMode m) {
return m == ShaderMode::kRepeat || m == ShaderMode::kMirrorRepeat ||
@ -293,13 +293,13 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
const char* subsetName = nullptr;
if (useSubset[0] || useSubset[1]) {
fSubsetUni = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "subset", &subsetName);
&te, kFragment_GrShaderFlag, kFloat4_GrSLType, "subset", &subsetName);
}
const char* clampName = nullptr;
if (useClamp[0] || useClamp[1]) {
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
@ -310,7 +310,7 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
filterLogic[1] != FilterLogic::kNone)) {
// TODO: Detect support for textureSize() or polyfill textureSize() in SkSL and
// always use?
fNormUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
fNormUni = args.fUniformHandler->addUniform(&te, kFragment_GrShaderFlag,
kFloat4_GrSLType, "norm", &norm);
// TODO: Remove the normalization from the CoordTransform to skip unnormalizing
// 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());
if (kIdentity_SkYUVColorSpace != yuvEffect.fYUVColorSpace) {
fColorSpaceMatrixVar = args.fUniformHandler->addUniform(
fColorSpaceMatrixVar = args.fUniformHandler->addUniform(&yuvEffect,
kFragment_GrShaderFlag, kHalf3x3_GrSLType, "colorSpaceMatrix");
fColorSpaceTranslateVar = args.fUniformHandler->addUniform(
fColorSpaceTranslateVar = args.fUniformHandler->addUniform(&yuvEffect,
kFragment_GrShaderFlag, kHalf3_GrSLType, "colorSpaceTranslate");
fragBuilder->codeAppendf(
"color.rgb = saturate(color.rgb * %s + %s);",

View File

@ -29,7 +29,7 @@ public:
(void)rect;
prevRect = float4(-1.0);
rectUniformVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "rectUniform");
&_outer, kFragment_GrShaderFlag, kFloat4_GrSLType, "rectUniform");
fragBuilder->codeAppendf(
"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, "

View File

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

View File

@ -286,8 +286,8 @@ public:
(void)textureRadius;
auto solidRadius = _outer.solidRadius;
(void)solidRadius;
circleDataVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
"circleData");
circleDataVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "circleData");
fragBuilder->codeAppendf(
"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) + "

View File

@ -30,8 +30,8 @@ public:
auto radius = _outer.radius;
(void)radius;
prevRadius = -1.0;
circleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"circle");
circleVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "circle");
fragBuilder->codeAppendf(
"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 "

View File

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

View File

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

View File

@ -27,8 +27,8 @@ public:
(void)color;
auto mode = _outer.mode;
(void)mode;
colorVar =
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "color");
colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "color");
fragBuilder->codeAppendf(
"@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 "

View File

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

View File

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

View File

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

View File

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

View File

@ -68,12 +68,12 @@ public:
(void)rect;
auto cornerRadius = _outer.cornerRadius;
(void)cornerRadius;
cornerRadiusVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"cornerRadius");
proxyRectVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"proxyRect");
blurRadiusVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"blurRadius");
cornerRadiusVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf_GrSLType, "cornerRadius");
proxyRectVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "proxyRect");
blurRadiusVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf_GrSLType, "blurRadius");
fragBuilder->codeAppendf(
"\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 "

View File

@ -33,15 +33,15 @@ public:
abs(rect.right()) > 16000.0) ||
abs(rect.bottom()) > 16000.0;
if (highp) {
rectFVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"rectF");
rectFVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "rectF");
}
if (!highp) {
rectHVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
"rectH");
rectHVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "rectH");
}
invSixSigmaVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"invSixSigma");
invSixSigmaVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf_GrSLType, "invSixSigma");
fragBuilder->codeAppendf(
"/* 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), "

View File

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

View File

@ -12,6 +12,7 @@
#include "src/gpu/GrShaderVar.h"
#include "src/gpu/GrTAllocator.h"
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/glsl/GrGLSLUniformHandler.h"
#include "include/private/SkTArray.h"
@ -25,22 +26,20 @@ class GrGLProgram;
*/
class GrGLProgramDataManager : public GrGLSLProgramDataManager {
public:
struct UniformInfo {
GrShaderVar fVariable;
uint32_t fVisibility;
GrGLint fLocation;
struct GLUniformInfo : public GrGLSLUniformHandler::UniformInfo {
GrGLint fLocation;
};
struct VaryingInfo {
GrShaderVar fVariable;
GrGLint fLocation;
GrGLint fLocation;
};
// 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
// name strings. Otherwise, we'd have to hand out copies.
typedef GrTAllocator<UniformInfo> UniformInfoArray;
typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
typedef GrTAllocator<GLUniformInfo> UniformInfoArray;
typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
const VaryingInfoArray&);

View File

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

View File

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

View File

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

View File

@ -97,7 +97,8 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb,
uni.fType = kFloat3x3_GrSLType;
}
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);
} else {
// 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);
} else {
const char* viewMatrixName;
*viewMatrixUniform = uniformHandler->addUniform(kVertex_GrShaderFlag,
*viewMatrixUniform = uniformHandler->addUniform(nullptr,
kVertex_GrShaderFlag,
kFloat3x3_GrSLType,
"uViewM",
&viewMatrixName);

View File

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

View File

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

View File

@ -31,6 +31,13 @@ struct GrGLSLBuiltinUniformHandles {
class GrGLSLUniformHandler {
public:
struct UniformInfo {
GrShaderVar fVariable;
uint32_t fVisibility;
const GrFragmentProcessor* fOwner;
SkString fRawName;
};
virtual ~GrGLSLUniformHandler() {}
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
then it will refer to the final uniform name after return. Use the addUniformArray variant
to add an array of uniforms. */
UniformHandle addUniform(uint32_t visibility,
UniformHandle addUniform(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type,
const char* name,
const char** outName = nullptr) {
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,
const char* name,
int arrayCount,
const char** outName = nullptr) {
SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
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;
@ -82,7 +92,8 @@ private:
virtual SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&,
const char* name, const GrShaderCaps*) = 0;
virtual UniformHandle internalAddUniformArray(uint32_t visibility,
virtual UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,

View File

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

View File

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

View File

@ -34,16 +34,16 @@ public:
(void)bias23;
auto threshold = _outer.threshold;
(void)threshold;
scale01Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale01");
bias01Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias01");
scale23Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale23");
bias23Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias23");
thresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"threshold");
scale01Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale01");
bias01Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias01");
scale23Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale23");
bias23Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias23");
thresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf_GrSLType, "threshold");
fragBuilder->codeAppendf(
"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 + "

View File

@ -28,9 +28,10 @@ public:
(void)start;
auto end = _outer.end;
(void)end;
startVar =
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "start");
endVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "end");
startVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "start");
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",
args.fInputColor, args.fOutputColor,
args.fUniformHandler->getUniformCStr(startVar),

View File

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

View File

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

View File

@ -62,69 +62,69 @@ public:
(void)thresholds1_7;
auto thresholds9_13 = _outer.thresholds9_13;
(void)thresholds9_13;
scale0_1Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale0_1");
scale0_1Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale0_1");
if (intervalCount > 1) {
scale2_3Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale2_3");
scale2_3Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale2_3");
}
if (intervalCount > 2) {
scale4_5Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale4_5");
scale4_5Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale4_5");
}
if (intervalCount > 3) {
scale6_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale6_7");
scale6_7Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale6_7");
}
if (intervalCount > 4) {
scale8_9Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale8_9");
scale8_9Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale8_9");
}
if (intervalCount > 5) {
scale10_11Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
scale10_11Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale10_11");
}
if (intervalCount > 6) {
scale12_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
scale12_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale12_13");
}
if (intervalCount > 7) {
scale14_15Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
scale14_15Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale14_15");
}
bias0_1Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias0_1");
bias0_1Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias0_1");
if (intervalCount > 1) {
bias2_3Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias2_3");
bias2_3Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias2_3");
}
if (intervalCount > 2) {
bias4_5Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias4_5");
bias4_5Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias4_5");
}
if (intervalCount > 3) {
bias6_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias6_7");
bias6_7Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias6_7");
}
if (intervalCount > 4) {
bias8_9Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias8_9");
bias8_9Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias8_9");
}
if (intervalCount > 5) {
bias10_11Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
bias10_11Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias10_11");
}
if (intervalCount > 6) {
bias12_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
bias12_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias12_13");
}
if (intervalCount > 7) {
bias14_15Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
bias14_15Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias14_15");
}
thresholds1_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
"thresholds1_7");
thresholds9_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
thresholds1_7Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "thresholds1_7");
thresholds9_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "thresholds9_13");
fragBuilder->codeAppendf(
"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/glsl/GrGLSLUniformHandler.h"
#include <vector>
// 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
// 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
struct UniformInfo {
GrShaderVar fVariable;
uint32_t fVisibility;
uint32_t fUBOffset;
struct MtlUniformInfo : public UniformInfo {
uint32_t fUBOffset;
};
typedef GrTAllocator<UniformInfo> UniformInfoArray;
typedef GrTAllocator<MtlUniformInfo> UniformInfoArray;
const GrShaderVar& getUniformVariable(UniformHandle u) const override {
return fUniforms.item(u.toIndex()).fVariable;
@ -50,7 +50,8 @@ private:
, fCurrentUBOMaxAlignment(0x0) {
}
UniformHandle internalAddUniformArray(uint32_t visibility,
UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,

View File

@ -200,12 +200,13 @@ static uint32_t get_ubo_aligned_offset(uint32_t* currentOffset,
}
GrGLSLUniformHandler::UniformHandle GrMtlUniformHandler::internalAddUniformArray(
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,
int arrayCount,
const char** outName) {
const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,
int arrayCount,
const char** outName) {
SkASSERT(name && strlen(name));
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
// we set the modifier to none for all uniforms declared inside the block.
UniformInfo& uni = fUniforms.push_back(GrMtlUniformHandler::UniformInfo{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag | kVertex_GrShaderFlag, offset
UniformInfo& uni = fUniforms.push_back(MtlUniformInfo{
{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag | kVertex_GrShaderFlag, owner, SkString(name)
},
offset
});
if (outName) {
@ -257,11 +261,14 @@ GrGLSLUniformHandler::SamplerHandle GrMtlUniformHandler::addSampler(
SkString layoutQualifier;
layoutQualifier.appendf("binding=%d", binding);
fSamplers.push_back(GrMtlUniformHandler::UniformInfo{
GrShaderVar{std::move(mangleName), GrSLCombinedSamplerTypeForTextureType(type),
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag, 0
fSamplers.push_back(MtlUniformInfo{
{
GrShaderVar{std::move(mangleName), GrSLCombinedSamplerTypeForTextureType(type),
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag, nullptr, SkString(name)
},
0
});
SkASSERT(caps->textureSwizzleAppliedInShader());
@ -281,7 +288,7 @@ void GrMtlUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
#ifdef SK_DEBUG
bool firstOffsetCheck = false;
for (const UniformInfo& localUniform : fUniforms.items()) {
for (const MtlUniformInfo& localUniform : fUniforms.items()) {
if (!firstOffsetCheck) {
// 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.

View File

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

View File

@ -19,7 +19,7 @@ public:
const char* viewMatrix;
fViewMatrixUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
args.fVaryingHandler->emitAttributes(shader);
@ -34,7 +34,7 @@ public:
const char* color;
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 = half4(1);", args.fOutputCoverage);
@ -120,7 +120,7 @@ void GrFillBoundingBoxShader::emitVertexCode(Impl* impl, GrGLSLVertexBuilder* v,
GrGLSLUniformHandler* uniformHandler) const {
const char* pathBounds;
impl->fPathBoundsUniform = uniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat4_GrSLType, "path_bounds", &pathBounds);
nullptr, kVertex_GrShaderFlag, kFloat4_GrSLType, "path_bounds", &pathBounds);
v->codeAppendf(R"(
// 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()) {
const char* viewMatrix;
fViewMatrixUniform = args.fUniformHandler->addUniform(
kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
args.fVertBuilder->codeAppendf(
"float2 vertexpos = (%s * float3(point, 1)).xy;", viewMatrix);
vertexPos.set(kFloat2_GrSLType, "vertexpos");

View File

@ -203,7 +203,7 @@ static uint32_t get_ubo_aligned_offset(uint32_t* currentOffset,
}
GrVkUniformHandler::~GrVkUniformHandler() {
for (UniformInfo& sampler : fSamplers.items()) {
for (VkUniformInfo& sampler : fSamplers.items()) {
if (sampler.fImmutableSampler) {
sampler.fImmutableSampler->unref();
sampler.fImmutableSampler = nullptr;
@ -212,12 +212,13 @@ GrVkUniformHandler::~GrVkUniformHandler() {
}
GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,
int arrayCount,
const char** outName) {
const GrFragmentProcessor* owner,
uint32_t visibility,
GrSLType type,
const char* name,
bool mangleName,
int arrayCount,
const char** outName) {
SkASSERT(name && strlen(name));
SkASSERT(GrSLTypeIsFloatType(type));
@ -238,10 +239,13 @@ GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
SkString layoutQualifier;
layoutQualifier.appendf("offset=%d", offset);
UniformInfo& uni = fUniforms.push_back(GrVkUniformHandler::UniformInfo{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
std::move(layoutQualifier), SkString()},
visibility, offset, nullptr
VkUniformInfo& uni = fUniforms.push_back(VkUniformInfo{
{
GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::None, arrayCount,
std::move(layoutQualifier), SkString()},
visibility, owner, SkString(name)
},
offset, nullptr
});
if (outName) {
@ -263,12 +267,15 @@ GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(
SkString layoutQualifier;
layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count());
UniformInfo& info = fSamplers.push_back(GrVkUniformHandler::UniformInfo{
GrShaderVar{std::move(mangleName),
GrSLCombinedSamplerTypeForTextureType(backendFormat.textureType()),
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
std::move(layoutQualifier), SkString()},
kFragment_GrShaderFlag, 0, nullptr
VkUniformInfo& info = fSamplers.push_back(VkUniformInfo{
{
GrShaderVar{std::move(mangleName),
GrSLCombinedSamplerTypeForTextureType(backendFormat.textureType()),
GrShaderVar::TypeModifier::Uniform, GrShaderVar::kNonArray,
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.
@ -287,7 +294,7 @@ GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(
}
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 ||
sampler.fVariable.getType() == kTextureExternalSampler_GrSLType);
if (visibility == sampler.fVisibility) {
@ -298,7 +305,7 @@ void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
#ifdef SK_DEBUG
bool firstOffsetCheck = false;
for (const UniformInfo& localUniform : fUniforms.items()) {
for (const VkUniformInfo& localUniform : fUniforms.items()) {
if (!firstOffsetCheck) {
// 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.
@ -309,7 +316,7 @@ void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
#endif
SkString uniformsString;
for (const UniformInfo& localUniform : fUniforms.items()) {
for (const VkUniformInfo& localUniform : fUniforms.items()) {
if (visibility & localUniform.fVisibility) {
if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);

View File

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

View File

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

View File

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

View File

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