Move glsl onto EmitArgs struct for emitCode

BUG=skia:

Review URL: https://codereview.chromium.org/1453623003
This commit is contained in:
egdaniel 2015-11-19 07:23:45 -08:00 committed by Commit bot
parent c0604609ce
commit a2e3e0f7f8
20 changed files with 90 additions and 28 deletions

View File

@ -724,8 +724,7 @@ void GrGLRectBlurEffect::emitCode(EmitArgs& args) {
const char *rectName;
const char *profileSizeName;
const char* precisionString = GrGLSLShaderVar::PrecisionString(args.fBuilder->glslCaps(),
fPrecision);
const char* precisionString = GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, fPrecision);
fProxyRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
fPrecision,

View File

@ -608,7 +608,11 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
}
fragBuilder->codeAppend("-vec2(0.5));\t\t");
fGLDomain.sampleTexture(fragBuilder, domain, args.fOutputColor, SkString(cCoords),
fGLDomain.sampleTexture(fragBuilder,
args.fGLSLCaps,
domain,
args.fOutputColor,
SkString(cCoords),
args.fSamplers[1]);
fragBuilder->codeAppend(";\n");
}

View File

@ -1028,6 +1028,7 @@ uint32_t GrGLGradientEffect::GenBaseGradientKey(const GrProcessor& processor) {
void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder,
GrGLSLFragmentBuilder* fragBuilder,
const GrGLSLCaps* glslCaps,
const GrGradientEffect& ge,
const char* gradientTValue,
const char* outputColor,
@ -1042,7 +1043,8 @@ void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder,
// considerations:
// The gradient SkShader reporting opaque is more restrictive than necessary in the two pt
// case. Make sure the key reflects this optimization (and note that it can use the same
// shader as thekBeforeIterp case). This same optimization applies to the 3 color case below.
// shader as thekBeforeIterp case). This same optimization applies to the 3 color case
// below.
if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
}
@ -1054,7 +1056,7 @@ void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder,
gradientTValue);
fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
builder->getUniformVariable(fColorStartUni).c_str());
if (!builder->glslCaps()->canUseMinAndAbsTogether()) {
if (!glslCaps->canUseMinAndAbsTogether()) {
// The Tegra3 compiler will sometimes never return if we have
// min(abs(oneMinus2t), 1.0), or do the abs first in a separate expression.
fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n");

View File

@ -427,6 +427,7 @@ protected:
// native GLSL mix), and 4+ color gradients that use the traditional texture lookup.
void emitColor(GrGLSLFPBuilder* builder,
GrGLSLFragmentBuilder* fragBuilder,
const GrGLSLCaps* caps,
const GrGradientEffect&,
const char* gradientTValue,
const char* outputColor,

View File

@ -608,6 +608,7 @@ void GrGLLinearGradient::emitCode(EmitArgs& args) {
t.append(".x");
this->emitColor(args.fBuilder,
args.fFragBuilder,
args.fGLSLCaps,
ge, t.c_str(),
args.fOutputColor,
args.fInputColor,

View File

@ -505,6 +505,7 @@ void GrGLRadialGradient::emitCode(EmitArgs& args) {
t.append(")");
this->emitColor(args.fBuilder,
args.fFragBuilder,
args.fGLSLCaps,
ge, t.c_str(),
args.fOutputColor,
args.fInputColor,

View File

@ -253,7 +253,7 @@ void GrGLSweepGradient::emitCode(EmitArgs& args) {
// 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi]
// On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int
// thus must us -1.0 * %s.x to work correctly
if (args.fBuilder->glslCaps()->mustForceNegatedAtanParamToFloat()){
if (args.fGLSLCaps->mustForceNegatedAtanParamToFloat()){
t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5",
coords2D.c_str(), coords2D.c_str());
} else {
@ -262,6 +262,7 @@ void GrGLSweepGradient::emitCode(EmitArgs& args) {
}
this->emitColor(args.fBuilder,
args.fFragBuilder,
args.fGLSLCaps,
ge, t.c_str(),
args.fOutputColor,
args.fInputColor,

View File

@ -272,6 +272,7 @@ void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppend("\t");
this->emitColor(args.fBuilder,
fragBuilder,
args.fGLSLCaps,
ge,
tName.c_str(),
args.fOutputColor,
@ -544,6 +545,7 @@ void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppend("\t\t");
this->emitColor(args.fBuilder,
fragBuilder,
args.fGLSLCaps,
ge,
tName.c_str(),
args.fOutputColor,
@ -733,6 +735,7 @@ void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) {
this->emitColor(args.fBuilder,
fragBuilder,
args.fGLSLCaps,
ge,
tName.c_str(),
args.fOutputColor,
@ -998,6 +1001,7 @@ void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) {
this->emitColor(args.fBuilder,
fragBuilder,
args.fGLSLCaps,
ge,
tName.c_str(),
args.fOutputColor,
@ -1248,6 +1252,7 @@ void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppend("\t\t");
this->emitColor(args.fBuilder,
fragBuilder,
args.fGLSLCaps,
ge,
tName.c_str(),
args.fOutputColor,

View File

@ -97,7 +97,12 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) {
coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1);
SkString sampleVar;
sampleVar.printf("rowColors[%d]", x);
fDomain.sampleTexture(fragBuilder, domain, sampleVar.c_str(), coord, args.fSamplers[0]);
fDomain.sampleTexture(fragBuilder,
args.fGLSLCaps,
domain,
sampleVar.c_str(),
coord,
args.fSamplers[0]);
}
fragBuilder->codeAppendf(
"\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors[1], rowColors[2], rowColors[3]);\n",

View File

@ -28,7 +28,7 @@ public:
// Using highp for GLES here in order to avoid some precision issues on specific GPUs.
GrGLSLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecision);
SkString tmpDecl;
tmpVar.appendDecl(args.fBuilder->glslCaps(), &tmpDecl);
tmpVar.appendDecl(args.fGLSLCaps, &tmpDecl);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;

View File

@ -100,7 +100,7 @@ public:
dfTexEffect.inTextureCoords()->fName);
// Use highp to work around aliasing issues
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(),
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
kHigh_GrSLPrecision));
fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
@ -338,7 +338,7 @@ public:
"TextureSize", &textureSizeUniName);
// Use highp to work around aliasing issues
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(),
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
kHigh_GrSLPrecision));
fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn());
@ -350,7 +350,7 @@ public:
fragBuilder->codeAppend("float distance = "
SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");");
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(),
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
kHigh_GrSLPrecision));
fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
fragBuilder->codeAppend("float afwidth;");
@ -574,10 +574,10 @@ public:
// create LCD offset adjusted by inverse of transform
// Use highp to work around aliasing issues
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(),
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
kHigh_GrSLPrecision));
fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(),
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
kHigh_GrSLPrecision));
SkScalar lcdDelta = 1.0f / (3.0f * atlas->width());

View File

@ -76,7 +76,12 @@ void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppendf("float k = %s[%d * %d + %d];", kernel, y, kWidth, x);
SkString coord;
coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc);
fDomain.sampleTexture(fragBuilder, domain, "c", coord, args.fSamplers[0]);
fDomain.sampleTexture(fragBuilder,
args.fGLSLCaps,
domain,
"c",
coord,
args.fSamplers[0]);
if (!fConvolveAlpha) {
fragBuilder->codeAppend("c.rgb /= c.a;");
fragBuilder->codeAppend("c.rgb = clamp(c.rgb, 0.0, 1.0);");
@ -89,7 +94,12 @@ 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, domain, "c", coords2D, args.fSamplers[0]);
fDomain.sampleTexture(fragBuilder,
args.fGLSLCaps,
domain,
"c",
coords2D,
args.fSamplers[0]);
fragBuilder->codeAppendf("%s.a = c.a;", args.fOutputColor);
fragBuilder->codeAppendf("%s.rgb = sum.rgb * %s + %s;", args.fOutputColor, gain, bias);
fragBuilder->codeAppendf("%s.rgb *= %s.a;", args.fOutputColor, args.fOutputColor);

View File

@ -42,6 +42,7 @@ GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index)
//////////////////////////////////////////////////////////////////////////////
void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
const GrGLSLCaps* glslCaps,
const GrTextureDomain& textureDomain,
const char* outColor,
const SkString& inCoords,
@ -88,7 +89,7 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
GrGLSLShaderBuilder::ShaderBlock block(builder);
const char* domain = fDomainName.c_str();
if (!program->glslCaps()->canUseAnyFunctionInShader()) {
if (!glslCaps->canUseAnyFunctionInShader()) {
// On the NexusS and GalaxyNexus, the other path (with the 'any'
// call) causes the compilation error "Calls to any function that
// may require a gradient calculation inside a conditional block
@ -101,10 +102,10 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
inCoords.c_str());
builder->codeAppend(";");
builder->codeAppend(GrGLSLShaderVar::PrecisionString(program->glslCaps(),
builder->codeAppend(GrGLSLShaderVar::PrecisionString(glslCaps,
kHigh_GrSLPrecision));
builder->codeAppendf("float x = (%s).x;", inCoords.c_str());
builder->codeAppend(GrGLSLShaderVar::PrecisionString(program->glslCaps(),
builder->codeAppend(GrGLSLShaderVar::PrecisionString(glslCaps,
kHigh_GrSLPrecision));
builder->codeAppendf("float y = (%s).y;", inCoords.c_str());
@ -197,7 +198,12 @@ void GrGLTextureDomainEffect::emitCode(EmitArgs& args) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
fGLDomain.sampleTexture(fragBuilder, domain, args.fOutputColor, coords2D, args.fSamplers[0],
fGLDomain.sampleTexture(fragBuilder,
args.fGLSLCaps,
domain,
args.fOutputColor,
coords2D,
args.fSamplers[0],
args.fInputColor);
}

View File

@ -114,6 +114,7 @@ public:
* expression before being written to outColor.
*/
void sampleTexture(GrGLSLShaderBuilder* builder,
const GrGLSLCaps* glslCaps,
const GrTextureDomain& textureDomain,
const char* outColor,
const SkString& inCoords,

View File

@ -261,6 +261,7 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentProcessor& fp,
GrGLSLFragmentProcessor::EmitArgs args(this,
&fFS,
this->glslCaps(),
fp,
outColor,
inColor,
@ -285,8 +286,16 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrPrimitiveProcessor& gp,
SkSTArray<4, GrGLSLTextureSampler> samplers(gp.numTextures());
this->emitSamplers(gp, &samplers, fGeometryProcessor);
GrGLSLGeometryProcessor::EmitArgs args(this, &fVS, &fFS, gp, outColor, outCoverage, samplers,
fCoordTransforms, &fOutCoords);
GrGLSLGeometryProcessor::EmitArgs args(this,
&fVS,
&fFS,
this->glslCaps(),
gp,
outColor,
outCoverage,
samplers,
fCoordTransforms,
&fOutCoords);
fGeometryProcessor->fGLProc->emitCode(args);
// We have to check that effects and the code they emit are consistent, ie if an effect
@ -321,9 +330,14 @@ void GrGLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
SkSTArray<4, GrGLSLTextureSampler> samplers(xp.numTextures());
this->emitSamplers(xp, &samplers, fXferProcessor);
GrGLSLXferProcessor::EmitArgs args(this, &fFS, xp, colorIn.c_str(), coverageIn.c_str(),
GrGLSLXferProcessor::EmitArgs args(this,
&fFS,
this->glslCaps(),
xp, colorIn.c_str(),
coverageIn.c_str(),
fFS.getPrimaryColorOutputName(),
fFS.getSecondaryColorOutputName(), samplers);
fFS.getSecondaryColorOutputName(),
samplers);
fXferProcessor->fGLProc->emitCode(args);
// We have to check that effects and the code they emit are consistent, ie if an effect

View File

@ -95,6 +95,7 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu
fragBuilder->getMangleString().c_str(), childProc.name());
EmitArgs childArgs(args.fBuilder,
fragBuilder,
args.fGLSLCaps,
childProc,
outputColor,
inputColor,

View File

@ -53,6 +53,7 @@ public:
struct EmitArgs {
EmitArgs(GrGLSLFPBuilder* builder,
GrGLSLFragmentBuilder* fragBuilder,
const GrGLSLCaps* caps,
const GrFragmentProcessor& fp,
const char* outputColor,
const char* inputColor,
@ -60,6 +61,7 @@ public:
const TextureSamplerArray& samplers)
: fBuilder(builder)
, fFragBuilder(fragBuilder)
, fGLSLCaps(caps)
, fFp(fp)
, fOutputColor(outputColor)
, fInputColor(inputColor)
@ -67,6 +69,7 @@ public:
, fSamplers(samplers) {}
GrGLSLFPBuilder* fBuilder;
GrGLSLFragmentBuilder* fFragBuilder;
const GrGLSLCaps* fGLSLCaps;
const GrFragmentProcessor& fFp;
const char* fOutputColor;
const char* fInputColor;

View File

@ -15,9 +15,10 @@
class GrBatchTracker;
class GrPrimitiveProcessor;
class GrGLSLVertexBuilder;
class GrGLSLCaps;
class GrGLSLFragmentBuilder;
class GrGLSLGPBuilder;
class GrGLSLVertexBuilder;
class GrGLSLPrimitiveProcessor {
public:
@ -34,6 +35,7 @@ public:
EmitArgs(GrGLSLGPBuilder* pb,
GrGLSLVertexBuilder* vertBuilder,
GrGLSLFragmentBuilder* fragBuilder,
const GrGLSLCaps* caps,
const GrPrimitiveProcessor& gp,
const char* outputColor,
const char* outputCoverage,
@ -43,6 +45,7 @@ public:
: fPB(pb)
, fVertBuilder(vertBuilder)
, fFragBuilder(fragBuilder)
, fGLSLCaps(caps)
, fGP(gp)
, fOutputColor(outputColor)
, fOutputCoverage(outputCoverage)
@ -52,6 +55,7 @@ public:
GrGLSLGPBuilder* fPB;
GrGLSLVertexBuilder* fVertBuilder;
GrGLSLFragmentBuilder* fFragBuilder;
const GrGLSLCaps* fGLSLCaps;
const GrPrimitiveProcessor& fGP;
const char* fOutputColor;
const char* fOutputCoverage;

View File

@ -65,8 +65,6 @@ public:
*/
virtual const char* getUniformCStr(UniformHandle u) const = 0;
virtual const GrGLSLCaps* glslCaps() const = 0;
/*
* *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
*/
@ -193,6 +191,8 @@ class GrGLSLProgramBuilder : public GrGLSLGPBuilder,
public:
typedef GrGpu::DrawArgs DrawArgs;
virtual const GrGLSLCaps* glslCaps() const = 0;
// Handles for program uniforms (other than per-effect uniforms)
struct BuiltinUniformHandles {
UniformHandle fRTAdjustmentUni;

View File

@ -11,9 +11,10 @@
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLTextureSampler.h"
class GrGLSLXPFragmentBuilder;
class GrGLSLXPBuilder;
class GrXferProcessor;
class GrGLSLXPBuilder;
class GrGLSLXPFragmentBuilder;
class GrGLSLCaps;
class GrGLSLXferProcessor {
public:
@ -24,6 +25,7 @@ public:
struct EmitArgs {
EmitArgs(GrGLSLXPBuilder* pb,
GrGLSLXPFragmentBuilder* fragBuilder,
const GrGLSLCaps* caps,
const GrXferProcessor& xp,
const char* inputColor,
const char* inputCoverage,
@ -32,6 +34,7 @@ public:
const TextureSamplerArray& samplers)
: fPB(pb)
, fXPFragBuilder(fragBuilder)
, fGLSLCaps(caps)
, fXP(xp)
, fInputColor(inputColor)
, fInputCoverage(inputCoverage)
@ -41,6 +44,7 @@ public:
GrGLSLXPBuilder* fPB;
GrGLSLXPFragmentBuilder* fXPFragBuilder;
const GrGLSLCaps* fGLSLCaps;
const GrXferProcessor& fXP;
const char* fInputColor;
const char* fInputCoverage;