aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/GLInstancedArraysBench.cpp2
-rw-r--r--bench/GLVec4ScalarBench.cpp2
-rw-r--r--bench/GLVertexAttributesBench.cpp2
-rw-r--r--include/gpu/GrTypesPriv.h13
-rw-r--r--include/private/GrGLSL.h2
-rw-r--r--src/gpu/GrCoordTransform.cpp4
-rw-r--r--src/gpu/GrGeometryProcessor.h1
-rw-r--r--src/gpu/GrShaderCaps.cpp6
-rw-r--r--src/gpu/gl/GrGLCaps.cpp5
-rw-r--r--src/gpu/gl/GrGLGpu.cpp6
-rw-r--r--src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp9
-rw-r--r--src/gpu/glsl/GrGLSLFragmentShaderBuilder.h23
-rw-r--r--src/gpu/glsl/GrGLSLVarying.cpp2
13 files changed, 50 insertions, 27 deletions
diff --git a/bench/GLInstancedArraysBench.cpp b/bench/GLInstancedArraysBench.cpp
index 5268dd6e72..fc5e8fb17f 100644
--- a/bench/GLInstancedArraysBench.cpp
+++ b/bench/GLInstancedArraysBench.cpp
@@ -133,7 +133,7 @@ GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) {
// setup fragment shader
GrShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier);
SkString fshaderTxt(version);
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps, &fshaderTxt);
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision, *shaderCaps, &fshaderTxt);
oColor.setTypeModifier(GrShaderVar::kIn_TypeModifier);
oColor.appendDecl(shaderCaps, &fshaderTxt);
fshaderTxt.append(";\n");
diff --git a/bench/GLVec4ScalarBench.cpp b/bench/GLVec4ScalarBench.cpp
index 26f9220750..b5c7e22a49 100644
--- a/bench/GLVec4ScalarBench.cpp
+++ b/bench/GLVec4ScalarBench.cpp
@@ -131,7 +131,7 @@ GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) {
// next stage.
GrShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier);
SkString fshaderTxt(version);
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps, &fshaderTxt);
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision, *shaderCaps, &fshaderTxt);
oPosition.setTypeModifier(GrShaderVar::kIn_TypeModifier);
oPosition.appendDecl(shaderCaps, &fshaderTxt);
fshaderTxt.append(";\n");
diff --git a/bench/GLVertexAttributesBench.cpp b/bench/GLVertexAttributesBench.cpp
index 4783d5510a..7efd984762 100644
--- a/bench/GLVertexAttributesBench.cpp
+++ b/bench/GLVertexAttributesBench.cpp
@@ -117,7 +117,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a
// setup fragment shader
GrShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier);
SkString fshaderTxt(version);
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps, &fshaderTxt);
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision, *shaderCaps, &fshaderTxt);
const char* fsOutName;
if (shaderCaps->mustDeclareFragmentShaderOutput()) {
diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h
index 5db1c24765..cbff7d8a3b 100644
--- a/include/gpu/GrTypesPriv.h
+++ b/include/gpu/GrTypesPriv.h
@@ -116,11 +116,14 @@ enum 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
+ // Default precision is a special tag that means "whatever the default for the program/type
+ // combination is". In other words, it maps to the empty string in shader code. There are some
+ // scenarios where kDefault is not allowed (as the default precision for a program, or for
+ // varyings, for example).
+ kDefault_GrSLPrecision,
+
+ // We only consider the "real" precisions here
+ kLast_GrSLPrecision = kHigh_GrSLPrecision,
};
static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
diff --git a/include/private/GrGLSL.h b/include/private/GrGLSL.h
index ed33c1cf4c..66f7be84d1 100644
--- a/include/private/GrGLSL.h
+++ b/include/private/GrGLSL.h
@@ -74,6 +74,8 @@ static inline const char* GrGLSLPrecisionString(GrSLPrecision p) {
return "mediump";
case kHigh_GrSLPrecision:
return "highp";
+ case kDefault_GrSLPrecision:
+ return "";
default:
SkFAIL("Unexpected precision type.");
return "";
diff --git a/src/gpu/GrCoordTransform.cpp b/src/gpu/GrCoordTransform.cpp
index b22f3258fc..9c6815ec84 100644
--- a/src/gpu/GrCoordTransform.cpp
+++ b/src/gpu/GrCoordTransform.cpp
@@ -15,13 +15,13 @@
static GrSLPrecision compute_precision(const GrShaderCaps* caps,
int width, int height,
GrSamplerParams::FilterMode filter) {
- // Always start at kDefault. Then if precisions differ we see if the precision needs to be
+ // Always start at kMedium. Then if precisions differ we see if the precision needs to be
// increased. Our rule is that we want at least 4 subpixel values in the representation for
// coords between 0 to 1 when bi- or tri-lerping and 1 value when nearest filtering. Note that
// this still might not be enough when drawing with repeat or mirror-repeat modes but that case
// can be arbitrarily bad.
int subPixelThresh = filter > GrSamplerParams::kNone_FilterMode ? 4 : 1;
- GrSLPrecision precision = kDefault_GrSLPrecision;
+ GrSLPrecision precision = kMedium_GrSLPrecision;
if (caps) {
if (caps->floatPrecisionVaries()) {
int maxD = SkTMax(width, height);
diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h
index 2711b9a608..e5222bf80a 100644
--- a/src/gpu/GrGeometryProcessor.h
+++ b/src/gpu/GrGeometryProcessor.h
@@ -51,6 +51,7 @@ protected:
*/
const Attribute& addVertexAttrib(const char* name, GrVertexAttribType type,
GrSLPrecision precision = kDefault_GrSLPrecision) {
+ precision = (kDefault_GrSLPrecision == precision) ? kMedium_GrSLPrecision : precision;
fAttribs.emplace_back(name, type, precision);
fVertexStride += fAttribs.back().fOffset;
return fAttribs.back();
diff --git a/src/gpu/GrShaderCaps.cpp b/src/gpu/GrShaderCaps.cpp
index e3e6b07361..636b955ab7 100644
--- a/src/gpu/GrShaderCaps.cpp
+++ b/src/gpu/GrShaderCaps.cpp
@@ -32,8 +32,10 @@ static const char* precision_to_string(GrSLPrecision p) {
return "medium";
case kHigh_GrSLPrecision:
return "high";
+ default:
+ SkFAIL("Unexpected precision type.");
+ return "";
}
- return "";
}
GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
@@ -201,7 +203,7 @@ void GrShaderCaps::initSamplerPrecisionTable() {
}
uint8_t* table = fSamplerPrecisions[visibility];
- table[kUnknown_GrPixelConfig] = kDefault_GrSLPrecision;
+ table[kUnknown_GrPixelConfig] = lowp;
table[kAlpha_8_GrPixelConfig] = lowp;
table[kGray_8_GrPixelConfig] = lowp;
table[kRGB_565_GrPixelConfig] = lowp;
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 2ec95347f8..06085b5e86 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -1255,9 +1255,10 @@ static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
return GR_GL_MEDIUM_FLOAT;
case kHigh_GrSLPrecision:
return GR_GL_HIGH_FLOAT;
+ default:
+ SkFAIL("Unexpected precision type.");
+ return -1;
}
- SkFAIL("Unknown precision.");
- return -1;
}
static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 6cdda0672a..17572a9bb3 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3569,7 +3569,7 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
fshaderTxt.appendf("#extension %s : require\n",
shaderCaps->externalTextureExtensionString());
}
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps,
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision, *shaderCaps,
&fshaderTxt);
vTexCoord.setTypeModifier(GrShaderVar::kIn_TypeModifier);
vTexCoord.appendDecl(shaderCaps, &fshaderTxt);
@@ -3707,7 +3707,7 @@ bool GrGLGpu::createMipmapProgram(int progIdx) {
fshaderTxt.appendf("#extension %s : require\n", extension);
}
}
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps,
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision, *shaderCaps,
&fshaderTxt);
for (int i = 0; i < numTaps; ++i) {
vTexCoords[i].setTypeModifier(GrShaderVar::kIn_TypeModifier);
@@ -3822,7 +3822,7 @@ bool GrGLGpu::createWireRectProgram() {
GrShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier);
SkString fshaderTxt(version);
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision,
*this->caps()->shaderCaps(),
&fshaderTxt);
uColor.appendDecl(this->caps()->shaderCaps(), &fshaderTxt);
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
index a1f5173436..484bd78211 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
@@ -85,7 +85,8 @@ GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* p
, fCustomColorOutputIndex(-1)
, fHasSecondaryOutput(false)
, fUsedSampleOffsetArrays(0)
- , fHasInitializedSampleMask(false) {
+ , fHasInitializedSampleMask(false)
+ , fDefaultPrecision(kMedium_GrSLPrecision) {
fSubstageIndices.push_back(0);
#ifdef SK_DEBUG
fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures;
@@ -178,6 +179,10 @@ void GrGLSLFragmentShaderBuilder::overrideSampleCoverage(const char* mask) {
fHasInitializedSampleMask = true;
}
+void GrGLSLFragmentShaderBuilder::elevateDefaultPrecision(GrSLPrecision precision) {
+ fDefaultPrecision = SkTMax(fDefaultPrecision, precision);
+}
+
const char* GrGLSLFragmentShaderBuilder::dstColor() {
SkDEBUGCODE(fHasReadDstColor = true;)
@@ -279,7 +284,7 @@ GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const {
void GrGLSLFragmentShaderBuilder::onFinalize() {
fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs());
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(fDefaultPrecision,
*fProgramBuilder->shaderCaps(),
&this->precisionQualifier());
if (fUsedSampleOffsetArrays & (1 << kSkiaDevice_Coordinates)) {
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
index 764f3bd812..65bcb8dae6 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
@@ -94,6 +94,13 @@ public:
virtual const char* distanceVectorName() const = 0;
/**
+ * Overrides the default precision for the entire fragment program. Processors that require
+ * high precision input (eg from incoming texture samples) may use this. For calculations that
+ * are limited to a single processor's code, it is better to annotate individual declarations.
+ */
+ virtual void elevateDefaultPrecision(GrSLPrecision) = 0;
+
+ /**
* Fragment procs with child procs should call these functions before/after calling emitCode
* on a child proc.
*/
@@ -167,6 +174,7 @@ public:
void appendOffsetToSample(const char* sampleIdx, Coordinates) override;
void maskSampleCoverage(const char* mask, bool invert = false) override;
void overrideSampleCoverage(const char* mask) override;
+ void elevateDefaultPrecision(GrSLPrecision) override;
const SkString& getMangleString() const override { return fMangleString; }
void onBeforeChildProcEmitCode() override;
void onAfterChildProcEmitCode() override;
@@ -225,13 +233,14 @@ private:
*/
SkString fMangleString;
- bool fSetupFragPosition;
- bool fHasCustomColorOutput;
- int fCustomColorOutputIndex;
- bool fHasSecondaryOutput;
- uint8_t fUsedSampleOffsetArrays;
- bool fHasInitializedSampleMask;
- SkString fDistanceVectorOutput;
+ bool fSetupFragPosition;
+ bool fHasCustomColorOutput;
+ int fCustomColorOutputIndex;
+ bool fHasSecondaryOutput;
+ uint8_t fUsedSampleOffsetArrays;
+ bool fHasInitializedSampleMask;
+ SkString fDistanceVectorOutput;
+ GrSLPrecision fDefaultPrecision;
#ifdef SK_DEBUG
// some state to verify shaders and effects are consistent, this is reset between effects by
diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp
index 7d841f5417..ef3fe8af23 100644
--- a/src/gpu/glsl/GrGLSLVarying.cpp
+++ b/src/gpu/glsl/GrGLSLVarying.cpp
@@ -42,7 +42,7 @@ void GrGLSLVaryingHandler::internalAddVarying(const char* name,
SkASSERT(varying);
v.fType = varying->fType;
- v.fPrecision = precision;
+ v.fPrecision = (kDefault_GrSLPrecision == precision) ? kMedium_GrSLPrecision : precision;
v.fIsFlat = flat;
fProgramBuilder->nameVariable(&v.fVsOut, 'v', name);
v.fVisibility = kNone_GrShaderFlags;