aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@google.com>2014-11-07 12:08:03 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-07 12:08:03 -0800
commitee0ea3f0dd878fb5c8354924c0c8627ab2a95c41 (patch)
treeff1dabfa99425f9e9ea7a81cb04afeeeff31e8f9 /src/gpu/gl
parentff343074b2a3fdaa5f120600e28717e366bceadd (diff)
Revert of Default geometry processor (patchset #9 id:160001 of https://codereview.chromium.org/678953002/)
Reason for revert: breaks nexus 5 Original issue's description: > Default geometry processor > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/ff343074b2a3fdaa5f120600e28717e366bceadd TBR=bsalomon@google.com,joshualitt@chromium.org NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/691313003
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLSL.h8
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp92
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h24
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp59
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.h17
5 files changed, 65 insertions, 135 deletions
diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h
index 99671c130e..b031a40a61 100644
--- a/src/gpu/gl/GrGLSL.h
+++ b/src/gpu/gl/GrGLSL.h
@@ -106,10 +106,6 @@ public:
return fExpr.c_str();
}
- bool isValid() const {
- return kFullExpr_ExprType != fType || !fExpr.isEmpty();
- }
-
protected:
/** Constructs an invalid expression.
* Useful only as a return value from functions that never actually return
@@ -170,6 +166,10 @@ protected:
fExpr.appendf(format, in0, in1);
}
+ bool isValid() const {
+ return kFullExpr_ExprType != fType || !fExpr.isEmpty();
+ }
+
/** Returns expression casted to another type.
* Generic implementation that is called for non-trivial cases of casts. */
template <typename T>
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index de4a1d5e6e..8fc6020121 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -57,11 +57,9 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState,
bool hasVertexShader = !(header.fUseNvpr &&
gpu->glPathRendering()->texturingMode() ==
GrGLPathRendering::FixedFunction_TexturingMode);
-
if (hasVertexShader) {
- pb->fVS.setupUniformViewMatrix();
- pb->fVS.setupPositionAndLocalCoords();
-
+ pb->fVS.setupLocalCoords();
+ pb->fVS.transformGLToSkiaCoords();
if (header.fEmitsPointSize) {
pb->fVS.codeAppend("gl_PointSize = 1.0;");
}
@@ -77,10 +75,10 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState,
// remove this cast to a vec4.
GrGLSLExpr4 inputCoverageVec4 = GrGLSLExpr4::VectorCast(inputCoverage);
- pb->emitAndInstallProcs(&inputColor, &inputCoverageVec4);
+ pb->emitAndInstallProcs(optState, &inputColor, &inputCoverageVec4);
if (hasVertexShader) {
- pb->fVS.transformToNormalizedDeviceSpace();
+ pb->fVS.transformSkiaToGLCoords();
}
// write the secondary color output if necessary
@@ -173,17 +171,7 @@ GrGLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray(uint32
UniformInfo& uni = fUniforms.push_back();
uni.fVariable.setType(type);
uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
- // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
- // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
- // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
- // the names will mismatch. I think the correct solution is to have all GPs which need the
- // uniform view matrix, they should upload the view matrix in their setData along with regular
- // uniforms.
- char prefix = 'u';
- if ('u' == name[0]) {
- prefix = '\0';
- }
- this->nameVariable(uni.fVariable.accessName(), prefix, name);
+ this->nameVariable(uni.fVariable.accessName(), 'u', name);
uni.fVariable.setArrayCount(count);
uni.fVisibility = visibility;
@@ -242,40 +230,23 @@ void GrGLProgramBuilder::setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* input
}
}
-void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor,
+void GrGLProgramBuilder::emitAndInstallProcs(const GrOptDrawState& optState,
+ GrGLSLExpr4* inputColor,
GrGLSLExpr4* inputCoverage) {
- // We need to collect all of the transforms to thread them through the GP in the case of GPs
- // which use additional shader stages between the VS and the FS. To do this we emit a dummy
- // input coverage
- GrGLSLExpr4 coverageInput = *inputCoverage;
- if (fOptState.hasGeometryProcessor()) {
- AutoStageAdvance adv(this);
- SkString outColorName;
- this->nameVariable(&outColorName, '\0', "gpOutput");
- coverageInput = outColorName;
- }
- GrGLSLExpr4 gpOutput = coverageInput;
-
- // Emit fragment processors
fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs));
- int numProcs = fOptState.numFragmentStages();
- this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor);
- this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, &coverageInput);
-
- // We have to save the existing code stack, and then append it to the fragment shader code
- // after emiting the GP
- if (fOptState.hasGeometryProcessor()) {
- SkString existingCode(fFS.fCode);
- fFS.fCode.reset();
- const GrGeometryProcessor& gp = *fOptState.getGeometryProcessor();
+ int numProcs = optState.numFragmentStages();
+ this->emitAndInstallFragProcs(0, optState.numColorStages(), inputColor);
+ if (optState.hasGeometryProcessor()) {
+ const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
fVS.emitAttributes(gp);
ProcKeyProvider keyProvider(&fDesc,
ProcKeyProvider::kGeometry_ProcessorType,
GrGLProgramDescBuilder::kProcessorKeyOffsetsAndLengthOffset);
- this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, keyProvider, *inputCoverage, &gpOutput);
- fFS.fCode.append(existingCode);
+ GrGLSLExpr4 output;
+ this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, keyProvider, *inputCoverage, &output);
+ *inputCoverage = output;
}
- *inputCoverage = coverageInput;
+ this->emitAndInstallFragProcs(optState.numColorStages(), numProcs, inputCoverage);
}
void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOut) {
@@ -301,14 +272,9 @@ void GrGLProgramBuilder::emitAndInstallProc(const Proc& proc,
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
- // create var to hold stage result. If we already have a valid output name, just use that
- // otherwise create a new mangled one.
+ // create var to hold stage result
SkString outColorName;
- if (output->isValid()) {
- outColorName = output->c_str();
- } else {
- this->nameVariable(&outColorName, '\0', "output");
- }
+ this->nameVariable(&outColorName, '\0', "output");
fFS.codeAppendf("vec4 %s;", outColorName.c_str());
*output = outColorName;
@@ -349,8 +315,8 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentStage& fs,
void GrGLProgramBuilder::emitAndInstallProc(const GrGeometryProcessor& gp,
const GrProcessorKey& key,
- const char* outCoverage,
- const char* inCoverage) {
+ const char* outColor,
+ const char* inColor) {
SkASSERT(!fGeometryProcessor);
fGeometryProcessor = SkNEW(GrGLInstalledGeoProc);
@@ -359,7 +325,7 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrGeometryProcessor& gp,
SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures());
this->emitSamplers(gp, &samplers, fGeometryProcessor);
- GrGLGeometryProcessor::EmitArgs args(this, gp, key, outCoverage, inCoverage, samplers);
+ GrGLGeometryProcessor::EmitArgs args(this, gp, key, outColor, inColor, samplers);
fGeometryProcessor->fGLProc->emitCode(args);
// We have to check that effects and the code they emit are consistent, ie if an effect
@@ -408,13 +374,23 @@ void GrGLProgramBuilder::emitTransforms(const GrFragmentStage& effectStage,
suffixedVaryingName.appendf("_%i", t);
varyingName = suffixedVaryingName.c_str();
}
- const char* coords = kPosition_GrCoordSet == effect->coordTransform(t).sourceCoords() ?
- fVS.positionAttribute().c_str() :
- fVS.localCoordsAttribute().c_str();
GrGLVertToFrag v(varyingType);
- this->addCoordVarying(varyingName, &v, uniName, coords);
+ this->addVarying(varyingName, &v);
+ const GrGLShaderVar& coords =
+ kPosition_GrCoordSet == effect->coordTransform(t).sourceCoords() ?
+ fVS.positionAttribute() :
+ fVS.localCoordsAttribute();
+
+ // varying = matrix * coords (logically)
SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType);
+ if (kVec2f_GrSLType == varyingType) {
+ fVS.codeAppendf("%s = (%s * vec3(%s, 1)).xy;",
+ v.vsOut(), uniName, coords.c_str());
+ } else {
+ fVS.codeAppendf("%s = %s * vec3(%s, 1);",
+ v.vsOut(), uniName, coords.c_str());
+ }
SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords,
(SkString(v.fsIn()), varyingType));
}
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index a44fa91090..4bcf50be6a 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -241,7 +241,8 @@ protected:
// generating stage code.
void nameVariable(SkString* out, char prefix, const char* name);
void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExpr1* inputCoverage);
- void emitAndInstallProcs(GrGLSLExpr4* inputColor,
+ void emitAndInstallProcs(const GrOptDrawState& optState,
+ GrGLSLExpr4* inputColor,
GrGLSLExpr4* inputCoverage);
void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOut);
template <class Proc>
@@ -258,8 +259,8 @@ protected:
const char* inColor);
void emitAndInstallProc(const GrGeometryProcessor&,
const GrProcessorKey&,
- const char* outCoverage,
- const char* inCoverage);
+ const char* outColor,
+ const char* inColor);
void verify(const GrGeometryProcessor&);
void verify(const GrFragmentProcessor&);
void emitSamplers(const GrProcessor&,
@@ -313,22 +314,6 @@ protected:
void enterStage() { fOutOfStage = false; }
int stageIndex() const { return fStageIndex; }
- struct TransformVarying {
- TransformVarying(const GrGLVarying& v, const char* uniName, const char* sourceCoords)
- : fV(v), fUniName(uniName), fSourceCoords(sourceCoords) {}
- GrGLVarying fV;
- SkString fUniName;
- SkString fSourceCoords;
- };
-
- void addCoordVarying(const char* name, GrGLVarying* v, const char* uniName,
- const char* sourceCoords) {
- this->addVarying(name, v);
- fCoordVaryings.push_back(TransformVarying(*v, uniName, sourceCoords));
- }
-
- const char* rtAdjustment() const { return "rtAdjustment"; }
-
// number of each input/output type in a single allocation block, used by many builders
static const int kVarsPerBlock;
@@ -346,7 +331,6 @@ protected:
const GrProgramDesc& fDesc;
GrGpuGL* fGpu;
UniformInfoArray fUniforms;
- SkSTArray<16, TransformVarying, true> fCoordVaryings;
friend class GrGLShaderBuilder;
friend class GrGLVertexBuilder;
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
index 7af5ce9843..2bef113410 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
@@ -20,7 +20,6 @@ GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program)
: INHERITED(program)
, fPositionVar(NULL)
, fLocalCoordsVar(NULL)
- , fRtAdjustName(NULL)
, fEffectAttribOffset(0) {
}
@@ -32,22 +31,9 @@ void GrGLVertexBuilder::addVarying(const char* name, GrGLVarying* v) {
v->fVsOut = fOutputs.back().getName().c_str();
}
-void GrGLVertexBuilder::setupUniformViewMatrix() {
- fProgramBuilder->fUniformHandles.fViewMatrixUni =
- fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
- kMat33f_GrSLType,
- this->uViewM());
-}
-
-void GrGLVertexBuilder::setupPositionAndLocalCoords() {
- // Setup position
- this->codeAppendf("vec3 %s;", this->glPosition());
-
- // setup position and local coords attribute
+void GrGLVertexBuilder::setupLocalCoords() {
fPositionVar = &fInputs.push_back();
- fPositionVar->set(kVec2f_GrSLType,
- GrGLShaderVar::kAttribute_TypeModifier,
- this->inPosition());
+ fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "inPosition");
if (-1 != fProgramBuilder->header().fLocalCoordAttributeIndex) {
fLocalCoordsVar = &fInputs.push_back();
fLocalCoordsVar->set(kVec2f_GrSLType,
@@ -59,6 +45,18 @@ void GrGLVertexBuilder::setupPositionAndLocalCoords() {
fEffectAttribOffset = fInputs.count();
}
+void GrGLVertexBuilder::transformGLToSkiaCoords() {
+ const char* viewMName;
+ fProgramBuilder->fUniformHandles.fViewMatrixUni =
+ fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
+ kMat33f_GrSLType,
+ "ViewM",
+ &viewMName);
+
+ // Transform the position into Skia's device coords.
+ this->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", viewMName, fPositionVar->c_str());
+}
+
void GrGLVertexBuilder::setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr1* out) {
GrGLVertToFrag v(kFloat_GrSLType);
fProgramBuilder->addVarying(inName, &v);
@@ -93,34 +91,17 @@ void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
}
}
-void GrGLVertexBuilder::transformToNormalizedDeviceSpace() {
- // setup RT Uniform
+void GrGLVertexBuilder::transformSkiaToGLCoords() {
+ const char* rtAdjustName;
fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
kVec4f_GrSLType,
- fProgramBuilder->rtAdjustment(),
- &fRtAdjustName);
- // Wire transforms
- SkTArray<GrGLProgramBuilder::TransformVarying, true>& transVs = fProgramBuilder->fCoordVaryings;
- int transformCount = transVs.count();
- for (int i = 0; i < transformCount; i++) {
- const char* coords = transVs[i].fSourceCoords.c_str();
-
- // varying = matrix * coords (logically)
- const GrGLVarying& v = transVs[i].fV;
- if (kVec2f_GrSLType == v.fType) {
- this->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.fVsOut, transVs[i].fUniName.c_str(),
- coords);
- } else {
- this->codeAppendf("%s = %s * vec3(%s, 1);", v.fVsOut, transVs[i].fUniName.c_str(),
- coords);
- }
- }
+ "rtAdjustment",
+ &rtAdjustName);
// Transform from Skia's device coords to GL's normalized device coords.
- this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);",
- this->glPosition(), fRtAdjustName, this->glPosition(), fRtAdjustName,
- this->glPosition());
+ this->codeAppendf("gl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3.z);",
+ rtAdjustName, rtAdjustName);
}
void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) {
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
index 7d6d95e508..2f14bd7702 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
@@ -31,15 +31,6 @@ public:
*/
const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
- /** returns the expected position output */
- const char* glPosition() const { return "pos3"; }
-
- /** returns the expected uviewM matrix */
- // TODO all of this fixed function stuff can live on the GP/PP
- const char* uViewM() const { return "uViewM"; }
- const char* inPosition() const { return "inPosition"; }
-
-
private:
/*
* Internal call for GrGLProgramBuilder.addVarying
@@ -49,13 +40,12 @@ private:
/*
* private helpers for compilation by GrGLProgramBuilder
*/
- void transformToNormalizedDeviceSpace();
- //TODO GP itself should setup the uniform view matrix
- void setupUniformViewMatrix();
- void setupPositionAndLocalCoords();
+ void setupLocalCoords();
+ void transformGLToSkiaCoords();
void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr1* out);
void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr4* out);
void emitAttributes(const GrGeometryProcessor& gp);
+ void transformSkiaToGLCoords();
void bindVertexAttributes(GrGLuint programID);
bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const;
@@ -71,7 +61,6 @@ private:
GrGLShaderVar* fPositionVar;
GrGLShaderVar* fLocalCoordsVar;
- const char* fRtAdjustName;
int fEffectAttribOffset;
friend class GrGLProgramBuilder;