aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/builders
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2015-11-11 06:27:20 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-11 06:27:20 -0800
commit8dcdedc4a087ea46ce1e2458d335d60918e56310 (patch)
tree40ef4cd4b187fceb923c4de5d7311b7684d7d6e8 /src/gpu/gl/builders
parent49115b57cb9d260ddd49a6905ee87af63b3ab066 (diff)
Make GrGLSLProgramBuilder base class for GrGLProgramBuilder.
This CL still keeps the weird diamond shape we have for all our ProgramBuilders. However, the GrGLSL base class will allow us to pull multiple other parts of our program setup away from GL which will eventually allow us to break up the diamond. As part of this all ShaderBuilder subclass have been made gl independent, however I will move them to GLSL files/class names in a follow on CL. BUG=skia: Review URL: https://codereview.chromium.org/1416423003
Diffstat (limited to 'src/gpu/gl/builders')
-rw-r--r--src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp54
-rw-r--r--src/gpu/gl/builders/GrGLFragmentShaderBuilder.h28
-rw-r--r--src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp4
-rw-r--r--src/gpu/gl/builders/GrGLGeometryShaderBuilder.h6
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp57
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h262
-rw-r--r--src/gpu/gl/builders/GrGLShaderBuilder.cpp12
-rw-r--r--src/gpu/gl/builders/GrGLShaderBuilder.h8
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp24
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.h12
10 files changed, 94 insertions, 373 deletions
diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp
index d06c2f3488..c464ffd3b1 100644
--- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp
@@ -7,17 +7,11 @@
#include "GrGLFragmentShaderBuilder.h"
#include "GrRenderTarget.h"
-#include "GrGLProgramBuilder.h"
-#include "gl/GrGLGpu.h"
#include "glsl/GrGLSL.h"
#include "glsl/GrGLSLCaps.h"
-
-#define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X)
-#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X)
+#include "glsl/GrGLSLProgramBuilder.h"
const char* GrGLFragmentShaderBuilder::kDstTextureColorName = "_dstColor";
-static const char* declared_color_output_name() { return "fsColorOut"; }
-static const char* declared_secondary_color_output_name() { return "fsSecondaryColorOut"; }
static const char* specific_layout_qualifier_name(GrBlendEquation equation) {
SkASSERT(GrBlendEquationIsAdvanced(equation));
@@ -69,11 +63,9 @@ GrGLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst) {
}
}
-GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLProgramBuilder* program,
+GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLSLProgramBuilder* program,
uint8_t fragPosKey)
: INHERITED(program)
- , fHasCustomColorOutput(false)
- , fHasSecondaryOutput(false)
, fSetupFragPosition(false)
, fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey)
, fCustomColorOutputIndex(-1)
@@ -118,18 +110,18 @@ SkString GrGLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCoor
const char* GrGLFragmentShaderBuilder::fragmentPosition() {
fHasReadFragmentPosition = true;
- GrGLGpu* gpu = fProgramBuilder->gpu();
+ const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
// We only declare "gl_FragCoord" when we're in the case where we want to use layout qualifiers
// to reverse y. Otherwise it isn't necessary and whether the "in" qualifier appears in the
// declaration varies in earlier GLSL specs. So it is simpler to omit it.
if (fTopLeftFragPosRead) {
fSetupFragPosition = true;
return "gl_FragCoord";
- } else if (gpu->glCaps().fragCoordConventionsSupport()) {
+ } else if (const char* extension = glslCaps->fragCoordConventionsExtensionString()) {
if (!fSetupFragPosition) {
- if (gpu->glslGeneration() < k150_GrGLSLGeneration) {
+ if (glslCaps->generation() < k150_GrGLSLGeneration) {
this->addFeature(1 << kFragCoordConventions_GLSLPrivateFeature,
- "GL_ARB_fragment_coord_conventions");
+ extension);
}
fInputs.push_back().set(kVec4f_GrSLType,
GrGLSLShaderVar::kIn_TypeModifier,
@@ -147,7 +139,7 @@ const char* GrGLFragmentShaderBuilder::fragmentPosition() {
const char* rtHeightName;
fProgramBuilder->fUniformHandles.fRTHeightUni =
- fProgramBuilder->addFragPosUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fProgramBuilder->addFragPosUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType,
kDefault_GrSLPrecision,
"RTHeight",
@@ -181,7 +173,7 @@ const char* GrGLFragmentShaderBuilder::dstColor() {
if (glslCaps->fbFetchNeedsCustomOutput()) {
this->enableCustomOutput();
fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOut_TypeModifier);
- fbFetchColorName = declared_color_output_name();
+ fbFetchColorName = DeclaredColorOutputName();
}
return fbFetchColorName;
} else {
@@ -212,35 +204,35 @@ void GrGLFragmentShaderBuilder::enableCustomOutput() {
fCustomColorOutputIndex = fOutputs.count();
fOutputs.push_back().set(kVec4f_GrSLType,
GrGLSLShaderVar::kOut_TypeModifier,
- declared_color_output_name());
+ DeclaredColorOutputName());
}
}
void GrGLFragmentShaderBuilder::enableSecondaryOutput() {
SkASSERT(!fHasSecondaryOutput);
fHasSecondaryOutput = true;
- if (kGLES_GrGLStandard == fProgramBuilder->gpu()->ctxInfo().standard()) {
- this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, "GL_EXT_blend_func_extended");
+ const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
+ if (const char* extension = caps.secondaryOutputExtensionString()) {
+ this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension);
}
// If the primary output is declared, we must declare also the secondary output
// and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
// output. The condition also co-incides with the condition in whici GLES SL 2.0
// requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output.
- const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
if (caps.mustDeclareFragmentShaderOutput()) {
fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier,
- declared_secondary_color_output_name());
+ DeclaredSecondaryColorOutputName());
}
}
const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const {
- return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor";
+ return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor";
}
const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const {
- const GrGLSLCaps& caps = *fProgramBuilder->gpu()->glCaps().glslCaps();
- return caps.mustDeclareFragmentShaderOutput() ? declared_secondary_color_output_name()
+ const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
+ return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName()
: "gl_SecondaryFragColorEXT";
}
@@ -250,18 +242,7 @@ void GrGLFragmentShaderBuilder::onFinalize() {
&this->precisionQualifier());
}
-void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID) {
- const GrGLCaps& caps = fProgramBuilder->gpu()->glCaps();
- if (fHasCustomColorOutput && caps.bindFragDataLocationSupport()) {
- GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name()));
- }
- if (fHasSecondaryOutput && caps.glslCaps()->mustDeclareFragmentShaderOutput()) {
- GL_CALL(BindFragDataLocationIndexed(programID, 0, 1,
- declared_secondary_color_output_name()));
- }
-}
-
-void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec) {
+void GrGLFragmentShaderBuilder::addVarying(GrGLSLVarying* v, GrSLPrecision fsPrec) {
v->fFsIn = v->fVsOut;
if (v->fGsOut) {
v->fFsIn = v->fGsOut;
@@ -284,3 +265,4 @@ void GrGLFragmentBuilder::onAfterChildProcEmitCode() {
int removeAt = fMangleString.findLastOf('_');
fMangleString.remove(removeAt, fMangleString.size() - removeAt);
}
+
diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
index 39ca5e7dad..16cc8cffe3 100644
--- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
@@ -10,19 +10,20 @@
#include "GrGLShaderBuilder.h"
-#include "gl/GrGLTypes.h"
#include "glsl/GrGLSLProcessorTypes.h"
class GrRenderTarget;
-class GrGLVarying;
+class GrGLSLVarying;
/*
* This base class encapsulates the functionality which the GP uses to build fragment shaders
*/
class GrGLFragmentBuilder : public GrGLShaderBuilder {
public:
- GrGLFragmentBuilder(GrGLProgramBuilder* program)
- : INHERITED(program) {
+ GrGLFragmentBuilder(GrGLSLProgramBuilder* program)
+ : INHERITED(program)
+ , fHasCustomColorOutput(false)
+ , fHasSecondaryOutput(false) {
fSubstageIndices.push_back(0);
}
virtual ~GrGLFragmentBuilder() {}
@@ -62,6 +63,13 @@ public:
const SkString& getMangleString() const { return fMangleString; }
+ bool hasCustomColorOutput() const { return fHasCustomColorOutput; }
+ bool hasSecondaryOutput() const { return fHasSecondaryOutput; }
+
+protected:
+ bool fHasCustomColorOutput;
+ bool fHasSecondaryOutput;
+
private:
/*
* State that tracks which child proc in the proc tree is currently emitting code. This is
@@ -95,7 +103,7 @@ private:
*/
class GrGLXPFragmentBuilder : public GrGLFragmentBuilder {
public:
- GrGLXPFragmentBuilder(GrGLProgramBuilder* program) : INHERITED(program) {}
+ GrGLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
/** Returns the variable name that holds the color of the destination pixel. This may be nullptr if
no effect advertised that it will read the destination. */
@@ -120,7 +128,7 @@ public:
the key is 0. */
static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst);
- GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, uint8_t fragPosKey);
+ GrGLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKey);
// true public interface, defined explicitly in the abstract interfaces above
bool enableFeature(GLSLFeature) override;
@@ -137,7 +145,6 @@ private:
void enableSecondaryOutput();
const char* getPrimaryColorOutputName() const;
const char* getSecondaryColorOutputName() const;
- void bindFragmentShaderLocations(GrGLuint programID);
// As GLProcessors emit code, there are some conditions we need to verify. We use the below
// state to track this. The reset call is called per processor emitted.
@@ -148,10 +155,13 @@ private:
fHasReadFragmentPosition = false;
}
+ static const char* DeclaredColorOutputName() { return "fsColorOut"; }
+ static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryColorOut"; }
+
/*
* An internal call for GrGLProgramBuilder to use to add varyings to the vertex shader
*/
- void addVarying(GrGLVarying*, GrSLPrecision);
+ void addVarying(GrGLSLVarying*, GrSLPrecision);
void onFinalize() override;
@@ -174,8 +184,6 @@ private:
static const char* kDstTextureColorName;
- bool fHasCustomColorOutput;
- bool fHasSecondaryOutput;
bool fSetupFragPosition;
bool fTopLeftFragPosRead;
int fCustomColorOutputIndex;
diff --git a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp
index 159b904f2c..420c513ae0 100644
--- a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp
@@ -9,12 +9,12 @@
#include "GrGLProgramBuilder.h"
#include "../GrGLGpu.h"
-GrGLGeometryBuilder::GrGLGeometryBuilder(GrGLProgramBuilder* program)
+GrGLGeometryBuilder::GrGLGeometryBuilder(GrGLSLProgramBuilder* program)
: INHERITED(program) {
}
-void GrGLGeometryBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLVarying* v) {
+void GrGLGeometryBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying* v) {
// if we have a GS take each varying in as an array
// and output as non-array.
if (v->vsVarying()) {
diff --git a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.h b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.h
index 7691666a60..e8076465a3 100644
--- a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.h
@@ -10,17 +10,17 @@
#include "GrGLShaderBuilder.h"
-class GrGLVarying;
+class GrGLSLVarying;
class GrGLGeometryBuilder : public GrGLShaderBuilder {
public:
- GrGLGeometryBuilder(GrGLProgramBuilder* program);
+ GrGLGeometryBuilder(GrGLSLProgramBuilder* program);
private:
/*
* an internal call for GrGLFullProgramBuilder to add varyings
*/
- void addVarying(const char* name, GrSLPrecision precision, GrGLVarying*);
+ void addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying*);
void onFinalize() override {}
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 232c7ba0c2..d336ff1f0d 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -27,8 +27,6 @@
#define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
#define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X)
-const int GrGLProgramBuilder::kVarsPerBlock = 8;
-
GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gpu) {
GrAutoLocaleSetter als("C");
@@ -53,13 +51,9 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp
/////////////////////////////////////////////////////////////////////////////
GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
- : fVS(this)
- , fGS(this)
- , fFS(this, args.fDesc->header().fFragPosKey)
- , fStageIndex(-1)
+ : INHERITED(args)
, fGeometryProcessor(nullptr)
, fXferProcessor(nullptr)
- , fArgs(args)
, fGpu(gpu)
, fUniforms(kVarsPerBlock)
, fSamplerUniforms(4)
@@ -67,7 +61,7 @@ GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
}
void GrGLProgramBuilder::addVarying(const char* name,
- GrGLVarying* varying,
+ GrGLSLVarying* varying,
GrSLPrecision precision) {
SkASSERT(varying);
if (varying->vsVarying()) {
@@ -84,7 +78,7 @@ void GrGLProgramBuilder::addVarying(const char* name,
void GrGLProgramBuilder::addPassThroughAttribute(const GrPrimitiveProcessor::Attribute* input,
const char* output) {
GrSLType type = GrVertexAttribTypeToSLType(input->fType);
- GrGLVertToFrag v(type);
+ GrGLSLVertToFrag v(type);
this->addVarying(input->fName, &v);
fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName);
fFS.codeAppendf("%s = %s;", output, v.fsIn());
@@ -92,7 +86,7 @@ void GrGLProgramBuilder::addPassThroughAttribute(const GrPrimitiveProcessor::Att
GrGLProgramBuilder::SeparableVaryingHandle GrGLProgramBuilder::addSeparableVarying(
const char* name,
- GrGLVertToFrag* v,
+ GrGLSLVertToFrag* v,
GrSLPrecision fsPrecision) {
// This call is not used for non-NVPR backends.
SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport() &&
@@ -106,21 +100,6 @@ GrGLProgramBuilder::SeparableVaryingHandle GrGLProgramBuilder::addSeparableVaryi
return SeparableVaryingHandle(varyingInfo.fLocation);
}
-void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
- if ('\0' == prefix) {
- *out = name;
- } else {
- out->printf("%c%s", prefix, name);
- }
- if (mangle) {
- if (out->endsWith('_')) {
- // Names containing "__" are reserved.
- out->append("x");
- }
- out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str());
- }
-}
-
GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformArray(
uint32_t visibility,
GrSLType type,
@@ -159,8 +138,7 @@ GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformAr
return GrGLSLProgramDataManager::UniformHandle(fUniforms.count() - 1);
}
-void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility,
- SkString* out) const {
+void GrGLProgramBuilder::onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const {
for (int i = 0; i < fUniforms.count(); ++i) {
if (fUniforms[i].fVisibility & visibility) {
fUniforms[i].fVariable.appendDecl(this->glslCaps(), out);
@@ -169,12 +147,8 @@ void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility,
}
}
-const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
- return fGpu->ctxInfo();
-}
-
const GrGLSLCaps* GrGLProgramBuilder::glslCaps() const {
- return this->ctxInfo().caps()->glslCaps();
+ return this->fGpu->ctxInfo().caps()->glslCaps();
}
bool GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage) {
@@ -330,7 +304,7 @@ void GrGLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
fFS.enableSecondaryOutput();
}
- if (this->ctxInfo().caps()->glslCaps()->mustDeclareFragmentShaderOutput()) {
+ if (this->glslCaps()->mustDeclareFragmentShaderOutput()) {
fFS.enableCustomOutput();
}
@@ -423,7 +397,12 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
// NVPR actually requires a vertex shader to compile
bool useNvpr = primitiveProcessor().isPathRendering();
if (!useNvpr) {
- fVS.bindVertexAttributes(programID);
+ const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
+
+ int vaCount = primProc.numAttribs();
+ for (int i = 0; i < vaCount; i++) {
+ GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName));
+ }
}
fFS.finalize(kFragment_Visibility);
@@ -460,7 +439,15 @@ void GrGLProgramBuilder::bindProgramResourceLocations(GrGLuint programID) {
}
}
- fFS.bindFragmentShaderLocations(programID);
+ const GrGLCaps& caps = this->gpu()->glCaps();
+ if (fFS.hasCustomColorOutput() && caps.bindFragDataLocationSupport()) {
+ GL_CALL(BindFragDataLocation(programID, 0,
+ GrGLFragmentShaderBuilder::DeclaredColorOutputName()));
+ }
+ if (fFS.hasSecondaryOutput() && caps.glslCaps()->mustDeclareFragmentShaderOutput()) {
+ GL_CALL(BindFragDataLocationIndexed(programID, 0, 1,
+ GrGLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
+ }
// handle NVPR separable varyings
if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() ||
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 3a1a50e453..c524f59e01 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -8,10 +8,8 @@
#ifndef GrGLProgramBuilder_DEFINED
#define GrGLProgramBuilder_DEFINED
-#include "GrGLFragmentShaderBuilder.h"
-#include "GrGLGeometryShaderBuilder.h"
-#include "GrGLVertexShaderBuilder.h"
#include "gl/GrGLProgramDataManager.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLTextureSampler.h"
#include "../GrGLPrimitiveProcessor.h"
@@ -20,199 +18,12 @@
class GrFragmentProcessor;
class GrGLContextInfo;
+class GrGLShaderBuilder;
class GrGLSLCaps;
// Enough precision to represent 1 / 2048 accurately in printf
#define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
-/*
- * This is the base class for a series of interfaces. This base class *MUST* remain abstract with
- * NO data members because it is used in multiple interface inheritance.
- * Heirarchy:
- * GrGLUniformBuilder
- * / \
- * GrGLFPBuilder GrGLGPBuilder
- * \ /
- * GrGLProgramBuilder(internal use only)
- */
-class GrGLUniformBuilder {
-public:
- enum ShaderVisibility {
- kVertex_Visibility = 1 << kVertex_GrShaderType,
- kGeometry_Visibility = 1 << kGeometry_GrShaderType,
- kFragment_Visibility = 1 << kFragment_GrShaderType,
- };
-
- virtual ~GrGLUniformBuilder() {}
-
- typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
- typedef GrGLSLProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle;
-
- /** Add a uniform variable to the current program, that has visibility in one or more shaders.
- visibility is a bitfield of ShaderVisibility values indicating from which shaders the
- uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not
- 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,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- const char** outName = nullptr) {
- return this->addUniformArray(visibility, type, precision, name, 0, outName);
- }
-
- virtual UniformHandle addUniformArray(
- uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- int arrayCount,
- const char** outName = nullptr) {
- return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
- outName);
- }
-
-
- virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
-
- /**
- * Shortcut for getUniformVariable(u).c_str()
- */
- virtual const char* getUniformCStr(UniformHandle u) const = 0;
-
- virtual const GrGLContextInfo& ctxInfo() const = 0;
-
- virtual const GrGLSLCaps* glslCaps() const = 0;
-
- virtual GrGLGpu* gpu() const = 0;
-
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-private:
- virtual UniformHandle internalAddUniformArray(
- uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- bool mangleName,
- int arrayCount,
- const char** outName) = 0;
-};
-
-// TODO move this into GrGLGPBuilder and move them both out of this file
-class GrGLVarying {
-public:
- bool vsVarying() const { return kVertToFrag_Varying == fVarying ||
- kVertToGeo_Varying == fVarying; }
- bool fsVarying() const { return kVertToFrag_Varying == fVarying ||
- kGeoToFrag_Varying == fVarying; }
- const char* vsOut() const { return fVsOut; }
- const char* gsIn() const { return fGsIn; }
- const char* gsOut() const { return fGsOut; }
- const char* fsIn() const { return fFsIn; }
- GrSLType type() const { return fType; }
-
-protected:
- enum Varying {
- kVertToFrag_Varying,
- kVertToGeo_Varying,
- kGeoToFrag_Varying,
- };
-
- GrGLVarying(GrSLType type, Varying varying)
- : fVarying(varying), fType(type), fVsOut(nullptr), fGsIn(nullptr), fGsOut(nullptr),
- fFsIn(nullptr) {}
-
- Varying fVarying;
-
-private:
- GrSLType fType;
- const char* fVsOut;
- const char* fGsIn;
- const char* fGsOut;
- const char* fFsIn;
-
- friend class GrGLVertexBuilder;
- friend class GrGLGeometryBuilder;
- friend class GrGLXferBuilder;
- friend class GrGLFragmentShaderBuilder;
-};
-
-struct GrGLVertToFrag : public GrGLVarying {
- GrGLVertToFrag(GrSLType type)
- : GrGLVarying(type, kVertToFrag_Varying) {}
-};
-
-struct GrGLVertToGeo : public GrGLVarying {
- GrGLVertToGeo(GrSLType type)
- : GrGLVarying(type, kVertToGeo_Varying) {}
-};
-
-struct GrGLGeoToFrag : public GrGLVarying {
- GrGLGeoToFrag(GrSLType type)
- : GrGLVarying(type, kGeoToFrag_Varying) {}
-};
-
-/* a specialization of the above for GPs. Lets the user add uniforms, varyings, and VS / FS code */
-class GrGLGPBuilder : public virtual GrGLUniformBuilder {
-public:
- /*
- * addVarying allows fine grained control for setting up varyings between stages. If you just
- * need to take an attribute and pass it through to an output value in a fragment shader, use
- * addPassThroughAttribute.
- * TODO convert most uses of addVarying to addPassThroughAttribute
- */
- virtual void addVarying(const char* name,
- GrGLVarying*,
- GrSLPrecision precision = kDefault_GrSLPrecision) = 0;
-
- /*
- * This call can be used by GP to pass an attribute through all shaders directly to 'output' in
- * the fragment shader. Though this call effects both the vertex shader and fragment shader,
- * it expects 'output' to be defined in the fragment shader before this call is made.
- * TODO it might be nicer behavior to have a flag to declare output inside this call
- */
- virtual void addPassThroughAttribute(const GrGeometryProcessor::Attribute*,
- const char* output) = 0;
-
- /*
- * Creates a fragment shader varying that can be referred to.
- * Comparable to GrGLUniformBuilder::addUniform().
- */
- virtual SeparableVaryingHandle addSeparableVarying(
- const char* name, GrGLVertToFrag*, GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0;
-
- // TODO rename getFragmentBuilder
- virtual GrGLFragmentBuilder* getFragmentShaderBuilder() = 0;
- virtual GrGLVertexBuilder* getVertexShaderBuilder() = 0;
-
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-};
-
-/* a specializations for FPs. Lets the user add uniforms and FS code */
-class GrGLFPBuilder : public virtual GrGLUniformBuilder {
-public:
- virtual GrGLFragmentBuilder* getFragmentShaderBuilder() = 0;
-
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-};
-
-/* a specializations for XPs. Lets the user add uniforms and FS code */
-class GrGLXPBuilder : public virtual GrGLUniformBuilder {
-public:
- virtual GrGLXPFragmentBuilder* getFragmentShaderBuilder() = 0;
-
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-};
-
/**
* The below struct represent processors installed in programs.
*/
@@ -238,11 +49,8 @@ struct GrGLInstalledFragProcs : public SkRefCnt {
* each of the elements of the shader pipeline, ie vertex, fragment, geometry, etc, lives in those
* respective builders
*/
-class GrGLProgramBuilder : public GrGLGPBuilder,
- public GrGLFPBuilder,
- public GrGLXPBuilder {
+class GrGLProgramBuilder : public GrGLSLProgramBuilder {
public:
- typedef GrGpu::DrawArgs DrawArgs;
/** Generates a shader program.
*
* The program implements what is specified in the stages given as input.
@@ -260,18 +68,13 @@ public:
return this->getUniformVariable(u).c_str();
}
- const GrGLContextInfo& ctxInfo() const override;
-
const GrGLSLCaps* glslCaps() const override;
- GrGLGpu* gpu() const override { return fGpu; }
-
- GrGLXPFragmentBuilder* getFragmentShaderBuilder() override { return &fFS; }
- GrGLVertexBuilder* getVertexShaderBuilder() override { return &fVS; }
+ GrGLGpu* gpu() const { return fGpu; }
void addVarying(
const char* name,
- GrGLVarying*,
+ GrGLSLVarying*,
GrSLPrecision precision = kDefault_GrSLPrecision) override;
void addPassThroughAttribute(const GrPrimitiveProcessor::Attribute*,
@@ -279,19 +82,10 @@ public:
SeparableVaryingHandle addSeparableVarying(
const char* name,
- GrGLVertToFrag*,
+ GrGLSLVertToFrag*,
GrSLPrecision fsPrecision = kDefault_GrSLPrecision) override;
- // Handles for program uniforms (other than per-effect uniforms)
- struct BuiltinUniformHandles {
- UniformHandle fRTAdjustmentUni;
-
- // We use the render target height to provide a y-down frag coord when specifying
- // origin_upper_left is not supported.
- UniformHandle fRTHeightUni;
- };
-
-protected:
+private:
typedef GrGLProgramDataManager::UniformInfo UniformInfo;
typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
typedef GrGLProgramDataManager::SeparableVaryingInfo SeparableVaryingInfo;
@@ -299,11 +93,6 @@ protected:
GrGLProgramBuilder(GrGLGpu*, const DrawArgs&);
- const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrimitiveProcessor; }
- const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
- const GrProgramDesc& desc() const { return *fArgs.fDesc; }
- const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(); }
-
UniformHandle internalAddUniformArray(uint32_t visibility,
GrSLType type,
GrSLPrecision precision,
@@ -312,20 +101,6 @@ protected:
int arrayCount,
const char** outName) override;
- // Used to add a uniform for frag position without mangling the name of the uniform inside of a
- // stage.
- UniformHandle addFragPosUniform(uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- const char** outName) {
- return this->internalAddUniformArray(visibility, type, precision, name, false, 0, outName);
- }
-
- // Generates a name for a variable. The generated string will be name prefixed by the prefix
- // char (unless the prefix is '\0'). It also will mangle the name to be stage-specific unless
- // explicitly asked not to.
- void nameVariable(SkString* out, char prefix, const char* name, bool mangle = true);
// Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
// If GrGLSLExpr4 has a valid name then it will use that instead
void nameExpression(GrGLSLExpr4*, const char* baseName);
@@ -365,16 +140,16 @@ protected:
GrGLenum type,
SkTDArray<GrGLuint>* shaderIds);
GrGLProgram* finalize();
- virtual void bindProgramResourceLocations(GrGLuint programID);
+ void bindProgramResourceLocations(GrGLuint programID);
bool checkLinkStatus(GrGLuint programID);
- virtual void resolveProgramResourceLocations(GrGLuint programID);
+ void resolveProgramResourceLocations(GrGLuint programID);
void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs);
void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs);
// Subclasses create different programs
- virtual GrGLProgram* createProgram(GrGLuint programID);
+ GrGLProgram* createProgram(GrGLuint programID);
- void appendUniformDecls(ShaderVisibility, SkString*) const;
+ void onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const override;
// reset is called by program creator between each processor's emit code. It increments the
// stage offset for variable name mangling, and also ensures verfication variables in the
@@ -397,24 +172,11 @@ protected:
private:
GrGLProgramBuilder* fPB;
};
- int stageIndex() const { return fStageIndex; }
-
- 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;
-
- BuiltinUniformHandles fUniformHandles;
- GrGLVertexBuilder fVS;
- GrGLGeometryBuilder fGS;
- GrGLFragmentShaderBuilder fFS;
- int fStageIndex;
GrGLInstalledGeoProc* fGeometryProcessor;
GrGLInstalledXferProc* fXferProcessor;
SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors;
- const DrawArgs& fArgs;
GrGLGpu* fGpu;
UniformInfoArray fUniforms;
GrGLPrimitiveProcessor::TransformsIn fCoordTransforms;
@@ -426,5 +188,7 @@ protected:
friend class GrGLVertexBuilder;
friend class GrGLFragmentShaderBuilder;
friend class GrGLGeometryBuilder;
+
+ typedef GrGLSLProgramBuilder INHERITED;
};
#endif
diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.cpp b/src/gpu/gl/builders/GrGLShaderBuilder.cpp
index 2c00bafcf7..ed5c3d4537 100644
--- a/src/gpu/gl/builders/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderBuilder.cpp
@@ -6,10 +6,10 @@
*/
#include "GrGLShaderBuilder.h"
-#include "gl/builders/GrGLProgramBuilder.h"
#include "glsl/GrGLSLCaps.h"
#include "glsl/GrGLSLShaderVar.h"
#include "glsl/GrGLSLTextureSampler.h"
+#include "glsl/GrGLSLProgramBuilder.h"
static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangledSwizzle) {
int i;
@@ -69,10 +69,10 @@ static void append_texture_lookup(SkString* out,
}
}
-GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program)
+GrGLShaderBuilder::GrGLShaderBuilder(GrGLSLProgramBuilder* program)
: fProgramBuilder(program)
- , fInputs(GrGLProgramBuilder::kVarsPerBlock)
- , fOutputs(GrGLProgramBuilder::kVarsPerBlock)
+ , fInputs(GrGLSLProgramBuilder::kVarsPerBlock)
+ , fOutputs(GrGLSLProgramBuilder::kVarsPerBlock)
, fFeaturesAddedMask(0)
, fCodeIndex(kCode)
, fFinalized(false) {
@@ -187,11 +187,11 @@ void GrGLShaderBuilder::finalize(uint32_t visibility) {
this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString();
this->compileAndAppendLayoutQualifiers();
SkASSERT(visibility);
- fProgramBuilder->appendUniformDecls((GrGLProgramBuilder::ShaderVisibility) visibility,
+ fProgramBuilder->appendUniformDecls((GrGLSLProgramBuilder::ShaderVisibility) visibility,
&this->uniforms());
this->appendDecls(fInputs, &this->inputs());
// We should not have any outputs in the fragment shader when using version 1.10
- SkASSERT(GrGLProgramBuilder::kFragment_Visibility != visibility ||
+ SkASSERT(GrGLSLProgramBuilder::kFragment_Visibility != visibility ||
k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
fOutputs.empty());
this->appendDecls(fOutputs, &this->outputs());
diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.h b/src/gpu/gl/builders/GrGLShaderBuilder.h
index d63a679e8c..2978db3a64 100644
--- a/src/gpu/gl/builders/GrGLShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLShaderBuilder.h
@@ -14,7 +14,7 @@
#include <stdarg.h>
-class GrGLProgramBuilder;
+class GrGLSLProgramBuilder;
class GrGLSLTextureSampler;
/**
@@ -22,7 +22,7 @@ class GrGLSLTextureSampler;
*/
class GrGLShaderBuilder {
public:
- GrGLShaderBuilder(GrGLProgramBuilder* program);
+ GrGLShaderBuilder(GrGLSLProgramBuilder* program);
virtual ~GrGLShaderBuilder() {}
void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); }
@@ -102,7 +102,7 @@ public:
/*
* Get parent builder for adding uniforms
*/
- GrGLProgramBuilder* getProgramBuilder() { return fProgramBuilder; }
+ GrGLSLProgramBuilder* getProgramBuilder() { return fProgramBuilder; }
/**
* Helper for begining and ending a block in the shader code.
@@ -179,7 +179,7 @@ protected:
kCode,
};
- GrGLProgramBuilder* fProgramBuilder;
+ GrGLSLProgramBuilder* fProgramBuilder;
SkSTArray<kCode, const char*, true> fCompilerStrings;
SkSTArray<kCode, int, true> fCompilerStringLengths;
SkSTArray<kCode, SkString> fShaderStrings;
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
index f19d63fffa..c4054e292b 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
@@ -6,19 +6,14 @@
*/
#include "GrGLVertexShaderBuilder.h"
-#include "GrGLProgramBuilder.h"
-#include "../GrGLGLSL.h"
-#include "../GrGLGpu.h"
+#include "glsl/GrGLSLProgramBuilder.h"
-#define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X)
-#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X)
-
-GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program)
+GrGLVertexBuilder::GrGLVertexBuilder(GrGLSLProgramBuilder* program)
: INHERITED(program)
, fRtAdjustName(nullptr) {
}
-void GrGLVertexBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLVarying* v) {
+void GrGLVertexBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying* v) {
fOutputs.push_back();
fOutputs.back().setType(v->fType);
fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier);
@@ -45,7 +40,7 @@ void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV
// setup RT Uniform
fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
- fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
+ fProgramBuilder->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
kVec4f_GrSLType, precision,
fProgramBuilder->rtAdjustment(),
&fRtAdjustName);
@@ -77,16 +72,6 @@ void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV
this->codeAppend("gl_PointSize = 1.0;");
}
-void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) {
- const GrPrimitiveProcessor& primProc = fProgramBuilder->primitiveProcessor();
-
- int vaCount = primProc.numAttribs();
- for (int i = 0; i < vaCount; i++) {
- GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName));
- }
- return;
-}
-
bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) {
SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
for (int i = 0; i < fInputs.count(); ++i) {
@@ -99,3 +84,4 @@ bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) {
fInputs.push_back(var);
return true;
}
+
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
index 81aebd41b8..4662c403e5 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
@@ -9,14 +9,13 @@
#define GrGLVertexShader_DEFINED
#include "GrGLShaderBuilder.h"
-#include "gl/GrGLTypes.h"
#include "GrGeometryProcessor.h"
-class GrGLVarying;
+class GrGLSLVarying;
class GrGLVertexBuilder : public GrGLShaderBuilder {
public:
- GrGLVertexBuilder(GrGLProgramBuilder* program);
+ GrGLVertexBuilder(GrGLSLProgramBuilder* program);
void transformToNormalizedDeviceSpace(const GrShaderVar& posVar);
void emitAttributes(const GrGeometryProcessor& gp);
@@ -33,12 +32,7 @@ private:
/*
* Internal call for GrGLProgramBuilder.addVarying
*/
- void addVarying(const char* name, GrSLPrecision, GrGLVarying*);
-
- /*
- * private helpers for compilation by GrGLProgramBuilder
- */
- void bindVertexAttributes(GrGLuint programID);
+ void addVarying(const char* name, GrSLPrecision, GrGLSLVarying*);
// an internal call which checks for uniquness of a var before adding it to the list of inputs
bool addAttribute(const GrShaderVar& var);