Stop discarding in frag shader when coverage is zero and stencil writes are enabled
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 5 Feb 2014 16:29:12 +0000 (16:29 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 5 Feb 2014 16:29:12 +0000 (16:29 +0000)
This fixes the corruption in the NVPR images here:
http://108.170.217.252:10117/builders/Test-Win8-ShuttleA-GTX660-x86-Debug/builds/251/steps/CompareGMs/logs/stdio

caused by:

https://skia.googlesource.com/skia.git/+/65ee5f424cb4dabd453268902c00086605d77c1d

The stencil path step writes inside and outside the clip when the clip is implemented by
a coverage effect. The path cover step then doesn't write outside of the clip because the FS
discards. This leaves stencil values outside of the clip non-zero which messed up subsequent
path or clip draws to those samples.

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/154623002

git-svn-id: http://skia.googlecode.com/svn/trunk@13320 2bbb7eff-a529-9590-31e7-b0007b416f81

src/gpu/gl/GrGLProgram.cpp
src/gpu/gl/GrGLProgramDesc.cpp
src/gpu/gl/GrGLProgramDesc.h
tests/GLProgramsTest.cpp

index cac38b4..6e9878a 100644 (file)
@@ -120,17 +120,6 @@ bool GrGLProgram::genProgram(GrGLShaderBuilder* builder,
                                       fDesc.numCoverageEffects(),
                                       &inCoverage));
 
-    // discard if coverage is zero
-    if (header.fDiscardIfZeroCoverage && !inCoverage.isOnes()) {
-        if (inCoverage.isZeros()) {
-            // This is unfortunate.
-            builder->fsCodeAppend("\tdiscard;\n");
-        } else {
-            builder->fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\t\tdiscard;\n\t}\n",
-                                   inCoverage.c_str());
-        }
-    }
-
     if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutput)) {
         const char* secondaryOutputName = builder->enableSecondaryOutput();
 
index 381461a..b6029fe 100644 (file)
@@ -215,8 +215,7 @@ void GrGLProgramDesc::Build(const GrDrawState& drawState,
 
     // Here we deal with whether/how we handle color and coverage separately.
 
-    // Set these defaults and then possibly change our mind if there is coverage.
-    header->fDiscardIfZeroCoverage = false;
+    // Set this default and then possibly change our mind if there is coverage.
     header->fCoverageOutput = kModulate_CoverageOutput;
 
     // If we do have coverage determine whether it matters.
@@ -224,12 +223,6 @@ void GrGLProgramDesc::Build(const GrDrawState& drawState,
     if (!drawState.isCoverageDrawing() && !skipCoverage &&
         (drawState.numCoverageStages() > 0 || requiresCoverageAttrib)) {
 
-        // If we're stenciling then we want to discard samples that have zero coverage
-        if (drawState.getStencil().doesWrite()) {
-            header->fDiscardIfZeroCoverage = true;
-            separateCoverageFromColor = true;
-        }
-
         if (gpu->caps()->dualSourceBlendingSupport() &&
             !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag |
                            GrDrawState::kCoverageAsAlpha_BlendOptFlag))) {
index ec3f097..9116fdf 100644 (file)
@@ -151,9 +151,6 @@ private:
                                                         // effects that read the fragment position.
                                                         // Otherwise, 0.
 
-        // should the FS discard if the coverage is zero (to avoid stencil manipulation)
-        SkBool8                     fDiscardIfZeroCoverage;
-
         ColorInput                  fColorInput : 8;
         ColorInput                  fCoverageInput : 8;
         CoverageOutput              fCoverageOutput : 8;
index f320735..24312ee 100644 (file)
@@ -65,8 +65,6 @@ void GrGLProgramDesc::setRandom(SkRandom* random,
     header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool();
 #endif
 
-    header->fDiscardIfZeroCoverage = random->nextBool();
-
     bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::kMaxVertexAttribCnt;
     header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1;