Revert "Revert "Revert "Allow FPs to elevate default precision for the entire fragmen...
authorBrian Osman <brianosman@google.com>
Mon, 3 Apr 2017 14:00:52 +0000 (14:00 +0000)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 3 Apr 2017 14:34:21 +0000 (14:34 +0000)
This reverts commit ec53c636b781830cb6146bb32106d4ee44651fcc.

Reason for revert: Mali GMs look bad.

Original change's description:
> Revert "Revert "Allow FPs to elevate default precision for the entire fragment program""
>
> This reverts commit 903c3f70400462e191ccbca63393b2df3fe2dd11.
>
> Reason for revert: Vulkan issue fixed in compiler.
>
> Original change's description:
> > Revert "Allow FPs to elevate default precision for the entire fragment program"
> >
> > This reverts commit 92d7ccafdf896cf19764e025873d13315a76842d.
> >
> > Reason for revert: Vulkan errors.
> >
> > Original change's description:
> > > Allow FPs to elevate default precision for the entire fragment program
> > >
> > > Currently, GrConfigConversionEffect is able to round-trip on many mobile
> > > GPUs because it uses highp for all intermediate variables (including the
> > > texture fetch result). Separating the texture sample into a different
> > > processor breaks that.
> > >
> > > This is a blunt instrument, not to be used lightly.
> > >
> > > Bug: skia:
> > > Change-Id: I2ab365e3da79628069e2eb727c43c2bf45bfd789
> > > Reviewed-on: https://skia-review.googlesource.com/10162
> > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > Commit-Queue: Brian Osman <brianosman@google.com>
> > >
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com,ethannicholas@google.com,reviews@skia.org
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> >
> > Change-Id: Iee5bb409f86a9cabecc76bd1273a5b3cef6af179
> > Reviewed-on: https://skia-review.googlesource.com/10967
> > Reviewed-by: Brian Osman <brianosman@google.com>
> > Commit-Queue: Brian Osman <brianosman@google.com>
> >
>
> TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,ethannicholas@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I733a0ecc40b58d8727f0259b5498c8e6610cedce
> Reviewed-on: https://skia-review.googlesource.com/11010
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
>

TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,ethannicholas@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Ic3274a0a8b776e811354c3441391ffdc80678292
Reviewed-on: https://skia-review.googlesource.com/11061
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>

13 files changed:
bench/GLInstancedArraysBench.cpp
bench/GLVec4ScalarBench.cpp
bench/GLVertexAttributesBench.cpp
include/gpu/GrTypesPriv.h
include/private/GrGLSL.h
src/gpu/GrCoordTransform.cpp
src/gpu/GrGeometryProcessor.h
src/gpu/GrShaderCaps.cpp
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGLGpu.cpp
src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
src/gpu/glsl/GrGLSLVarying.cpp

index fc5e8fb..5268dd6 100644 (file)
@@ -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(kMedium_GrSLPrecision, *shaderCaps, &fshaderTxt);
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps, &fshaderTxt);
     oColor.setTypeModifier(GrShaderVar::kIn_TypeModifier);
     oColor.appendDecl(shaderCaps, &fshaderTxt);
     fshaderTxt.append(";\n");
index b5c7e22..26f9220 100644 (file)
@@ -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(kMedium_GrSLPrecision, *shaderCaps, &fshaderTxt);
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps, &fshaderTxt);
     oPosition.setTypeModifier(GrShaderVar::kIn_TypeModifier);
     oPosition.appendDecl(shaderCaps, &fshaderTxt);
     fshaderTxt.append(";\n");
index 7efd984..4783d55 100644 (file)
@@ -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(kMedium_GrSLPrecision, *shaderCaps, &fshaderTxt);
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *shaderCaps, &fshaderTxt);
 
     const char* fsOutName;
     if (shaderCaps->mustDeclareFragmentShaderOutput()) {
index cbff7d8..5db1c24 100644 (file)
@@ -116,14 +116,11 @@ enum GrSLPrecision {
     kMedium_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,
+    // 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;
index 66f7be8..ed33c1c 100644 (file)
@@ -74,8 +74,6 @@ static inline const char* GrGLSLPrecisionString(GrSLPrecision p) {
             return "mediump";
         case kHigh_GrSLPrecision:
             return "highp";
-        case kDefault_GrSLPrecision:
-            return "";
         default:
             SkFAIL("Unexpected precision type.");
             return "";
index 9c6815e..b22f325 100644 (file)
 static GrSLPrecision compute_precision(const GrShaderCaps* caps,
                                        int width, int height,
                                        GrSamplerParams::FilterMode filter) {
-    // Always start at kMedium. Then if precisions differ we see if the precision needs to be
+    // Always start at kDefault. 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 = kMedium_GrSLPrecision;
+    GrSLPrecision precision = kDefault_GrSLPrecision;
     if (caps) {
         if (caps->floatPrecisionVaries()) {
             int maxD = SkTMax(width, height);
index e5222bf..2711b9a 100644 (file)
@@ -51,7 +51,6 @@ 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();
index 636b955..e3e6b07 100644 (file)
@@ -32,10 +32,8 @@ 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) {
@@ -203,7 +201,7 @@ void GrShaderCaps::initSamplerPrecisionTable() {
         }
 
         uint8_t* table = fSamplerPrecisions[visibility];
-        table[kUnknown_GrPixelConfig]        = lowp;
+        table[kUnknown_GrPixelConfig]        = kDefault_GrSLPrecision;
         table[kAlpha_8_GrPixelConfig]        = lowp;
         table[kGray_8_GrPixelConfig]         = lowp;
         table[kRGB_565_GrPixelConfig]        = lowp;
index 06085b5..2ec9534 100644 (file)
@@ -1255,10 +1255,9 @@ 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) {
index 17572a9..6cdda06 100644 (file)
@@ -3569,7 +3569,7 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
         fshaderTxt.appendf("#extension %s : require\n",
                            shaderCaps->externalTextureExtensionString());
     }
-    GrGLSLAppendDefaultFloatPrecisionDeclaration(kMedium_GrSLPrecision, *shaderCaps,
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_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(kMedium_GrSLPrecision, *shaderCaps,
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_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(kMedium_GrSLPrecision,
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
                                                  *this->caps()->shaderCaps(),
                                                  &fshaderTxt);
     uColor.appendDecl(this->caps()->shaderCaps(), &fshaderTxt);
index 484bd78..a1f5173 100644 (file)
@@ -85,8 +85,7 @@ GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* p
     , fCustomColorOutputIndex(-1)
     , fHasSecondaryOutput(false)
     , fUsedSampleOffsetArrays(0)
-    , fHasInitializedSampleMask(false)
-    , fDefaultPrecision(kMedium_GrSLPrecision) {
+    , fHasInitializedSampleMask(false) {
     fSubstageIndices.push_back(0);
 #ifdef SK_DEBUG
     fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures;
@@ -179,10 +178,6 @@ void GrGLSLFragmentShaderBuilder::overrideSampleCoverage(const char* mask) {
     fHasInitializedSampleMask = true;
 }
 
-void GrGLSLFragmentShaderBuilder::elevateDefaultPrecision(GrSLPrecision precision) {
-    fDefaultPrecision = SkTMax(fDefaultPrecision, precision);
-}
-
 const char* GrGLSLFragmentShaderBuilder::dstColor() {
     SkDEBUGCODE(fHasReadDstColor = true;)
 
@@ -284,7 +279,7 @@ GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const {
 
 void GrGLSLFragmentShaderBuilder::onFinalize() {
     fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs());
-    GrGLSLAppendDefaultFloatPrecisionDeclaration(fDefaultPrecision,
+    GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
                                                  *fProgramBuilder->shaderCaps(),
                                                  &this->precisionQualifier());
     if (fUsedSampleOffsetArrays & (1 << kSkiaDevice_Coordinates)) {
index 65bcb8d..764f3bd 100644 (file)
@@ -94,13 +94,6 @@ 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.
      */
@@ -174,7 +167,6 @@ 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;
@@ -233,14 +225,13 @@ private:
      */
     SkString fMangleString;
 
-    bool          fSetupFragPosition;
-    bool          fHasCustomColorOutput;
-    int           fCustomColorOutputIndex;
-    bool          fHasSecondaryOutput;
-    uint8_t       fUsedSampleOffsetArrays;
-    bool          fHasInitializedSampleMask;
-    SkString      fDistanceVectorOutput;
-    GrSLPrecision fDefaultPrecision;
+    bool       fSetupFragPosition;
+    bool       fHasCustomColorOutput;
+    int        fCustomColorOutputIndex;
+    bool       fHasSecondaryOutput;
+    uint8_t    fUsedSampleOffsetArrays;
+    bool       fHasInitializedSampleMask;
+    SkString   fDistanceVectorOutput;
 
 #ifdef SK_DEBUG
     // some state to verify shaders and effects are consistent, this is reset between effects by
index ef3fe8a..7d841f5 100644 (file)
@@ -42,7 +42,7 @@ void GrGLSLVaryingHandler::internalAddVarying(const char* name,
 
     SkASSERT(varying);
     v.fType = varying->fType;
-    v.fPrecision = (kDefault_GrSLPrecision == precision) ? kMedium_GrSLPrecision : precision;
+    v.fPrecision = precision;
     v.fIsFlat = flat;
     fProgramBuilder->nameVariable(&v.fVsOut, 'v', name);
     v.fVisibility = kNone_GrShaderFlags;