Change GrGLProgramDesc header to have DoPathRendering flag instead of RequiresVertexS...
authoregdaniel <egdaniel@google.com>
Mon, 22 Sep 2014 19:29:52 +0000 (12:29 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 22 Sep 2014 19:29:52 +0000 (12:29 -0700)
Also update GLProgramTests to fix bug where it would incorrectly try to PathRendering when we did
not want to.

BUG=skia:
R=bsalomon@google.com, joshualitt@chromium.org

Author: egdaniel@google.com

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

src/gpu/gl/GrGLProgram.cpp
src/gpu/gl/GrGLProgramDesc.cpp
src/gpu/gl/GrGLProgramDesc.h
src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.cpp
src/gpu/gl/builders/GrGLProgramBuilder.cpp
tests/GLProgramsTest.cpp

index dccd4bb..a695173 100644 (file)
@@ -29,9 +29,10 @@ GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu,
                                  const GrEffectStage* colorStages[],
                                  const GrEffectStage* coverageStages[]) {
     SkAutoTDelete<GrGLProgramBuilder> builder;
-    if (!desc.getHeader().fRequiresVertexShader &&
-        gpu->glCaps().pathRenderingSupport() &&
-        gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunction_TexturingMode) {
+    if (desc.getHeader().fUseFragShaderOnly) {
+        SkASSERT(gpu->glCaps().pathRenderingSupport());
+        SkASSERT(gpu->glPathRendering()->texturingMode() ==
+                 GrGLPathRendering::FixedFunction_TexturingMode);
         SkASSERT(NULL == geometryProcessor);
         builder.reset(SkNEW_ARGS(GrGLFragmentOnlyProgramBuilder, (gpu, desc)));
     } else {
index c6560be..c0a9e13 100644 (file)
@@ -163,7 +163,7 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState,
                             GrGpu::DrawType drawType,
                             GrBlendCoeff srcCoeff,
                             GrBlendCoeff dstCoeff,
-                            const GrGpuGL* gpu,
+                            GrGpuGL* gpu,
                             const GrDeviceCoordTexture* dstCopy,
                             const GrEffectStage** geometryProcessor,
                             SkTArray<const GrEffectStage*, true>* colorStages,
@@ -260,12 +260,11 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState,
     // Because header is a pointer into the dynamic array, we can't push any new data into the key
     // below here.
 
-    // We will only require a vertex shader if we have more than just the position VA attrib.
-    // If we have a geom processor we must us a vertex shader and we should not have a geometry
-    // processor if we are doing path rendering.
-    SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType) || !optState.requiresVertexShader());
-    header->fRequiresVertexShader = optState.requiresVertexShader() ||
-                                    !GrGpu::IsPathRenderingDrawType(drawType);
+    header->fUseFragShaderOnly = gpu->caps()->pathRenderingSupport() &&
+        GrGpu::IsPathRenderingDrawType(drawType) &&
+        gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunction_TexturingMode;
+    SkASSERT(!header->fUseFragShaderOnly || !optState.hasGeometryProcessor());
+
     header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType;
 
     // Currently the experimental GS will only work with triangle prims (and it doesn't do anything
@@ -277,7 +276,7 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState,
     header->fExperimentalGS = false;
 #endif
 #endif
-    bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->pathRenderingSupport();
+    bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || header->fUseFragShaderOnly;
 
     if (!inputColorIsUsed) {
         header->fColorInput = kAllOnes_ColorInput;
@@ -285,7 +284,7 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState,
         header->fColorInput = kUniform_ColorInput;
     } else {
         header->fColorInput = kAttribute_ColorInput;
-        header->fRequiresVertexShader = true;
+        header->fUseFragShaderOnly = false;
     }
 
     bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == optState.getCoverageColor();
@@ -296,7 +295,7 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState,
         header->fCoverageInput = kUniform_ColorInput;
     } else {
         header->fCoverageInput = kAttribute_ColorInput;
-        header->fRequiresVertexShader = true;
+        header->fUseFragShaderOnly = false;
     }
 
     if (optState.readsDst()) {
index 8cee707..c9bdac5 100644 (file)
@@ -45,14 +45,15 @@ public:
 
     // For unit testing.
     bool setRandom(SkRandom*,
-                   const GrGpuGL* gpu,
+                   GrGpuGL* gpu,
                    const GrRenderTarget* dummyDstRenderTarget,
                    const GrTexture* dummyDstCopyTexture,
                    const GrEffectStage* geometryProcessor,
                    const GrEffectStage* stages[],
                    int numColorStages,
                    int numCoverageStages,
-                   int currAttribIndex);
+                   int currAttribIndex,
+                   GrGpu::DrawType);
 
     /**
      * Builds a program descriptor from a GrOptDrawState. Whether the primitive type is points, and
@@ -64,7 +65,7 @@ public:
                       GrGpu::DrawType drawType,
                       GrBlendCoeff srcCoeff,
                       GrBlendCoeff dstCoeff,
-                      const GrGpuGL* gpu,
+                      GrGpuGL* gpu,
                       const GrDeviceCoordTexture* dstCopy,
                       const GrEffectStage** outGeometryProcessor,
                       SkTArray<const GrEffectStage*, true>* outColorStages,
@@ -151,7 +152,7 @@ private:
         ColorInput                  fCoverageInput : 8;
         CoverageOutput              fCoverageOutput : 8;
 
-        SkBool8                     fRequiresVertexShader;
+        SkBool8                     fUseFragShaderOnly;
         SkBool8                     fEmitsPointSize;
 
         // To enable experimental geometry shader code (not for use in
index 16def63..9c32433 100644 (file)
@@ -11,7 +11,7 @@
 GrGLFragmentOnlyProgramBuilder::GrGLFragmentOnlyProgramBuilder(GrGpuGL* gpu,
                                                                const GrGLProgramDesc& desc)
     : INHERITED(gpu, desc) {
-    SkASSERT(!desc.getHeader().fRequiresVertexShader);
+    SkASSERT(desc.getHeader().fUseFragShaderOnly);
     SkASSERT(gpu->glCaps().pathRenderingSupport());
     SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorInput);
     SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverageInput);
index a0dd555..328243d 100644 (file)
@@ -84,9 +84,7 @@ bool GrGLProgramBuilder::genProgram(const GrEffectStage* geometryProcessor,
 
 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu,
                                        const GrGLProgramDesc& desc)
-    : fFragOnly(!desc.getHeader().fRequiresVertexShader &&
-                gpu->glCaps().pathRenderingSupport() &&
-                gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunction_TexturingMode)
+    : fFragOnly(SkToBool(desc.getHeader().fUseFragShaderOnly))
     , fTexCoordSetCnt(0)
     , fProgramID(0)
     , fFS(this, desc)
index 7fc084f..0574bfc 100644 (file)
@@ -35,15 +35,19 @@ static void get_stage_stats(const GrEffectStage stage, bool* readsDst,
 }
 
 bool GrGLProgramDesc::setRandom(SkRandom* random,
-                                const GrGpuGL* gpu,
+                                GrGpuGL* gpu,
                                 const GrRenderTarget* dstRenderTarget,
                                 const GrTexture* dstCopyTexture,
                                 const GrEffectStage* geometryProcessor,
                                 const GrEffectStage* stages[],
                                 int numColorStages,
                                 int numCoverageStages,
-                                int currAttribIndex) {
-    bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::kMaxVertexAttribCnt;
+                                int currAttribIndex,
+                                GrGpu::DrawType drawType) {
+    bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType);
+    bool useLocalCoords = !isPathRendering &&
+                          random->nextBool() &&
+                          currAttribIndex < GrDrawState::kMaxVertexAttribCnt;
 
     int numStages = numColorStages + numCoverageStages;
     fKey.reset();
@@ -110,12 +114,10 @@ bool GrGLProgramDesc::setRandom(SkRandom* random,
     // if the effects have used up all off the available attributes,
     // don't try to use color or coverage attributes as input
     do {
-        uint32_t colorRand = random->nextULessThan(2);
-        header->fColorInput = (0 == colorRand) ? GrGLProgramDesc::kAttribute_ColorInput :
-                                                 GrGLProgramDesc::kUniform_ColorInput;
-    } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
+        header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>(
+                                     random->nextULessThan(kColorInputCnt));
+    } while ((GrDrawState::kMaxVertexAttribCnt <= currAttribIndex || isPathRendering) &&
              kAttribute_ColorInput == header->fColorInput);
-
     header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput) ?
                                         currAttribIndex++ :
                                         -1;
@@ -123,7 +125,7 @@ bool GrGLProgramDesc::setRandom(SkRandom* random,
     do {
         header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>(
                                      random->nextULessThan(kColorInputCnt));
-    } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex  &&
+    } while ((GrDrawState::kMaxVertexAttribCnt <= currAttribIndex || isPathRendering)  &&
              kAttribute_ColorInput == header->fCoverageInput);
     header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_ColorInput) ?
                                         currAttribIndex++ :
@@ -153,10 +155,8 @@ bool GrGLProgramDesc::setRandom(SkRandom* random,
         header->fFragPosKey = 0;
     }
 
-    header->fRequiresVertexShader = vertexShader ||
-                                    useLocalCoords ||
-                                    kAttribute_ColorInput == header->fColorInput ||
-                                    kAttribute_ColorInput == header->fCoverageInput;
+    header->fUseFragShaderOnly = isPathRendering && gpu->glPathRendering()->texturingMode() ==
+                                                    GrGLPathRendering::FixedFunction_TexturingMode;
     header->fHasGeometryProcessor = vertexShader;
 
     CoverageOutput coverageOutput;
@@ -248,12 +248,13 @@ bool GrGpuGL::programUnitTest(int maxStages) {
 
         SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages);
 
-        bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport() &&
-            this->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunction_TexturingMode &&
-            random.nextBool();
+        bool usePathRendering = this->glCaps().pathRenderingSupport() && random.nextBool();
+        
+        GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType :
+                                                      GrGpu::kDrawPoints_DrawType;
 
         SkAutoTDelete<GrEffectStage> geometryProcessor;
-        bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : random.nextBool();
+        bool hasGeometryProcessor = usePathRendering ? false : random.nextBool();
         if (hasGeometryProcessor) {
             while (true) {
                 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage(
@@ -306,7 +307,8 @@ bool GrGpuGL::programUnitTest(int maxStages) {
 
             // If adding this effect would exceed the max texture coord set count then generate a
             // new random effect.
-            if (useFixedFunctionPathRendering) {
+            if (usePathRendering && this->glPathRendering()->texturingMode() ==
+                                    GrGLPathRendering::FixedFunction_TexturingMode) {;
                 int numTransforms = effect->numTransforms();
                 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) {
                     continue;
@@ -327,7 +329,8 @@ bool GrGpuGL::programUnitTest(int maxStages) {
                              stages.get(),
                              numColorStages,
                              numCoverageStages,
-                             currAttribIndex)) {
+                             currAttribIndex,
+                             drawType)) {
             return false;
         }