* Create a transformation that applies the matrix to a coord set.
*/
GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix& m,
- GrShaderVar::Precision precision = GrShaderVar::kDefault_Precision) {
+ GrSLPrecision precision = kDefault_GrSLPrecision) {
SkDEBUGCODE(fInProcessor = false);
this->reset(sourceCoords, m, precision);
}
void reset(GrCoordSet, const SkMatrix&, const GrTexture*);
void reset(GrCoordSet sourceCoords, const SkMatrix& m,
- GrShaderVar::Precision precision = GrShaderVar::kDefault_Precision);
+ GrSLPrecision precision = kDefault_GrSLPrecision);
GrCoordTransform& operator= (const GrCoordTransform& that) {
SkASSERT(!fInProcessor);
GrCoordSet sourceCoords() const { return fSourceCoords; }
const SkMatrix& getMatrix() const { return fMatrix; }
bool reverseY() const { return fReverseY; }
- GrShaderVar::Precision precision() const { return fPrecision; }
+ GrSLPrecision precision() const { return fPrecision; }
/** Useful for effects that want to insert a texture matrix that is implied by the texture
dimensions */
GrCoordSet fSourceCoords;
SkMatrix fMatrix;
bool fReverseY;
- GrShaderVar::Precision fPrecision;
+ GrSLPrecision fPrecision;
typedef SkNoncopyable INHERITED;
#ifdef SK_DEBUG
kVaryingOut_TypeModifier
};
- enum Precision {
- kLow_Precision,
- kMedium_Precision,
- kHigh_Precision,
-
- // Default precision is medium. This is because on OpenGL ES 2 highp support is not
- // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
- kDefault_Precision = kMedium_Precision,
-
- kLast_Precision = kHigh_Precision
- };
- static const int kPrecisionCount = kLast_Precision + 1;
-
/**
* Defaults to a float with no precision specifier
*/
: fType(kFloat_GrSLType)
, fTypeModifier(kNone_TypeModifier)
, fCount(kNonArray)
- , fPrecision(kDefault_Precision) {
+ , fPrecision(kDefault_GrSLPrecision) {
}
GrShaderVar(const SkString& name, GrSLType type, int arrayCount = kNonArray,
- Precision precision = kDefault_Precision)
+ GrSLPrecision precision = kDefault_GrSLPrecision)
: fType(type)
, fTypeModifier(kNone_TypeModifier)
, fName(name)
}
GrShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray,
- Precision precision = kDefault_Precision)
+ GrSLPrecision precision = kDefault_GrSLPrecision)
: fType(type)
, fTypeModifier(kNone_TypeModifier)
, fName(name)
}
GrShaderVar(const char* name, GrSLType type, TypeModifier typeModifier,
- int arrayCount = kNonArray, Precision precision = kDefault_Precision)
+ int arrayCount = kNonArray, GrSLPrecision precision = kDefault_GrSLPrecision)
: fType(type)
, fTypeModifier(typeModifier)
, fName(name)
void set(GrSLType type,
TypeModifier typeModifier,
const SkString& name,
- Precision precision = kDefault_Precision) {
+ GrSLPrecision precision = kDefault_GrSLPrecision) {
SkASSERT(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
void set(GrSLType type,
TypeModifier typeModifier,
const char* name,
- Precision precision = kDefault_Precision) {
+ GrSLPrecision precision = kDefault_GrSLPrecision) {
SkASSERT(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
TypeModifier typeModifier,
const SkString& name,
int count,
- Precision precision = kDefault_Precision) {
+ GrSLPrecision precision = kDefault_GrSLPrecision) {
SkASSERT(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
TypeModifier typeModifier,
const char* name,
int count,
- Precision precision = kDefault_Precision) {
+ GrSLPrecision precision = kDefault_GrSLPrecision) {
SkASSERT(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
/**
* Get the precision of the var
*/
- Precision getPrecision() const { return fPrecision; }
+ GrSLPrecision getPrecision() const { return fPrecision; }
/**
* Set the precision of the var
*/
- void setPrecision(Precision p) { fPrecision = p; }
+ void setPrecision(GrSLPrecision p) { fPrecision = p; }
protected:
GrSLType fType;
TypeModifier fTypeModifier;
SkString fName;
int fCount;
- Precision fPrecision;
+ GrSLPrecision fPrecision;
};
#endif
static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
/**
+ * Precisions of shader language variables. Not all shading languages support precisions or actually
+ * vary the internal precision based on the qualifiers.
+ */
+enum GrSLPrecision {
+ kLow_GrSLPrecision,
+ kMedium_GrSLPrecision,
+ kHigh_GrSLPrecision,
+
+ // Default precision is medium. This is because on OpenGL ES 2 highp support is not
+ // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
+ kDefault_GrSLPrecision = kMedium_GrSLPrecision,
+
+ kLast_GrSLPrecision = kHigh_GrSLPrecision
+};
+
+static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
+
+/**
* Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
*/
static inline int GrSLTypeVectorCount(GrSLType type) {
// increased. Our rule is that we want at least 4 subpixel values in the representation for
// coords between 0 to 1. Note that this still might not be enough when drawing with repeat
// or mirror-repeat modes but that case can be arbitrarily bad.
- fPrecision = GrShaderVar::kDefault_Precision;
+ fPrecision = kDefault_GrSLPrecision;
if (texture->getContext()) {
const GrDrawTargetCaps* caps = texture->getContext()->getGpu()->caps();
if (caps->floatPrecisionVaries()) {
if ((2 << info->fBits) / maxD > 4) {
break;
}
- if (GrShaderVar::kHigh_Precision == fPrecision) {
+ if (kHigh_GrSLPrecision == fPrecision) {
break;
}
- GrShaderVar::Precision nextP = static_cast<GrShaderVar::Precision>(fPrecision + 1);
+ GrSLPrecision nextP = static_cast<GrSLPrecision>(fPrecision + 1);
info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, nextP);
if (!info->supported()) {
break;
void GrCoordTransform::reset(GrCoordSet sourceCoords,
const SkMatrix& m,
- GrShaderVar::Precision precision) {
+ GrSLPrecision precision) {
SkASSERT(!fInProcessor);
fSourceCoords = sourceCoords;
fMatrix = m;
fShaderPrecisionVaries = other.fShaderPrecisionVaries;
for (int s = 0; s < kGrShaderTypeCount; ++s) {
- for (int p = 0; p < GrShaderVar::kPrecisionCount; ++p) {
+ for (int p = 0; p < kGrSLPrecisionCount; ++p) {
fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p];
}
}
return "";
}
-static const char* precision_to_string(GrShaderVar::Precision p) {
+static const char* precision_to_string(GrSLPrecision p) {
switch (p) {
- case GrShaderVar::kLow_Precision:
+ case kLow_GrSLPrecision:
return "low";
- case GrShaderVar::kMedium_Precision:
+ case kMedium_GrSLPrecision:
return "medium";
- case GrShaderVar::kHigh_Precision:
+ case kHigh_GrSLPrecision:
return "high";
}
return "";
for (int s = 0; s < kGrShaderTypeCount; ++s) {
GrShaderType shaderType = static_cast<GrShaderType>(s);
r.appendf("\t%s:\n", shader_type_to_string(shaderType));
- for (int p = 0; p < GrShaderVar::kPrecisionCount; ++p) {
+ for (int p = 0; p < kGrSLPrecisionCount; ++p) {
if (fFloatPrecisions[s][p].supported()) {
- GrShaderVar::Precision precision = static_cast<GrShaderVar::Precision>(p);
+ GrSLPrecision precision = static_cast<GrSLPrecision>(p);
r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n",
precision_to_string(precision),
fFloatPrecisions[s][p].fLogRangeLow,
SK_DECLARE_INST_COUNT(GrDrawTargetCaps)
/** Info about shader variable precision within a given shader stage. That is, this info
- is relevant to a float (or vecNf) variable declared with a GrShaderVar::Precision
+ is relevant to a float (or vecNf) variable declared with a GrSLPrecision
in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
struct PrecisionInfo {
PrecisionInfo() {
* called.
*/
const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
- GrShaderVar::Precision precision) const {
+ GrSLPrecision precision) const {
return fFloatPrecisions[shaderType][precision];
};
bool fConfigTextureSupport[kGrPixelConfigCnt];
bool fShaderPrecisionVaries;
- PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][GrShaderVar::kPrecisionCount];
+ PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
private:
static uint32_t CreateUniqueID();
const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>();
GrGLVertToFrag v(kVec4f_GrSLType);
- args.fPB->addVarying("CubicCoeffs", &v, GrGLShaderVar::kHigh_Precision);
+ args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision);
vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName);
// setup coord outputs
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
- GrGLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar gF("gF", kVec2f_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar gFM("gFM", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
- GrGLShaderVar func("func", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
+ GrGLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar gF("gF", kVec2f_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar gFM("gFM", kFloat_GrSLType, 0, kHigh_GrSLPrecision);
+ GrGLShaderVar func("func", kFloat_GrSLType, 0, kHigh_GrSLPrecision);
fsBuilder->declAppend(edgeAlpha);
fsBuilder->declAppend(dklmdx);
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) SK_OVERRIDE {
// Using highp for GLES here in order to avoid some precision issues on specific GPUs.
- GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
+ GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecision);
SkString tmpDecl;
tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl);
fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
}
-static GrGLenum precision_to_gl_float_type(GrShaderVar::Precision p) {
+static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
switch (p) {
- case GrShaderVar::kLow_Precision:
+ case kLow_GrSLPrecision:
return GR_GL_LOW_FLOAT;
- case GrShaderVar::kMedium_Precision:
+ case kMedium_GrSLPrecision:
return GR_GL_MEDIUM_FLOAT;
- case GrShaderVar::kHigh_Precision:
+ case kHigh_GrSLPrecision:
return GR_GL_HIGH_FLOAT;
}
SkFAIL("Unknown precision.");
GrGLenum glShader = shader_type_to_gl_shader(shaderType);
PrecisionInfo* first = NULL;
fShaderPrecisionVaries = false;
- for (int p = 0; p < GrShaderVar::kPrecisionCount; ++p) {
- GrShaderVar::Precision precision = static_cast<GrShaderVar::Precision>(p);
+ for (int p = 0; p < kGrSLPrecisionCount; ++p) {
+ GrSLPrecision precision = static_cast<GrSLPrecision>(p);
GrGLenum glPrecision = precision_to_gl_float_type(precision);
GrGLint range[2];
GrGLint bits;
fShaderPrecisionVaries = false;
for (int s = 0; s < kGrShaderTypeCount; ++s) {
if (kGeometry_GrShaderType != s || fGeometryShaderSupport) {
- for (int p = 0; p < GrShaderVar::kPrecisionCount; ++p) {
+ for (int p = 0; p < kGrSLPrecisionCount; ++p) {
fFloatPrecisions[s][p].fLogRangeLow = 127;
fFloatPrecisions[s][p].fLogRangeHigh = 127;
fFloatPrecisions[s][p].fBits = 23;
kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 1,
};
-GR_STATIC_ASSERT(GrShaderVar::kHigh_Precision < (1 << kPrecisionBits));
+GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits));
/**
* We specialize the vertex code for each of these matrix types.
key |= kPositionCoords_Flag;
}
- GR_STATIC_ASSERT(GrShaderVar::kPrecisionCount <= (1 << kPrecisionBits));
+ GR_STATIC_ASSERT(kGrSLPrecisionCount <= (1 << kPrecisionBits));
key |= (coordTransform.precision() << kPrecisionShift);
key <<= kTransformKeyBits * t;
}
GrGLShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray,
- Precision precision = kDefault_Precision)
+ GrSLPrecision precision = kDefault_GrSLPrecision)
: GrShaderVar(name, type, arrayCount, precision)
, fOrigin(kDefault_Origin)
, fUseUniformFloatArrays(USE_UNIFORM_FLOAT_ARRAYS) {
}
GrGLShaderVar(const char* name, GrSLType type, TypeModifier typeModifier,
- int arrayCount = kNonArray, Precision precision = kDefault_Precision)
+ int arrayCount = kNonArray, GrSLPrecision precision = kDefault_GrSLPrecision)
: GrShaderVar(name, type, typeModifier, arrayCount, precision)
, fOrigin(kDefault_Origin)
, fUseUniformFloatArrays(USE_UNIFORM_FLOAT_ARRAYS) {
void set(GrSLType type,
TypeModifier typeModifier,
const SkString& name,
- Precision precision = kDefault_Precision,
+ GrSLPrecision precision = kDefault_GrSLPrecision,
Origin origin = kDefault_Origin,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
void set(GrSLType type,
TypeModifier typeModifier,
const char* name,
- Precision precision = kDefault_Precision,
+ GrSLPrecision precision = kDefault_GrSLPrecision,
Origin origin = kDefault_Origin,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
TypeModifier typeModifier,
const SkString& name,
int count,
- Precision precision = kDefault_Precision,
+ GrSLPrecision precision = kDefault_GrSLPrecision,
Origin origin = kDefault_Origin,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
TypeModifier typeModifier,
const char* name,
int count,
- Precision precision = kDefault_Precision,
+ GrSLPrecision precision = kDefault_GrSLPrecision,
Origin origin = kDefault_Origin,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
fUseUniformFloatArrays ? "" : ".x");
}
- static const char* PrecisionString(Precision p, GrGLStandard standard) {
+ static const char* PrecisionString(GrSLPrecision p, GrGLStandard standard) {
// Desktop GLSL has added precision qualifiers but they don't do anything.
if (kGLES_GrGLStandard == standard) {
switch (p) {
- case kLow_Precision:
+ case kLow_GrSLPrecision:
return "lowp ";
- case kMedium_Precision:
+ case kMedium_GrSLPrecision:
return "mediump ";
- case kHigh_Precision:
+ case kHigh_GrSLPrecision:
return "highp ";
default:
SkFAIL("Unexpected precision type.");
const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor";
static const char* declared_color_output_name() { return "fsColorOut"; }
static const char* dual_source_output_name() { return "dualSourceOut"; }
-static void append_default_precision_qualifier(GrGLShaderVar::Precision p,
+static void append_default_precision_qualifier(GrSLPrecision p,
GrGLStandard standard,
SkString* str) {
// Desktop GLSL has added precision qualifiers but they don't do anything.
if (kGLES_GrGLStandard == standard) {
switch (p) {
- case GrGLShaderVar::kHigh_Precision:
+ case kHigh_GrSLPrecision:
str->append("precision highp float;\n");
break;
- case GrGLShaderVar::kMedium_Precision:
+ case kMedium_GrSLPrecision:
str->append("precision mediump float;\n");
break;
- case GrGLShaderVar::kLow_Precision:
+ case kLow_GrSLPrecision:
str->append("precision lowp float;\n");
break;
default:
fInputs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kIn_TypeModifier,
"gl_FragCoord",
- GrGLShaderVar::kDefault_Precision,
+ kDefault_GrSLPrecision,
GrGLShaderVar::kUpperLeft_Origin);
fSetupFragPosition = true;
}
GrGpuGL* gpu = fProgramBuilder->gpu();
SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo()));
fragShaderSrc.append(fExtensions);
- append_default_precision_qualifier(GrShaderVar::kDefault_Precision,
+ append_default_precision_qualifier(kDefault_GrSLPrecision,
gpu->glStandard(),
&fragShaderSrc);
fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility, &fragShaderSrc);
}
}
-void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrGLShaderVar::Precision fsPrec) {
+void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec) {
v->fFsIn = v->fVsOut;
if (v->fGsOut) {
v->fFsIn = v->fGsOut;
/*
* An internal call for GrGLProgramBuilder to use to add varyings to the vertex shader
*/
- void addVarying(GrGLVarying*, GrGLShaderVar::Precision);
+ void addVarying(GrGLVarying*, GrSLPrecision);
/**
* Features that should only be enabled by GrGLFragmentShaderBuilder itself.
void GrGLProgramBuilder::addVarying(const char* name,
GrGLVarying* varying,
- GrGLShaderVar::Precision fsPrecision) {
+ GrSLPrecision fsPrecision) {
SkASSERT(varying);
if (varying->vsVarying()) {
fVS.addVarying(name, varying);
// to use the default FS precision.
if ((kVertex_Visibility | kFragment_Visibility) == visibility) {
// the fragment and vertex precisions must match
- uni.fVariable.setPrecision(GrShaderVar::kDefault_Precision);
+ uni.fVariable.setPrecision(kDefault_GrSLPrecision);
}
if (outName) {
*/
virtual void addVarying(const char* name,
GrGLVarying*,
- GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precision) = 0;
+ GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0;
/*
* This call can be used by GP to pass an attribute through all shaders directly to 'output' in
virtual void addVarying(
const char* name,
GrGLVarying*,
- GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precision) SK_OVERRIDE;
+ GrSLPrecision fsPrecision = kDefault_GrSLPrecision) SK_OVERRIDE;
virtual void addPassThroughAttribute(const GrGeometryProcessor::GrAttribute*,
const char* output) SK_OVERRIDE;